Skip to content

Commit

Permalink
fix: can not continue game after calling 'end'
Browse files Browse the repository at this point in the history
  • Loading branch information
MakinoharaShoko committed Mar 2, 2024
1 parent 7e481d7 commit 8fa74b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/webgal/src/Core/gameScripts/end.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { resetStage } from '@/Core/controller/stage/resetStage';
import { webgalStore } from '@/store/store';
import { setVisibility } from '@/store/GUIReducer';
import { playBgm } from '@/Core/controller/stage/playBgm';

import { WebGAL } from '@/Core/WebGAL';
import { resetFastSave } from '@/store/userDataReducer';
import { syncStorageFast } from '@/Core/controller/storage/storageController';

/**
* 结束游戏
Expand All @@ -19,8 +20,14 @@ export const end = (sentence: ISentence): IPerform => {
const dispatch = webgalStore.dispatch;
// 重新获取初始场景
const sceneUrl: string = assetSetter('start.txt', fileType.scene);
// 场景写入到运行时
// 为了在 scriptExecutor 自增 sentenceId 后再重置场景
setTimeout(() => {
WebGAL.sceneManager.resetScene();
}, 5);
dispatch(resetFastSave());
syncStorageFast();
sceneFetcher(sceneUrl).then((rawScene) => {
// 场景写入到运行时
WebGAL.sceneManager.sceneData.currentScene = sceneParser(rawScene, 'start.txt', sceneUrl);
});
dispatch(setVisibility({ component: 'showTitle', visibility: true }));
Expand Down
4 changes: 4 additions & 0 deletions packages/webgal/src/store/userDataReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ const userDataSlice = createSlice({
setFastSave: (state, action: PayloadAction<ISaveData | null>) => {
state.quickSaveData = action.payload;
},
resetFastSave: (state) => {
state.quickSaveData = null;
},
resetOptionSet(state) {
Object.assign(state.optionData, initialOptionSet);
},
Expand All @@ -153,6 +156,7 @@ export const {
resetOptionSet,
resetSaveData,
resetAllData,
resetFastSave,
} = userDataSlice.actions;
export default userDataSlice.reducer;

Expand Down

0 comments on commit 8fa74b1

Please sign in to comment.