Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.5.4 #512

Merged
merged 26 commits into from
Jul 20, 2024
Merged

4.5.4 #512

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
671f156
在into、textbox上增加对常用的符号转义
xiaoxustudio Jun 28, 2024
74a31c7
setVar增加获取游戏运行属性,可用于调试游戏等操作
xiaoxustudio Jun 29, 2024
6de3cee
Merge branch 'dev' into dev1
xiaoxustudio Jun 30, 2024
6533bab
Merge branch 'dev1' of https://github.com/xiaoxustudio/WebGAL into dev29
xiaoxustudio Jul 1, 2024
06b9728
add test txt file
xiaoxustudio Jul 1, 2024
d8b4df2
Merge branch 'OpenWebGAL:main' into dev1
xiaoxustudio Jul 1, 2024
8feddc6
split test files
MakinoharaShoko Jul 2, 2024
d4e737b
修复useEscape解析失败
xiaoxustudio Jul 2, 2024
7131627
Merge branch 'dev1' of https://github.com/xiaoxustudio/WebGAL into dev1
xiaoxustudio Jul 2, 2024
d6dcbc8
Merge pull request #508 from xiaoxustudio/dev1
MakinoharaShoko Jul 3, 2024
de4458c
增加ConfigData
xiaoxustudio Jul 5, 2024
bbc5ea5
Merge branch 'dev29' into dev
xiaoxustudio Jul 5, 2024
4314a6c
use record as the type of ConfigData
MakinoharaShoko Jul 6, 2024
9009477
Reference PR 510
xiaoxustudio Jul 7, 2024
1975f83
Merge branch 'dev' of https://github.com/xiaoxustudio/WebGAL into dev
xiaoxustudio Jul 7, 2024
99e42d2
move test script entry
MakinoharaShoko Jul 7, 2024
c81a09b
Reference PR 510 (2)
xiaoxustudio Jul 7, 2024
35d9871
Merge branch 'dev' of https://github.com/xiaoxustudio/WebGAL into dev
xiaoxustudio Jul 7, 2024
b10cff5
Fixed bug where globalVariable is empty
xiaoxustudio Jul 7, 2024
e7fbcc5
fix: game config handler
MakinoharaShoko Jul 8, 2024
cd61809
fix: lint, setVar, infoFetcher
MakinoharaShoko Jul 8, 2024
a6794f0
fix: optimize setVar
MakinoharaShoko Jul 8, 2024
c238449
fix: sperate stage and userData when get sys vars
MakinoharaShoko Jul 8, 2024
17f7a98
fix: demo var script
MakinoharaShoko Jul 8, 2024
34f1487
Merge pull request #510 from xiaoxustudio/dev
MakinoharaShoko Jul 8, 2024
dbd00b9
update version
MakinoharaShoko Jul 20, 2024
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
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
Loading