2025-03-20 01:46:54 +08:00
|
|
|
import { store } from "@tauri-store/valtio"
|
2025-03-17 11:48:30 +08:00
|
|
|
import { useSnapshot } from "valtio"
|
2025-03-20 01:46:54 +08:00
|
|
|
import { DEFAULT_STORE_CONFIG } from "./config"
|
2024-09-21 02:25:23 +08:00
|
|
|
|
2025-03-23 16:42:13 +08:00
|
|
|
interface LaunchOption {
|
|
|
|
|
option: string
|
|
|
|
|
name: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface VideoSetting {
|
|
|
|
|
width: number; // 分辨率宽度
|
|
|
|
|
height: number; // 分辨率高度
|
|
|
|
|
fullscreen: string; // 全屏
|
|
|
|
|
vsync: string; // 垂直同步
|
|
|
|
|
enhanceCharacterContrast: string; // 增强角色对比度
|
|
|
|
|
cmaa2AntiAliasing: string; // CMAA2抗锯齿
|
|
|
|
|
msaaAntiAliasing: string; // 多重采样抗锯齿
|
|
|
|
|
globalShadowQuality: string; // 全局阴影效果
|
|
|
|
|
dynamicShadows: string; // 动态阴影
|
|
|
|
|
modelTextureDetail: string; // 模型/贴图细节
|
|
|
|
|
textureFilteringMode: string; // 贴图过滤模式
|
|
|
|
|
lightShadowDetail: string; // 光影细节
|
|
|
|
|
particleDetail: string; // 粒子细节
|
|
|
|
|
ambientOcclusion: string; // 环境光遮蔽
|
|
|
|
|
hdr: string; // 高动态范围
|
|
|
|
|
fidelityFxSuperResolution: string; // Fidelity FX 超级分辨率
|
|
|
|
|
}
|
2025-03-17 11:48:30 +08:00
|
|
|
|
2025-03-12 11:22:32 +08:00
|
|
|
const defaultValue = {
|
2025-03-12 13:07:16 +08:00
|
|
|
launchOptions: [
|
2025-03-23 16:42:13 +08:00
|
|
|
{ option: "-novid -high -freq 144 -fullscreen", name: "" },
|
|
|
|
|
{ option: "-novid -high -w 1920 -h 1080 -freq 144 -sw -noborder", name: "" },
|
|
|
|
|
{ option: "-novid -high -freq 144 -fullscreen -allow_third_party_software", name: "" },
|
|
|
|
|
] as LaunchOption[],
|
2025-03-12 11:22:32 +08:00
|
|
|
launchIndex: 0,
|
2025-03-12 22:20:06 +08:00
|
|
|
powerPlan: 0,
|
2025-03-23 16:42:13 +08:00
|
|
|
videoSetting: {
|
|
|
|
|
width: 1920,
|
|
|
|
|
height: 1080
|
|
|
|
|
} as VideoSetting,
|
2024-09-21 02:25:23 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-12 22:20:06 +08:00
|
|
|
export const toolStore = store(
|
|
|
|
|
"tool",
|
|
|
|
|
{ ...defaultValue },
|
|
|
|
|
DEFAULT_STORE_CONFIG,
|
|
|
|
|
)
|
2025-03-12 11:22:32 +08:00
|
|
|
|
2025-03-17 11:48:30 +08:00
|
|
|
export const useToolStore = () => {
|
|
|
|
|
void toolStore.start
|
|
|
|
|
const state = useSnapshot(toolStore.state)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
state,
|
2025-03-21 15:06:41 +08:00
|
|
|
store: toolStore,
|
2025-03-17 11:48:30 +08:00
|
|
|
setLaunchOption,
|
|
|
|
|
setLaunchOptions,
|
|
|
|
|
setLaunchIndex,
|
|
|
|
|
setPowerPlan,
|
2025-03-23 16:42:13 +08:00
|
|
|
setVideoSetting,
|
2025-03-17 11:48:30 +08:00
|
|
|
addLaunchOption,
|
|
|
|
|
resetToolStore,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-23 16:42:13 +08:00
|
|
|
const setLaunchOption = (option: LaunchOption, index: number) => {
|
2025-03-12 11:22:32 +08:00
|
|
|
toolStore.state.launchOptions = [
|
|
|
|
|
...toolStore.state.launchOptions.slice(0, index),
|
|
|
|
|
option,
|
2025-03-12 22:20:06 +08:00
|
|
|
...toolStore.state.launchOptions.slice(index + 1),
|
2025-03-12 11:22:32 +08:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-23 16:42:13 +08:00
|
|
|
const setLaunchOptions = (options: LaunchOption[]) => {
|
2025-03-12 11:22:32 +08:00
|
|
|
toolStore.state.launchOptions = options
|
2024-09-27 10:38:40 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-17 11:48:30 +08:00
|
|
|
const setLaunchIndex = (index: number) => {
|
2025-03-12 11:22:32 +08:00
|
|
|
toolStore.state.launchIndex = index
|
|
|
|
|
}
|
2024-09-27 10:38:40 +08:00
|
|
|
|
2025-03-17 11:48:30 +08:00
|
|
|
const setPowerPlan = (plan: number) => {
|
2025-03-12 11:22:32 +08:00
|
|
|
toolStore.state.powerPlan = plan
|
|
|
|
|
}
|
2024-09-21 02:25:23 +08:00
|
|
|
|
2025-03-23 16:42:13 +08:00
|
|
|
const setVideoSetting = (setting: VideoSetting) => {
|
|
|
|
|
toolStore.state.videoSetting = setting
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const addLaunchOption = (option: LaunchOption) => {
|
2025-03-13 22:04:27 +08:00
|
|
|
// 限制最高10个
|
|
|
|
|
if (toolStore.state.launchOptions.length >= 10) {
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-03-14 19:13:32 +08:00
|
|
|
toolStore.state.launchOptions = [...toolStore.state.launchOptions, option]
|
2025-03-13 22:04:27 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-17 11:48:30 +08:00
|
|
|
const resetToolStore = () => {
|
2025-03-13 22:25:06 +08:00
|
|
|
setLaunchOptions(defaultValue.launchOptions)
|
|
|
|
|
setLaunchIndex(defaultValue.launchIndex)
|
|
|
|
|
setPowerPlan(defaultValue.powerPlan)
|
2025-03-23 16:42:13 +08:00
|
|
|
setVideoSetting(defaultValue.videoSetting)
|
2025-03-12 11:22:32 +08:00
|
|
|
}
|