webgal-parser 4.4.5-fix2 → 4.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +1 -0
- package/build/cjs/interface/sceneInterface.d.ts +2 -1
- package/build/es/index.js +1 -0
- package/build/es/interface/sceneInterface.d.ts +2 -1
- package/build/types/interface/sceneInterface.d.ts +2 -1
- package/build/umd/index.global.js +1 -0
- package/package.json +40 -40
- package/src/config/scriptConfig.ts +46 -46
- package/src/configParser/configParser.ts +60 -60
- package/src/index.ts +42 -42
- package/src/interface/assets.ts +12 -12
- package/src/interface/runtimeInterface.ts +9 -9
- package/src/interface/sceneInterface.ts +104 -103
- package/src/parser4/index.ts +158 -158
- package/src/sceneParser.ts +47 -47
- package/src/scriptParser/argsParser.ts +68 -68
- package/src/scriptParser/assetsScanner.ts +72 -72
- package/src/scriptParser/commandParser.ts +57 -57
- package/src/scriptParser/contentParser.ts +66 -66
- package/src/scriptParser/scriptParser.ts +87 -87
- package/src/scriptParser/subSceneScanner.ts +23 -23
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import { arg, commandType, IAsset, ISentence, parsedCommand } from "../interface/sceneInterface";
|
|
2
|
-
import { commandParser } from "./commandParser";
|
|
3
|
-
import { argsParser } from "./argsParser";
|
|
4
|
-
import { contentParser } from "./contentParser";
|
|
5
|
-
import { assetsScanner } from "./assetsScanner";
|
|
6
|
-
import { subSceneScanner } from "./subSceneScanner";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 语句解析器
|
|
10
|
-
* @param sentenceRaw 原始语句
|
|
11
|
-
* @param assetSetter
|
|
12
|
-
* @param ADD_NEXT_ARG_LIST
|
|
13
|
-
* @param SCRIPT_CONFIG
|
|
14
|
-
*/
|
|
15
|
-
export const scriptParser = (sentenceRaw: string, assetSetter: any, ADD_NEXT_ARG_LIST: any, SCRIPT_CONFIG: any): ISentence => {
|
|
16
|
-
let command: commandType; // 默认为对话
|
|
17
|
-
let content: string; // 语句内容
|
|
18
|
-
let subScene: Array<string>; // 语句携带的子场景(可能没有)
|
|
19
|
-
const args: Array<arg> = []; // 语句参数列表
|
|
20
|
-
let sentenceAssets: Array<IAsset>; // 语句携带的资源列表
|
|
21
|
-
let parsedCommand: parsedCommand; // 解析后的命令
|
|
22
|
-
let commandRaw: string;
|
|
23
|
-
|
|
24
|
-
// 正式开始解析
|
|
25
|
-
|
|
26
|
-
// 去分号,前面已做,这里不再需要
|
|
27
|
-
let newSentenceRaw = sentenceRaw.split(";")[0];
|
|
28
|
-
if (newSentenceRaw === "") {
|
|
29
|
-
// 注释提前返回
|
|
30
|
-
return {
|
|
31
|
-
command: commandType.comment, // 语句类型
|
|
32
|
-
commandRaw: "comment", // 命令原始内容,方便调试
|
|
33
|
-
content: sentenceRaw.split(";")[1] ?? "", // 语句内容
|
|
34
|
-
args: [{ key: "next", value: true }], // 参数列表
|
|
35
|
-
sentenceAssets: [], // 语句携带的资源列表
|
|
36
|
-
subScene: [] // 语句携带的子场景
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
// 截取命令
|
|
40
|
-
const getCommandResult = /:/.exec(newSentenceRaw);
|
|
41
|
-
/**
|
|
42
|
-
* 拆分命令和语句,同时处理连续对话。
|
|
43
|
-
*/
|
|
44
|
-
// 没有command,说明这是一条连续对话或单条语句
|
|
45
|
-
if (getCommandResult === null) {
|
|
46
|
-
commandRaw = newSentenceRaw;
|
|
47
|
-
parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
48
|
-
command = parsedCommand.type;
|
|
49
|
-
for (const e of parsedCommand.additionalArgs) {
|
|
50
|
-
// 由于是连续对话,所以我们去除 speaker 参数。
|
|
51
|
-
if (command === commandType.say && e.key === "speaker") {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
args.push(e);
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
commandRaw = newSentenceRaw.substring(0, getCommandResult.index);
|
|
58
|
-
// 划分命令区域和content区域
|
|
59
|
-
newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
|
|
60
|
-
parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
61
|
-
command = parsedCommand.type;
|
|
62
|
-
for (const e of parsedCommand.additionalArgs) {
|
|
63
|
-
args.push(e);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// 截取参数区域
|
|
67
|
-
const getArgsResult = / -/.exec(newSentenceRaw);
|
|
68
|
-
// 获取到参数
|
|
69
|
-
if (getArgsResult) {
|
|
70
|
-
const argsRaw = newSentenceRaw.substring(getArgsResult.index, sentenceRaw.length);
|
|
71
|
-
newSentenceRaw = newSentenceRaw.substring(0, getArgsResult.index);
|
|
72
|
-
for (const e of argsParser(argsRaw, assetSetter)) {
|
|
73
|
-
args.push(e);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
content = contentParser(newSentenceRaw, command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
|
|
77
|
-
sentenceAssets = assetsScanner(command, content, args); // 扫描语句携带资源
|
|
78
|
-
subScene = subSceneScanner(command, content); // 扫描语句携带子场景
|
|
79
|
-
return {
|
|
80
|
-
command: command, // 语句类型
|
|
81
|
-
commandRaw: commandRaw, // 命令原始内容,方便调试
|
|
82
|
-
content: content, // 语句内容
|
|
83
|
-
args: args, // 参数列表
|
|
84
|
-
sentenceAssets: sentenceAssets, // 语句携带的资源列表
|
|
85
|
-
subScene: subScene // 语句携带的子场景
|
|
86
|
-
};
|
|
87
|
-
};
|
|
1
|
+
import { arg, commandType, IAsset, ISentence, parsedCommand } from "../interface/sceneInterface";
|
|
2
|
+
import { commandParser } from "./commandParser";
|
|
3
|
+
import { argsParser } from "./argsParser";
|
|
4
|
+
import { contentParser } from "./contentParser";
|
|
5
|
+
import { assetsScanner } from "./assetsScanner";
|
|
6
|
+
import { subSceneScanner } from "./subSceneScanner";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 语句解析器
|
|
10
|
+
* @param sentenceRaw 原始语句
|
|
11
|
+
* @param assetSetter
|
|
12
|
+
* @param ADD_NEXT_ARG_LIST
|
|
13
|
+
* @param SCRIPT_CONFIG
|
|
14
|
+
*/
|
|
15
|
+
export const scriptParser = (sentenceRaw: string, assetSetter: any, ADD_NEXT_ARG_LIST: any, SCRIPT_CONFIG: any): ISentence => {
|
|
16
|
+
let command: commandType; // 默认为对话
|
|
17
|
+
let content: string; // 语句内容
|
|
18
|
+
let subScene: Array<string>; // 语句携带的子场景(可能没有)
|
|
19
|
+
const args: Array<arg> = []; // 语句参数列表
|
|
20
|
+
let sentenceAssets: Array<IAsset>; // 语句携带的资源列表
|
|
21
|
+
let parsedCommand: parsedCommand; // 解析后的命令
|
|
22
|
+
let commandRaw: string;
|
|
23
|
+
|
|
24
|
+
// 正式开始解析
|
|
25
|
+
|
|
26
|
+
// 去分号,前面已做,这里不再需要
|
|
27
|
+
let newSentenceRaw = sentenceRaw.split(";")[0];
|
|
28
|
+
if (newSentenceRaw === "") {
|
|
29
|
+
// 注释提前返回
|
|
30
|
+
return {
|
|
31
|
+
command: commandType.comment, // 语句类型
|
|
32
|
+
commandRaw: "comment", // 命令原始内容,方便调试
|
|
33
|
+
content: sentenceRaw.split(";")[1] ?? "", // 语句内容
|
|
34
|
+
args: [{ key: "next", value: true }], // 参数列表
|
|
35
|
+
sentenceAssets: [], // 语句携带的资源列表
|
|
36
|
+
subScene: [] // 语句携带的子场景
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// 截取命令
|
|
40
|
+
const getCommandResult = /:/.exec(newSentenceRaw);
|
|
41
|
+
/**
|
|
42
|
+
* 拆分命令和语句,同时处理连续对话。
|
|
43
|
+
*/
|
|
44
|
+
// 没有command,说明这是一条连续对话或单条语句
|
|
45
|
+
if (getCommandResult === null) {
|
|
46
|
+
commandRaw = newSentenceRaw;
|
|
47
|
+
parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
48
|
+
command = parsedCommand.type;
|
|
49
|
+
for (const e of parsedCommand.additionalArgs) {
|
|
50
|
+
// 由于是连续对话,所以我们去除 speaker 参数。
|
|
51
|
+
if (command === commandType.say && e.key === "speaker") {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
args.push(e);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
commandRaw = newSentenceRaw.substring(0, getCommandResult.index);
|
|
58
|
+
// 划分命令区域和content区域
|
|
59
|
+
newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
|
|
60
|
+
parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
61
|
+
command = parsedCommand.type;
|
|
62
|
+
for (const e of parsedCommand.additionalArgs) {
|
|
63
|
+
args.push(e);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// 截取参数区域
|
|
67
|
+
const getArgsResult = / -/.exec(newSentenceRaw);
|
|
68
|
+
// 获取到参数
|
|
69
|
+
if (getArgsResult) {
|
|
70
|
+
const argsRaw = newSentenceRaw.substring(getArgsResult.index, sentenceRaw.length);
|
|
71
|
+
newSentenceRaw = newSentenceRaw.substring(0, getArgsResult.index);
|
|
72
|
+
for (const e of argsParser(argsRaw, assetSetter)) {
|
|
73
|
+
args.push(e);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
content = contentParser(newSentenceRaw, command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
|
|
77
|
+
sentenceAssets = assetsScanner(command, content, args); // 扫描语句携带资源
|
|
78
|
+
subScene = subSceneScanner(command, content); // 扫描语句携带子场景
|
|
79
|
+
return {
|
|
80
|
+
command: command, // 语句类型
|
|
81
|
+
commandRaw: commandRaw, // 命令原始内容,方便调试
|
|
82
|
+
content: content, // 语句内容
|
|
83
|
+
args: args, // 参数列表
|
|
84
|
+
sentenceAssets: sentenceAssets, // 语句携带的资源列表
|
|
85
|
+
subScene: subScene // 语句携带的子场景
|
|
86
|
+
};
|
|
87
|
+
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 扫描子场景
|
|
3
|
-
* @param content 语句内容
|
|
4
|
-
* @return {Array<string>} 子场景列表
|
|
5
|
-
*/
|
|
6
|
-
import { commandType } from "../interface/sceneInterface";
|
|
7
|
-
|
|
8
|
-
export const subSceneScanner = (command: commandType, content: string): Array<string> => {
|
|
9
|
-
const subSceneList: Array<string> = [];
|
|
10
|
-
if (command === commandType.changeScene || command === commandType.callScene) {
|
|
11
|
-
subSceneList.push(content);
|
|
12
|
-
}
|
|
13
|
-
if (command === commandType.choose) {
|
|
14
|
-
const chooseList = content.split("|");
|
|
15
|
-
const chooseValue = chooseList.map((e) => e.split(":")[1] ?? "");
|
|
16
|
-
chooseValue.forEach((e) => {
|
|
17
|
-
if (e.match(/\./)) {
|
|
18
|
-
subSceneList.push(e);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return subSceneList;
|
|
23
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* 扫描子场景
|
|
3
|
+
* @param content 语句内容
|
|
4
|
+
* @return {Array<string>} 子场景列表
|
|
5
|
+
*/
|
|
6
|
+
import { commandType } from "../interface/sceneInterface";
|
|
7
|
+
|
|
8
|
+
export const subSceneScanner = (command: commandType, content: string): Array<string> => {
|
|
9
|
+
const subSceneList: Array<string> = [];
|
|
10
|
+
if (command === commandType.changeScene || command === commandType.callScene) {
|
|
11
|
+
subSceneList.push(content);
|
|
12
|
+
}
|
|
13
|
+
if (command === commandType.choose) {
|
|
14
|
+
const chooseList = content.split("|");
|
|
15
|
+
const chooseValue = chooseList.map((e) => e.split(":")[1] ?? "");
|
|
16
|
+
chooseValue.forEach((e) => {
|
|
17
|
+
if (e.match(/\./)) {
|
|
18
|
+
subSceneList.push(e);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return subSceneList;
|
|
23
|
+
};
|