Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
MakinoharaShoko committed Jul 21, 2024
2 parents ec9f494 + 4985366 commit 8da8ee4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
10 changes: 6 additions & 4 deletions packages/webgal/src/Core/controller/stage/playBgm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ export function playBgm(url: string, enter = 0, volume = 100): void {
clearTimeout(emptyBgmTimeout);
webgalStore.dispatch(setStage({ key: 'bgm', value: { src: url, enter: enter, volume: volume } }));
}
const audioElement = document.getElementById('currentBgm') as HTMLAudioElement;
if (audioElement.src) {
audioElement?.play();
}
setTimeout(() => {
const audioElement = document.getElementById('currentBgm') as HTMLAudioElement;
if (audioElement.src) {
audioElement?.play();
}
}, 0);
}
4 changes: 2 additions & 2 deletions packages/webgal/src/Core/gameScripts/setVar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { webgalStore } from '@/store/store';
import { setStageVar } from '@/store/stageReducer';
import { logger } from '@/Core/util/logger';
import { compile } from 'angular-expressions';
import { setGlobalVar } from '@/store/userDataReducer';
import { setScriptManagedGlobalVar } from '@/store/userDataReducer';
import { ActionCreatorWithPayload } from '@reduxjs/toolkit';
import { ISetGameVar } from '@/store/stageInterface';
import { dumpToStorageFast } from '@/Core/controller/storage/storageController';
Expand All @@ -22,7 +22,7 @@ export const setVar = (sentence: ISentence): IPerform => {
});
let targetReducerFunction: ActionCreatorWithPayload<ISetGameVar, string>;
if (setGlobal) {
targetReducerFunction = setGlobalVar;
targetReducerFunction = setScriptManagedGlobalVar;
} else {
targetReducerFunction = setStageVar;
}
Expand Down
16 changes: 8 additions & 8 deletions packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export const infoFetcher = (url: string) => {
// 按照游戏的配置开始设置对应的状态
gameConfig.forEach((e) => {
const { command, args } = e;
let res: any = args[0].trim();
if (/^(true|false)$/g.test(args[0])) {
res = !!res;
} else if (/^[0-9]+\.?[0-9]+$/g.test(args[0])) {
res = Number(res);
}
if (!webgalStore.getState().userData.globalGameVar?.[command]) {
logger.info('首次写入 Game Config');
if (args.length > 0) {
let res: any = args[0].trim();
if (/^(true|false)$/g.test(args[0])) {
res = !!res;
} else if (/^[0-9]+\.?[0-9]+$/g.test(args[0])) {
res = Number(res);
}

dispatch(
setGlobalVar({
key: command,
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 @@ -92,6 +92,7 @@ export interface IAppreciation {
* @interface IUserData 用户数据接口
*/
export interface IUserData {
scriptManagedGlobalVar: string[];
globalGameVar: IGameVar; // 不跟随存档的全局变量
optionData: IOptionData; // 用户设置选项数据
appreciationData: IAppreciation;
Expand Down
12 changes: 12 additions & 0 deletions packages/webgal/src/store/userDataReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const initialOptionSet: IOptionData = {
// 初始化用户数据
export const initState: IUserData = {
optionData: initialOptionSet,
scriptManagedGlobalVar: [],
globalGameVar: {},
appreciationData: {
bgm: [],
Expand Down Expand Up @@ -114,7 +115,17 @@ const userDataSlice = createSlice({
* @param action 要改变或添加的变量
*/
setGlobalVar: (state, action: PayloadAction<ISetGameVar>) => {
const isRegistedInUserData = state.scriptManagedGlobalVar.findIndex((key) => key === action.payload.key) >= 0;
if (!isRegistedInUserData) {
state.globalGameVar[action.payload.key] = action.payload.value;
}
},
setScriptManagedGlobalVar: (state, action: PayloadAction<ISetGameVar>) => {
const isRegistedInUserData = state.scriptManagedGlobalVar.findIndex((key) => key === action.payload.key) >= 0;
state.globalGameVar[action.payload.key] = action.payload.value;
if (!isRegistedInUserData) {
state.scriptManagedGlobalVar.push(action.payload.key);
}
},
/**
* 设置存档/读档页面
Expand All @@ -138,6 +149,7 @@ export const {
resetUserData,
setOptionData,
setGlobalVar,
setScriptManagedGlobalVar,
setSlPage,
unlockCgInUserData,
unlockBgmInUserData,
Expand Down

0 comments on commit 8da8ee4

Please sign in to comment.