Skip to content

Commit

Permalink
Merge pull request #535 from OpenWebGAL/dev
Browse files Browse the repository at this point in the history
4.5.5
  • Loading branch information
MakinoharaShoko authored Aug 24, 2024
2 parents 4811d32 + 959185e commit cc4ab2c
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 98 deletions.
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.4",
"version": "4.5.5",
"scripts": {
"dev": "vite --host --port 3000",
"build": "cross-env NODE_ENV=production tsc && vite build --base=./",
Expand Down
2 changes: 1 addition & 1 deletion packages/webgal/public/game/scene/demo_zh_cn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ miniAvatar:miniavatar.png;
changeFigure:stand2.png -right -next;
{egine} 是使用 Web 技术开发的引擎,因此在网页端有良好的表现。 -v2.wav;
由于这个特性,如果你将 {egine} 部署到服务器或网页托管平台上,玩家只需要一串链接就可以开始游玩! -v3.wav;
setAnimation:move-front-and-back -target=fig-left -next;
setAnimation:move-front-and-back -target=fig-left -continue;
听起来是不是非常吸引人? -v4.wav;
changeFigure:none -right -next;
setTransform:{"position": {"x": 500,"y": 0}} -target=fig-left -next;
Expand Down
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.4"
"webgal-version":"4.5.5"
}
16 changes: 11 additions & 5 deletions packages/webgal/src/Core/Modules/perform/performController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ export class PerformController {
if (!perform.isHoldOn) {
// 如果不是保持演出,清除
this.unmountPerform(perform.performName);
if (perform.goNextWhenOver) {
// nextSentence();
this.goNextWhenOver();
}
}
}, perform.duration);

if (script.args.find((e) => e.key === 'continue' && e.value === true)) perform.goNextWhenOver = true;

this.performList.push(perform);
}

Expand All @@ -52,6 +50,10 @@ export class PerformController {
if (!e.isHoldOn && e.performName === name) {
e.stopFunction();
clearTimeout(e.stopTimeout as unknown as number);
if (e.goNextWhenOver) {
// nextSentence();
this.goNextWhenOver();
}
this.performList.splice(i, 1);
i--;
}
Expand All @@ -62,6 +64,10 @@ export class PerformController {
if (e.performName === name) {
e.stopFunction();
clearTimeout(e.stopTimeout as unknown as number);
if (e.goNextWhenOver) {
// nextSentence();
this.goNextWhenOver();
}
this.performList.splice(i, 1);
i--;
/**
Expand Down Expand Up @@ -89,7 +95,7 @@ export class PerformController {

private goNextWhenOver() {
let isBlockingAuto = false;
this.performList.forEach((e) => {
this.performList?.forEach((e) => {
if (e.blockingAuto())
// 阻塞且没有结束的演出
isBlockingAuto = true;
Expand Down
2 changes: 2 additions & 0 deletions packages/webgal/src/Core/controller/gamePlay/nextSentence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const nextSentence = () => {
isGoNext = true;
}
if (!e.skipNextCollect) {
// 由于提前结束使用的不是 unmountPerform 标准 API,所以不会触发两次 nextSentence
e.stopFunction();
clearTimeout(e.stopTimeout as unknown as number);
WebGAL.gameplay.performController.performList.splice(i, 1);
Expand All @@ -80,6 +81,7 @@ export const nextSentence = () => {
}
}
if (isGoNext) {
// 由于不使用 unmountPerform 标准 API,这里需要手动收集一下 isGoNext
nextSentence();
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger } from '../../util/logger';
import { IStageState } from '@/store/stageInterface';
import { restoreScene } from '../scene/restoreScene';
import { webgalStore } from '@/store/store';
import { getValueFromState } from '@/Core/gameScripts/setVar';
import { getValueFromStateElseKey } from '@/Core/gameScripts/setVar';
import { strIf } from '@/Core/controller/gamePlay/strIf';
import { nextSentence } from '@/Core/controller/gamePlay/nextSentence';
import cloneDeep from 'lodash/cloneDeep';
Expand All @@ -25,7 +25,7 @@ export const whenChecker = (whenValue: string | undefined): boolean => {
if (e.match(/true/) || e.match(/false/)) {
return e;
}
return getValueFromState(e).toString();
return getValueFromStateElseKey(e);
} else return e;
})
.reduce((pre, curr) => pre + curr, '');
Expand Down Expand Up @@ -59,8 +59,8 @@ export const scriptExecutor = () => {

if (contentExp !== null) {
contentExp.forEach((e) => {
const contentVarValue = getValueFromState(e.replace(/(?<!\\)\{(.*)\}/, '$1'));
retContent = retContent.replace(e, contentVarValue ? contentVarValue.toString() : e);
const contentVarValue = getValueFromStateElseKey(e.replace(/(?<!\\)\{(.*)\}/, '$1'));
retContent = retContent.replace(e, contentVarValue);
});
}
retContent = retContent.replace(/\\{/g, '{').replace(/\\}/g, '}');
Expand Down
22 changes: 16 additions & 6 deletions packages/webgal/src/Core/controller/scene/restoreScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ import { WebGAL } from '@/Core/WebGAL';
* @param entry 场景入口
*/
export const restoreScene = (entry: ISceneEntry) => {
if (WebGAL.sceneManager.lockSceneWrite) {
return;
}
WebGAL.sceneManager.lockSceneWrite = true;
// 场景写入到运行时
sceneFetcher(entry.sceneUrl).then((rawScene) => {
WebGAL.sceneManager.sceneData.currentScene = sceneParser(rawScene, entry.sceneName, entry.sceneUrl);
WebGAL.sceneManager.sceneData.currentSentenceId = entry.continueLine + 1; // 重设场景
logger.debug('现在恢复场景,恢复后场景:', WebGAL.sceneManager.sceneData.currentScene);
nextSentence();
});
sceneFetcher(entry.sceneUrl)
.then((rawScene) => {
WebGAL.sceneManager.sceneData.currentScene = sceneParser(rawScene, entry.sceneName, entry.sceneUrl);
WebGAL.sceneManager.sceneData.currentSentenceId = entry.continueLine + 1; // 重设场景
logger.debug('现在恢复场景,恢复后场景:', WebGAL.sceneManager.sceneData.currentScene);
WebGAL.sceneManager.lockSceneWrite = false;
nextSentence();
})
.catch((e) => {
logger.error('场景调用错误', e);
WebGAL.sceneManager.lockSceneWrite = false;
});
};
1 change: 0 additions & 1 deletion packages/webgal/src/Core/gameScripts/intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export const intro = (sentence: ISentence): IPerform => {
if (!isHold) {
timeout = setTimeout(() => {
WebGAL.gameplay.performController.unmountPerform(performName);
setTimeout(nextSentence, 0);
}, baseDuration);
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/webgal/src/Core/gameScripts/playVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React from 'react';
import ReactDOM from 'react-dom';
import styles from '@/Stage/FullScreenPerform/fullScreenPerform.module.scss';
import { webgalStore } from '@/store/store';
import { nextSentence } from '@/Core/controller/gamePlay/nextSentence';
import { getRandomPerformName, PerformController } from '@/Core/Modules/perform/performController';
import { getSentenceArgByKey } from '@/Core/util/getSentenceArg';
import { WebGAL } from '@/Core/WebGAL';
Expand Down Expand Up @@ -55,7 +54,6 @@ export const playVideo = (sentence: ISentence): IPerform => {
isOver = true;
e.stopFunction();
WebGAL.gameplay.performController.unmountPerform(e.performName);
nextSentence();
}
}
};
Expand Down
5 changes: 4 additions & 1 deletion packages/webgal/src/Core/gameScripts/say.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getRandomPerformName, PerformController } from '@/Core/Modules/perform/
import { getSentenceArgByKey } from '@/Core/util/getSentenceArg';
import { textSize, voiceOption } from '@/store/userDataInterface';
import { WebGAL } from '@/Core/WebGAL';
import { compileSentence } from '@/Stage/TextBox/TextBox';

/**
* 进行普通对话的显示
Expand Down Expand Up @@ -50,7 +51,9 @@ export const say = (sentence: ISentence): IPerform => {
// 计算延迟
const textDelay = useTextDelay(userDataState.optionData.textSpeed);
// 本句延迟
const sentenceDelay = textDelay * sentence.content.length;
const textNodes = compileSentence(sentence.content, 3);
const len = textNodes.reduce((prev, curr) => prev + curr.length, 0);
const sentenceDelay = textDelay * len;

for (const e of sentence.args) {
if (e.key === 'fontSize') {
Expand Down
43 changes: 34 additions & 9 deletions packages/webgal/src/Core/gameScripts/setVar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ export const setVar = (sentence: ISentence): IPerform => {
// 将变量替换为变量的值,然后合成表达式字符串
const valExp2 = valExpArr
.map((e) => {
if (e.match(/\$?[.a-zA-Z]/)) {
return String(getValueFromState(e.trim()));
} else return e;
if (!e.trim().match(/^[a-zA-Z_$][a-zA-Z0-9_.]*$/)) {
// 检查是否是变量名,不是就返回本身
return e;
}
const _r = getValueFromStateElseKey(e.trim());
return typeof _r === 'string' ? `'${_r}'` : _r;
})
.reduce((pre, curr) => pre + curr, '');
const exp = compile(valExp2);
const result = exp();
let result = '';
try {
const exp = compile(valExp2);
result = exp();
} catch (e) {
logger.error('expression compile error', e);
}
webgalStore.dispatch(targetReducerFunction({ key, value: result }));
} else if (valExp.match(/true|false/)) {
if (valExp.match(/true/)) {
Expand All @@ -54,11 +62,13 @@ export const setVar = (sentence: ISentence): IPerform => {
if (valExp.match(/false/)) {
webgalStore.dispatch(targetReducerFunction({ key, value: false }));
}
} else if (valExp.length === 0) {
webgalStore.dispatch(targetReducerFunction({ key, value: '' }));
} else {
if (!isNaN(Number(valExp))) {
webgalStore.dispatch(targetReducerFunction({ key, value: Number(valExp) }));
} else {
webgalStore.dispatch(targetReducerFunction({ key, value: valExp }));
webgalStore.dispatch(targetReducerFunction({ key, value: getValueFromStateElseKey(valExp) }));
}
}
if (setGlobal) {
Expand All @@ -79,10 +89,13 @@ export const setVar = (sentence: ISentence): IPerform => {
};
};

type BaseVal = string | number | boolean;
type BaseVal = string | number | boolean | undefined;

/**
* 取不到时返回 undefined
*/
export function getValueFromState(key: string) {
let ret: any = 0;
let ret: any;
const stage = webgalStore.getState().stage;
const userData = webgalStore.getState().userData;
const _Merge = { stage, userData }; // 不要直接合并到一起,防止可能的键冲突
Expand All @@ -92,7 +105,19 @@ export function getValueFromState(key: string) {
ret = userData.globalGameVar[key];
} else if (key.startsWith('$')) {
const propertyKey = key.replace('$', '');
ret = get(_Merge, propertyKey, 0) as BaseVal;
ret = get(_Merge, propertyKey, undefined) as BaseVal;
}
return ret;
}

/**
* 取不到时返回 key
*/
export function getValueFromStateElseKey(key: string) {
const valueFromState = getValueFromState(key);
if (valueFromState === null || valueFromState === undefined) {
logger.warn('valueFromState result null, key = ' + key);
return key;
}
return valueFromState;
}
33 changes: 21 additions & 12 deletions packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,28 @@ export const infoFetcher = (url: string) => {
gameConfig.forEach((e) => {
const { command, args } = e;
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);
}
if (args.length > 1) {
dispatch(
setGlobalVar({
key: command,
value: args.join('|'),
}),
);
} else {
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,
value: res,
}),
);
dispatch(
setGlobalVar({
key: command,
value: res,
}),
);
}
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/webgal/src/Stage/TextBox/IMSSTextbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export default function IMSSTextbox(props: ITextboxProps) {
let delay = allTextIndex * textDelay;
allTextIndex++;
let prevLength = currentConcatDialogPrev.length;
if (currentConcatDialogPrev !== '' && index >= prevLength) {
if (currentConcatDialogPrev !== '' && allTextIndex >= prevLength) {
delay = delay - prevLength * textDelay;
}
const styleClassName = ' ' + css(style);
const styleAllText = ' ' + css(style_alltext);
if (index < prevLength) {
if (allTextIndex < prevLength) {
return (
<span
// data-text={e}
Expand Down
6 changes: 5 additions & 1 deletion packages/webgal/src/Stage/TextBox/TextBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ function parseString(input: string): Segment[] {
const enhance = match[3];
let parsedEnhanced: KeyValuePair[] = [];
let ruby = '';
if (enhance.match(/style=|tips=|ruby=/)) {
if (enhance.match(/style=|tips=|ruby=|style-alltext=/)) {
parsedEnhanced = parseEnhancedString(enhance);
const rubyKvPair = parsedEnhanced.find((e) => e.key === 'ruby');
if (rubyKvPair) {
ruby = rubyKvPair.value;
}
} else {
ruby = enhance;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webgal/src/UI/Logo/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Logo: FC = () => {
currentLogoIndex.set(0);
currentTimeOutId.set(setTimeout(nextImg, animationDuration));
}
}, [isEnterGame, logoImage]);
}, [isEnterGame]);

const currentLogoUrl = currentLogoIndex.value === -1 ? '' : logoImage[currentLogoIndex.value];
return (
Expand Down
19 changes: 2 additions & 17 deletions packages/webgal/src/config/info.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
export const __INFO = {
version: 'WebGAL 4.5.4',
version: 'WebGAL 4.5.5',
contributors: [
{ username: 'Mahiru', link: 'https://github.com/MakinoharaShoko' },
{ username: 'Hoshinokinya', link: 'https://github.com/hshqwq' },
{ username: 'Junbo Xiong', link: 'https://github.com/C6H5-NO2' },
{ username: 'lykl', link: 'https://github.com/lykl' },
{ username: 'SakuraSnow', link: 'https://github.com/sliyoxn' },
{ username: 'bcqsd', link: 'https://github.com/bcqsd' },
{ username: 'Yuji Sakai', link: 'https://github.com/generalfreed' },
{ username: 'Iara', link: 'https://github.com/labiker' },
{ username: '22', link: 'https://github.com/nini22P' },
{ username: '德布罗煜', link: 'https://github.com/ch1ny' },
{ username: 'Mike Zhou', link: 'https://github.com/mikezzb' },
{ username: 'Murasame0721', link: 'https://github.com/Murasame0721' },
{ username: 'loliko', link: 'https://github.com/loliko114514' },
{ username: 'IdrilK', link: 'https://github.com/IdrilK' },
{ username: 'callofblood', link: 'https://github.com/callofblood' },
{ username: 'lyle', link: 'https://github.com/lylelove' },
// 现在改为跳转到 GitHub 了
],
};
15 changes: 7 additions & 8 deletions packages/webgal/src/hooks/useConfigData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ const useConfigData = () => {
setEbg(titleUrl);
break;
}
/**
* TODO:Game_Logo 是个数组,并且改变后会造成进入游戏界面重新渲染,以后再考虑如何处理
*/
// case 'Game_Logo': {
// const logoUrlList = [assetSetter(val, fileType.background)];
// webgalStore.dispatch(setLogoImage(logoUrlList));
// break;
// }

case 'Game_Logo': {
const logos = val.split('|');
const logoUrlList = logos.map((val) => assetSetter(val, fileType.background));
webgalStore.dispatch(setLogoImage(logoUrlList));
break;
}

case 'Title_bgm': {
const bgmUrl = assetSetter(val, fileType.bgm);
Expand Down
Loading

0 comments on commit cc4ab2c

Please sign in to comment.