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

处理两处Issue #501

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
19 changes: 15 additions & 4 deletions packages/parser/src/scriptParser/scriptParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ export const scriptParser = (
};
}
// 截取命令
const getCommandResult = /:/.exec(newSentenceRaw);
const getCommandResult = /\s*:\s*/.exec(newSentenceRaw);
/**
* 拆分命令和语句,同时处理连续对话。
*/
// 没有command,说明这是一条连续对话或单条语句
if (getCommandResult === null) {
commandRaw = newSentenceRaw;
parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP);
parsedCommand = commandParser(
commandRaw,
ADD_NEXT_ARG_LIST,
SCRIPT_CONFIG_MAP,
);
command = parsedCommand.type;
for (const e of parsedCommand.additionalArgs) {
// 由于是连续对话,所以我们去除 speaker 参数。
Expand All @@ -72,7 +76,11 @@ export const scriptParser = (
getCommandResult.index + 1,
newSentenceRaw.length,
);
parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP);
parsedCommand = commandParser(
commandRaw,
ADD_NEXT_ARG_LIST,
SCRIPT_CONFIG_MAP,
);
command = parsedCommand.type;
for (const e of parsedCommand.additionalArgs) {
args.push(e);
Expand All @@ -91,7 +99,10 @@ export const scriptParser = (
args.push(e);
}
}
content = contentParser(newSentenceRaw, command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
let trimContent =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这几行是在做什么,此时 newSentenceRaw 已经 trim 了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也许我需要重新修改它

newSentenceRaw.substring(0, newSentenceRaw.indexOf(':')).trim() +
newSentenceRaw.substring(newSentenceRaw.indexOf(':') + 1).trim(); // 内容部分去空处理
content = contentParser(trimContent, command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
sentenceAssets = assetsScanner(command, content, args); // 扫描语句携带资源
subScene = subSceneScanner(command, content); // 扫描语句携带子场景
return {
Expand Down
3 changes: 3 additions & 0 deletions packages/parser/test/test-resources/var.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
setVar:a=1;
WebGAL:a=1? -when=a==1;

; : 解析测试
WebGAL : test;
8 changes: 6 additions & 2 deletions packages/webgal/src/Core/controller/gamePlay/strIf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { compile } from 'angular-expressions';

export function strIf(s: string) {
const res = compile(s);
return res();
try {
const res = compile(s);
return res();
} catch {
return false;
}
}
Loading