Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { webgalStore } from '@/store/store';
import { setGlobalVar } from '@/store/userDataReducer';
import { setGlobalVar, setUserData } from '@/store/userDataReducer';
import { setEnableAppreciationMode } from '@/store/GUIReducer';
import { Live2D, WebGAL } from '@/Core/WebGAL';
import { WebgalParser } from '@/Core/parser/sceneParser';
Expand All @@ -8,6 +8,7 @@ import { initKey } from '@/Core/controller/storage/fastSaveLoad';
import { getFastSaveFromStorage, getSavesFromStorage } from '@/Core/controller/storage/savesController';
import { logger } from '@/Core/util/logger';
import axios from 'axios';
import { IGameVar } from '@/store/stageInterface';

/**
* 获取游戏信息
Expand All @@ -26,11 +27,14 @@ export const infoFetcher = (url: string) => {
await getStorageAsync();
getFastSaveFromStorage();
getSavesFromStorage(0, 0);
// 存储 config.txt 中的配置,用于清除所有数据时还原配置
const gameConfigInit: IGameVar = {};
// 按照游戏的配置开始设置对应的状态
gameConfig.forEach((e) => {
const { command, args } = e;
if (args.length > 0) {
if (args.length > 1) {
gameConfigInit[command] = args.join('|');
dispatch(
setGlobalVar({
key: command,
Expand All @@ -45,6 +49,7 @@ export const infoFetcher = (url: string) => {
res = Number(res);
}

gameConfigInit[command] = res;
dispatch(
setGlobalVar({
key: command,
Expand All @@ -65,6 +70,8 @@ export const infoFetcher = (url: string) => {
}
}
});

dispatch(setUserData({ key: 'gameConfigInit', value: gameConfigInit }));
// @ts-expect-error renderPromiseResolve is a global variable
window.renderPromiseResolve();
setStorage();
Expand Down
1 change: 1 addition & 0 deletions packages/webgal/src/store/userDataInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface IUserData {
globalGameVar: IGameVar; // 不跟随存档的全局变量
optionData: IOptionData; // 用户设置选项数据
appreciationData: IAppreciation;
gameConfigInit: IGameVar;
}

export interface ISetUserDataPayload {
Expand Down
4 changes: 3 additions & 1 deletion packages/webgal/src/store/userDataReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const initState: IUserData = {
bgm: [],
cg: [],
},
gameConfigInit: {},
};

const userDataSlice = createSlice({
Expand Down Expand Up @@ -138,7 +139,8 @@ const userDataSlice = createSlice({
Object.assign(state.optionData, initialOptionSet);
},
resetAllData(state) {
Object.assign(state, cloneDeep(initState));
const { gameConfigInit } = state;
Object.assign(state, { ...cloneDeep(initState), globalGameVar: cloneDeep(gameConfigInit), gameConfigInit });
},
},
});
Expand Down