Skip to content

Commit

Permalink
Merge pull request #512 from OpenWebGAL/dev
Browse files Browse the repository at this point in the history
4.5.4
  • Loading branch information
MakinoharaShoko authored Jul 20, 2024
2 parents ea0f06b + dbd00b9 commit b9c57d9
Show file tree
Hide file tree
Showing 25 changed files with 236 additions and 116 deletions.
2 changes: 1 addition & 1 deletion packages/parser/src/configParser/configParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function configLineParser(inputLine: string): IConfigItem {
};
}
// 截取命令
const getCommandResult = /:/.exec(newSentenceRaw);
const getCommandResult = /\s*:\s*/.exec(newSentenceRaw);

// 没有command
if (getCommandResult === null) {
Expand Down
6 changes: 3 additions & 3 deletions packages/parser/src/scriptParser/contentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export const contentParser = (
};

function getChooseContent(contentRaw: string, assetSetter: any): string {
const chooseList = contentRaw.split('|');
const chooseList = contentRaw.split(/(?<!\\)\|/);
const chooseKeyList: Array<string> = [];
const chooseValueList: Array<string> = [];
for (const e of chooseList) {
chooseKeyList.push(e.split(':')[0] ?? '');
chooseValueList.push(e.split(':')[1] ?? '');
chooseKeyList.push(e.split(/(?<!\\):/)[0] ?? '');
chooseValueList.push(e.split(/(?<!\\):/)[1] ?? '');
}
const parsedChooseList = chooseValueList.map((e) => {
if (e.match(/\./)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webgal/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webgal",
"private": true,
"version": "4.5.3",
"version": "4.5.4",
"scripts": {
"dev": "vite --host --port 3000",
"build": "cross-env NODE_ENV=production tsc && vite build --base=./",
Expand Down
3 changes: 3 additions & 0 deletions packages/webgal/public/game/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ Game_key:0f87dstRg;
Title_img:WebGAL_New_Enter_Image.png;
Title_bgm:s_Title.mp3;
Game_Logo:WebGalEnter.png;
Debug:true;
GameNum:10;
GameNum_Double:20;
15 changes: 15 additions & 0 deletions packages/webgal/public/game/scene/demo_changeConfig.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
webgal:我会修改标题 -hold;
setVar:Game_name=WebGal_Change -global;
webgal:游戏标题已经被我修改为{Game_name} -hold;
webgal:我会修改游戏背景 -hold;
setVar:Title_img=bg.png -global;
webgal:游戏背景已经被我修改为{Title_img} -hold;
webgal:获取Debug值:{Debug} -hold;
setVar:GameNum=15 -global;
webgal:获取并修改GameNum的值:{GameNum} -hold;
setVar:GameNum_Double=GameNum_Double + 5;
webgal:获取GameNum_Double的值,但我不会修改它原本的值:{GameNum_Double} -hold;
webgal:获取bgm声音:{$stage.bgm.volume} -hold;
setVar:bgm_calc= $stage.bgm.volume * 2 ;
webgal:获取bgm声音的两倍是{bgm_calc} -hold;
end;
3 changes: 3 additions & 0 deletions packages/webgal/public/game/scene/demo_escape.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
intro:我会显示出来:\:\,\.\;不信你看看 -hold;
WebGal:我会显示出来:\:\,\.\;不信你看看;
choose:我会显示出来:\:\,\.\;不信你看看;
2 changes: 1 addition & 1 deletion packages/webgal/public/game/scene/demo_var.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ setVar:speaker=WebGAL;
{speaker}:Background now is {bg}.;
{speaker}:\{bg\} is not use interpolation.;
setVar:a=3;
setVar:bg=bg1.png -when=a>2;
setVar:bg=WebGalEnter.png -when=a>2;
changeBg:{bg} -next;
setVar:func=variable interpolation;
{speaker}:Bg changed! Welcome to {speaker} {func}!;
Expand Down
1 change: 1 addition & 0 deletions packages/webgal/public/game/scene/function_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
choose:Lip Sync Animation Test:demo_animation.txt | Variable interpolation test:demo_var.txt | Change Config:demo_changeConfig.txt;
2 changes: 1 addition & 1 deletion packages/webgal/public/game/scene/start.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
setVar:heroine=WebGAL;
setVar:egine=WebGAL;
choose:简体中文:demo_zh_cn.txt|日本語:demo_ja.txt|English:demo_en.txt|Lip Sync Animation Test:demo_animation.txt | Variable interpolation test:demo_var.txt;
choose:简体中文:demo_zh_cn.txt|日本語:demo_ja.txt|English:demo_en.txt|Test:function_test.txt;
2 changes: 1 addition & 1 deletion packages/webgal/public/game/template/template.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name":"Default Template",
"webgal-version":"4.5.3"
"webgal-version":"4.5.4"
}
10 changes: 5 additions & 5 deletions packages/webgal/src/Core/gameScripts/choose/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PerformController } from '@/Core/Modules/perform/performController';
import { useSEByWebgalStore } from '@/hooks/useSoundEffect';
import { WebGAL } from '@/Core/WebGAL';
import { whenChecker } from '@/Core/controller/gamePlay/scriptExecutor';
import useEscape from '@/hooks/useEscape';
import useApplyStyle from '@/hooks/useApplyStyle';
import { Provider } from 'react-redux';

Expand All @@ -23,8 +24,7 @@ class ChooseOption {
const parts = script.split('->');
const conditonPart = parts.length > 1 ? parts[0] : null;
const mainPart = parts.length > 1 ? parts[1] : parts[0];
const mainPartNodes = mainPart.split(':');

const mainPartNodes = mainPart.split(/(?<!\\):/g);
const option = new ChooseOption(mainPartNodes[0], mainPartNodes[1]);
if (conditonPart !== null) {
const showConditionPart = conditonPart.match(/\((.*)\)/);
Expand All @@ -45,9 +45,9 @@ class ChooseOption {
public enableCondition?: string;

public constructor(text: string, jump: string) {
this.text = text;
this.text = useEscape(text);
this.jump = jump;
this.jumpToScene = jump.match(/\./) !== null;
this.jumpToScene = jump.match(/(?<!\\)\./) !== null;
}
}

Expand All @@ -56,7 +56,7 @@ class ChooseOption {
* @param sentence
*/
export const choose = (sentence: ISentence): IPerform => {
const chooseOptionScripts = sentence.content.split('|');
const chooseOptionScripts = sentence.content.split(/(?<!\\)\|/);
const chooseOptions = chooseOptionScripts.map((e) => ChooseOption.parse(e));

// eslint-disable-next-line react/no-deprecated
Expand Down
4 changes: 3 additions & 1 deletion packages/webgal/src/Core/gameScripts/intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { nextSentence } from '@/Core/controller/gamePlay/nextSentence';
import { PerformController } from '@/Core/Modules/perform/performController';
import { logger } from '@/Core/util/logger';
import { WebGAL } from '@/Core/WebGAL';
import { replace } from 'lodash';
import useEscape from '@/hooks/useEscape';
/**
* 显示一小段黑屏演示
* @param sentence
Expand Down Expand Up @@ -81,7 +83,7 @@ export const intro = (sentence: ISentence): IPerform => {
width: '100%',
height: '100%',
};
const introArray: Array<string> = sentence.content.split(/\|/);
const introArray: Array<string> = sentence.content.split(/(?<!\\)\|/).map((val: string) => useEscape(val));

let endWait = 1000;
let baseDuration = endWait + delayTime * introArray.length;
Expand Down
34 changes: 22 additions & 12 deletions packages/webgal/src/Core/gameScripts/setVar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { setGlobalVar } from '@/store/userDataReducer';
import { ActionCreatorWithPayload } from '@reduxjs/toolkit';
import { ISetGameVar } from '@/store/stageInterface';
import { dumpToStorageFast } from '@/Core/controller/storage/storageController';

import get from 'lodash/get';
/**
* 设置变量
* @param sentence
Expand All @@ -27,9 +27,9 @@ export const setVar = (sentence: ISentence): IPerform => {
targetReducerFunction = setStageVar;
}
// 先把表达式拆分为变量名和赋值语句
if (sentence.content.match(/=/)) {
const key = sentence.content.split(/=/)[0];
const valExp = sentence.content.split(/=/)[1];
if (sentence.content.match(/\s*=\s*/)) {
const key = sentence.content.split(/\s*=\s*/)[0];
const valExp = sentence.content.split(/\s*=\s*/)[1];
if (valExp === 'random()') {
webgalStore.dispatch(targetReducerFunction({ key, value: Math.random() }));
} else if (valExp.match(/[+\-*\/()]/)) {
Expand All @@ -39,8 +39,8 @@ export const setVar = (sentence: ISentence): IPerform => {
// 将变量替换为变量的值,然后合成表达式字符串
const valExp2 = valExpArr
.map((e) => {
if (e.match(/[a-zA-Z]/)) {
return getValueFromState(e).toString();
if (e.match(/\$?[.a-zA-Z]/)) {
return String(getValueFromState(e.trim()));
} else return e;
})
.reduce((pre, curr) => pre + curr, '');
Expand All @@ -57,7 +57,9 @@ export const setVar = (sentence: ISentence): IPerform => {
} else {
if (!isNaN(Number(valExp))) {
webgalStore.dispatch(targetReducerFunction({ key, value: Number(valExp) }));
} else webgalStore.dispatch(targetReducerFunction({ key, value: valExp }));
} else {
webgalStore.dispatch(targetReducerFunction({ key, value: valExp }));
}
}
if (setGlobal) {
logger.debug('设置全局变量:', { key, value: webgalStore.getState().userData.globalGameVar[key] });
Expand All @@ -77,12 +79,20 @@ export const setVar = (sentence: ISentence): IPerform => {
};
};

type BaseVal = string | number | boolean;

export function getValueFromState(key: string) {
let ret: number | string | boolean = 0;
if (webgalStore.getState().stage.GameVar.hasOwnProperty(key)) {
ret = webgalStore.getState().stage.GameVar[key];
} else if (webgalStore.getState().userData.globalGameVar.hasOwnProperty(key)) {
ret = webgalStore.getState().userData.globalGameVar[key];
let ret: any = 0;
const stage = webgalStore.getState().stage;
const userData = webgalStore.getState().userData;
const _Merge = { stage, userData }; // 不要直接合并到一起,防止可能的键冲突
if (stage.GameVar.hasOwnProperty(key)) {
ret = stage.GameVar[key];
} else if (userData.globalGameVar.hasOwnProperty(key)) {
ret = userData.globalGameVar[key];
} else if (key.startsWith('$')) {
const propertyKey = key.replace('$', '');
ret = get(_Merge, propertyKey, 0) as BaseVal;
}
return ret;
}
77 changes: 30 additions & 47 deletions packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import axios from 'axios';
import { logger } from '../logger';
import { assetSetter, fileType } from '../gameAssetsAccess/assetSetter';
import { getStorage } from '../../controller/storage/storageController';
import { getStorage, getStorageAsync, setStorage } from '../../controller/storage/storageController';
import { webgalStore } from '@/store/store';
import { setGuiAsset, setLogoImage } from '@/store/GUIReducer';
import { setEbg } from '@/Core/gameScripts/changeBg/setEbg';
import { initKey } from '@/Core/controller/storage/fastSaveLoad';
import { WebgalParser } from '@/Core/parser/sceneParser';
import { WebGAL } from '@/Core/WebGAL';
import { getFastSaveFromStorage, getSavesFromStorage } from '@/Core/controller/storage/savesController';
import { setGlobalVar } from '@/store/userDataReducer';

declare global {
interface Window {
Expand All @@ -20,55 +18,40 @@ declare global {
* @param url 游戏信息路径
*/
export const infoFetcher = (url: string) => {
const GUIState = webgalStore.getState().GUI;
const dispatch = webgalStore.dispatch;
axios.get(url).then((r) => {
axios.get(url).then(async (r) => {
let gameConfigRaw: string = r.data;
const gameConfig = WebgalParser.parseConfig(gameConfigRaw);
let gameConfig = WebgalParser.parseConfig(gameConfigRaw);
logger.info('获取到游戏信息', gameConfig);
// 先把 key 找到并设置了
const keyItem = gameConfig.find((e) => e.command === 'Game_key');
WebGAL.gameKey = (keyItem?.args?.[0] as string) ?? '';
initKey();
await getStorageAsync();
getFastSaveFromStorage();
getSavesFromStorage(0, 0);
// 按照游戏的配置开始设置对应的状态
if (GUIState) {
gameConfig.forEach((e) => {
const { command, args } = e;

switch (command) {
case 'Title_img': {
const titleUrl = assetSetter(args.join(''), fileType.background);
dispatch(setGuiAsset({ asset: 'titleBg', value: titleUrl }));
setEbg(titleUrl);
break;
}

case 'Game_Logo': {
const logoUrlList = args.map((url) => assetSetter(url, fileType.background));
dispatch(setLogoImage(logoUrlList));
break;
}
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');
dispatch(
setGlobalVar({
key: command,
value: res,
}),
);
}
});

case 'Title_bgm': {
const bgmUrl = assetSetter(args[0], fileType.bgm);
dispatch(setGuiAsset({ asset: 'titleBgm', value: bgmUrl }));
break;
}

case 'Game_name': {
WebGAL.gameName = args[0];
document.title = args[0];
break;
}

case 'Game_key': {
WebGAL.gameKey = args[0];
getStorage();
getFastSaveFromStorage();
getSavesFromStorage(0, 0);
break;
}
}
});
}
window?.renderPromise?.();
delete window.renderPromise;
initKey();
setStorage();
});
};
2 changes: 1 addition & 1 deletion packages/webgal/src/Stage/MainStage/useSetBg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ function addBg(type?: 'image' | 'spine', ...args: any[]) {
// @ts-ignore
return WebGAL.gameplay.pixiStage?.addBg(...args);
}
}
}
3 changes: 2 additions & 1 deletion packages/webgal/src/Stage/TextBox/TextBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { match } from '@/Core/util/match';
import { textSize } from '@/store/userDataInterface';
import IMSSTextbox from '@/Stage/TextBox/IMSSTextbox';
import { SCREEN_CONSTANTS } from '@/Core/util/constants';
import useEscape from '@/hooks/useEscape';

const userAgent = navigator.userAgent;
const isFirefox = /firefox/i.test(userAgent);
Expand Down Expand Up @@ -100,7 +101,7 @@ function isCJK(character: string) {

export function compileSentence(sentence: string, lineLimit: number, ignoreLineLimit?: boolean): EnhancedNode[][] {
// 先拆行
const lines = sentence.split('|');
const lines = sentence.split(/(?<!\\)\|/).map((val: string) => useEscape(val));
// 对每一行进行注音处理
const rubyLines = lines.map((line) => parseString(line));
const nodeLines = rubyLines.map((line) => {
Expand Down
10 changes: 3 additions & 7 deletions packages/webgal/src/UI/Title/Title.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { FC } from 'react';
import { FC, useEffect } from 'react';
import styles from './title.module.scss';
import { playBgm } from '@/Core/controller/stage/playBgm';
import { continueGame, startGame } from '@/Core/controller/gamePlay/startContinueGame';
import { useDispatch, useSelector } from 'react-redux';
import { RootState, webgalStore } from '@/store/store';
import { setMenuPanelTag, setVisibility } from '@/store/GUIReducer';
import { MenuPanelTag } from '@/store/guiInterface';
import { nextSentence } from '@/Core/controller/gamePlay/nextSentence';
import { restorePerform } from '@/Core/controller/storage/jumpFromBacklog';
import { setEbg } from '@/Core/gameScripts/changeBg/setEbg';
import useTrans from '@/hooks/useTrans';
// import { resize } from '@/Core/util/resize';
import { hasFastSaveRecord, loadFastSaveGame } from '@/Core/controller/storage/fastSaveLoad';
import useSoundEffect from '@/hooks/useSoundEffect';
import { WebGAL } from '@/Core/WebGAL';
import useApplyStyle from '@/hooks/useApplyStyle';
import { fullScreenOption } from '@/store/userDataInterface';
import { keyboard } from '@/hooks/useHotkey';

import useConfigData from '@/hooks/useConfigData';
/**
* 标题页
* @constructor
Expand All @@ -33,7 +29,7 @@ const Title: FC = () => {
const { playSeEnter, playSeClick } = useSoundEffect();

const applyStyle = useApplyStyle('UI/Title/title.scss');

useConfigData(); // 监听基础ConfigData变化
return (
<>
{GUIState.showTitle && <div className={applyStyle('Title_backup_background', styles.Title_backup_background)} />}
Expand Down
2 changes: 1 addition & 1 deletion packages/webgal/src/config/info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const __INFO = {
version: 'WebGAL 4.5.3',
version: 'WebGAL 4.5.4',
contributors: [
{ username: 'Mahiru', link: 'https://github.com/MakinoharaShoko' },
{ username: 'Hoshinokinya', link: 'https://github.com/hshqwq' },
Expand Down
Loading

0 comments on commit b9c57d9

Please sign in to comment.