Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions packages/parser/src/scriptParser/contentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ function getChooseContent(contentRaw: string, assetSetter: any): string {
const chooseKeyList: Array<string> = [];
const chooseValueList: Array<string> = [];
for (const e of chooseList) {
chooseKeyList.push(e.split(/(?<!\\):/)[0] ?? '');
chooseValueList.push(e.split(/(?<!\\):/)[1] ?? '');
const chooseItem = e.split(/(?<!\\):|(?<!\\):/);
chooseKeyList.push(chooseItem[0] ?? '');
chooseValueList.push(chooseItem[1] ?? '');
}
const parsedChooseList = chooseValueList.map((e) => {
if (e.match(/\./)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/scriptParser/scriptParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const scriptParser = (
};
}
// 截取命令
const getCommandResult = /:/.exec(newSentenceRaw);
const getCommandResult = /(?<!\\):|(?<!\\):/.exec(newSentenceRaw);
/**
* 拆分命令和语句,同时处理连续对话。
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/scriptParser/subSceneScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const subSceneScanner = (
}
if (command === commandType.choose) {
const chooseList = content.split('|');
const chooseValue = chooseList.map((e) => e.split(':')[1] ?? '');
const chooseValue = chooseList.map((e) => e.split(/(?<!\\):|(?<!\\):/)[1] ?? '');
chooseValue.forEach((e) => {
if (e.match(/\./)) {
subSceneList.push(e);
Expand Down
40 changes: 40 additions & 0 deletions packages/parser/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,46 @@ test("choose", async () => {
expect(result.sentenceList).toContainEqual(expectSentenceItem);
});

test("choose supports chinese colon separator", async () => {
const parser = new SceneParser((assetList) => {
}, (fileName, assetType) => {
return fileName;
}, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);

const result = parser.parse(`choose:继续冒险:sceneA.scene|返回城市:sceneB.scene;`, 'test', 'test');

const expectSentenceItem: ISentence = {
command: commandType.choose,
commandRaw: "choose",
content: "继续冒险:sceneA.scene|返回城市:sceneB.scene",
args: [],
sentenceAssets: [],
subScene: ["sceneA.scene", "sceneB.scene"],
inlineComment: ""
};
expect(result.sentenceList).toContainEqual(expectSentenceItem);
});

test("statement supports chinese colon separator", async () => {
const parser = new SceneParser((assetList) => {
}, (fileName, assetType) => {
return fileName;
}, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);

const result = parser.parse(`say:欢迎回来 -speaker=WebGAL;`, 'test', 'test');

const expectSentenceItem: ISentence = {
command: commandType.say,
commandRaw: "say",
content: "欢迎回来",
args: [{ key: 'speaker', value: 'WebGAL' }],
sentenceAssets: [],
subScene: [],
inlineComment: ""
};
expect(result.sentenceList).toContainEqual(expectSentenceItem);
});

test("long-script", async () => {

const sceneRaw = await fsp.readFile('test/test-resources/long-script.txt');
Expand Down