webgal-parser 4.3.5 → 4.3.6

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.
Files changed (40) hide show
  1. package/build/index.global.js +421 -421
  2. package/build/index.js +421 -421
  3. package/build/types/index.d.ts +10 -10
  4. package/build/types/interface/assets.d.ts +12 -12
  5. package/build/types/interface/runtimeInterface.d.ts +9 -9
  6. package/build/types/interface/sceneInterface.d.ts +91 -91
  7. package/build/types/sceneParser.d.ts +14 -14
  8. package/build/types/scriptParser/argsParser.d.ts +9 -9
  9. package/build/types/scriptParser/assetsScanner.d.ts +9 -9
  10. package/build/types/scriptParser/commandParser.d.ts +9 -9
  11. package/build/types/scriptParser/contentParser.d.ts +9 -9
  12. package/build/types/scriptParser/scriptParser.d.ts +9 -9
  13. package/build/types/scriptParser/subSceneScanner.d.ts +7 -7
  14. package/index.d.ts +10 -10
  15. package/index.js +421 -421
  16. package/interface/assets.d.ts +12 -12
  17. package/interface/assets.js +16 -16
  18. package/interface/runtimeInterface.d.ts +9 -9
  19. package/interface/runtimeInterface.js +2 -2
  20. package/interface/sceneInterface.d.ts +91 -91
  21. package/interface/sceneInterface.js +32 -32
  22. package/interface/sceneInterface.ts +1 -0
  23. package/package.json +1 -1
  24. package/sceneParser.d.ts +14 -14
  25. package/sceneParser.js +53 -53
  26. package/scriptParser/argsParser.d.ts +9 -9
  27. package/scriptParser/argsParser.js +70 -70
  28. package/scriptParser/assetsScanner.d.ts +9 -9
  29. package/scriptParser/assetsScanner.js +75 -75
  30. package/scriptParser/assetsScanner.ts +10 -2
  31. package/scriptParser/commandParser.d.ts +9 -9
  32. package/scriptParser/commandParser.js +60 -60
  33. package/scriptParser/contentParser.d.ts +9 -9
  34. package/scriptParser/contentParser.js +68 -68
  35. package/scriptParser/contentParser.ts +2 -0
  36. package/scriptParser/scriptParser.d.ts +9 -9
  37. package/scriptParser/scriptParser.js +81 -81
  38. package/scriptParser/subSceneScanner.d.ts +7 -7
  39. package/scriptParser/subSceneScanner.js +26 -26
  40. package/test/test.ts +1 -1
package/build/index.js CHANGED
@@ -1,444 +1,444 @@
1
1
  import * as __ from 'lodash';
2
2
 
3
- var commandType;
4
- (function (commandType) {
5
- commandType[commandType["say"] = 0] = "say";
6
- commandType[commandType["changeBg"] = 1] = "changeBg";
7
- commandType[commandType["changeFigure"] = 2] = "changeFigure";
8
- commandType[commandType["bgm"] = 3] = "bgm";
9
- commandType[commandType["video"] = 4] = "video";
10
- commandType[commandType["pixi"] = 5] = "pixi";
11
- commandType[commandType["pixiInit"] = 6] = "pixiInit";
12
- commandType[commandType["intro"] = 7] = "intro";
13
- commandType[commandType["miniAvatar"] = 8] = "miniAvatar";
14
- commandType[commandType["changeScene"] = 9] = "changeScene";
15
- commandType[commandType["choose"] = 10] = "choose";
16
- commandType[commandType["end"] = 11] = "end";
17
- commandType[commandType["setComplexAnimation"] = 12] = "setComplexAnimation";
18
- commandType[commandType["setFilter"] = 13] = "setFilter";
19
- commandType[commandType["label"] = 14] = "label";
20
- commandType[commandType["jumpLabel"] = 15] = "jumpLabel";
21
- commandType[commandType["chooseLabel"] = 16] = "chooseLabel";
22
- commandType[commandType["setVar"] = 17] = "setVar";
23
- commandType[commandType["if"] = 18] = "if";
24
- commandType[commandType["callScene"] = 19] = "callScene";
25
- commandType[commandType["showVars"] = 20] = "showVars";
26
- commandType[commandType["unlockCg"] = 21] = "unlockCg";
27
- commandType[commandType["unlockBgm"] = 22] = "unlockBgm";
28
- commandType[commandType["filmMode"] = 23] = "filmMode";
29
- commandType[commandType["setTextbox"] = 24] = "setTextbox";
30
- commandType[commandType["setAnimation"] = 25] = "setAnimation";
3
+ var commandType;
4
+ (function (commandType) {
5
+ commandType[commandType["say"] = 0] = "say";
6
+ commandType[commandType["changeBg"] = 1] = "changeBg";
7
+ commandType[commandType["changeFigure"] = 2] = "changeFigure";
8
+ commandType[commandType["bgm"] = 3] = "bgm";
9
+ commandType[commandType["video"] = 4] = "video";
10
+ commandType[commandType["pixi"] = 5] = "pixi";
11
+ commandType[commandType["pixiInit"] = 6] = "pixiInit";
12
+ commandType[commandType["intro"] = 7] = "intro";
13
+ commandType[commandType["miniAvatar"] = 8] = "miniAvatar";
14
+ commandType[commandType["changeScene"] = 9] = "changeScene";
15
+ commandType[commandType["choose"] = 10] = "choose";
16
+ commandType[commandType["end"] = 11] = "end";
17
+ commandType[commandType["setComplexAnimation"] = 12] = "setComplexAnimation";
18
+ commandType[commandType["setFilter"] = 13] = "setFilter";
19
+ commandType[commandType["label"] = 14] = "label";
20
+ commandType[commandType["jumpLabel"] = 15] = "jumpLabel";
21
+ commandType[commandType["chooseLabel"] = 16] = "chooseLabel";
22
+ commandType[commandType["setVar"] = 17] = "setVar";
23
+ commandType[commandType["if"] = 18] = "if";
24
+ commandType[commandType["callScene"] = 19] = "callScene";
25
+ commandType[commandType["showVars"] = 20] = "showVars";
26
+ commandType[commandType["unlockCg"] = 21] = "unlockCg";
27
+ commandType[commandType["unlockBgm"] = 22] = "unlockBgm";
28
+ commandType[commandType["filmMode"] = 23] = "filmMode";
29
+ commandType[commandType["setTextbox"] = 24] = "setTextbox";
30
+ commandType[commandType["setAnimation"] = 25] = "setAnimation";
31
31
  })(commandType || (commandType = {}));
32
32
 
33
- /**
34
- * 处理命令
35
- * @param commandRaw
36
- * @param ADD_NEXT_ARG_LIST
37
- * @param SCRIPT_CONFIG
38
- * @return {parsedCommand} 处理后的命令
39
- */
40
- const commandParser = (commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
41
- let returnCommand = {
42
- type: commandType.say,
43
- additionalArgs: []
44
- };
45
- // 开始处理命令内容
46
- const type = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
47
- returnCommand.type = type;
48
- // 如果是对话,加上额外的参数
49
- if (type === commandType.say) {
50
- returnCommand.additionalArgs.push({
51
- key: "speaker",
52
- value: commandRaw
53
- });
54
- }
55
- returnCommand = addNextArg(returnCommand, type, ADD_NEXT_ARG_LIST);
56
- return returnCommand;
57
- };
58
- /**
59
- * 根据command原始值判断是什么命令
60
- * @param command command原始值
61
- * @param ADD_NEXT_ARG_LIST
62
- * @param SCRIPT_CONFIG
63
- * @return {commandType} 得到的command类型
64
- */
65
- function getCommandType(command, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
66
- // if (command.match(/if/)) {
67
- // return commandType.if;
68
- // }
69
- const commandMap = new Map();
70
- SCRIPT_CONFIG.forEach((e) => {
71
- commandMap.set(e.scriptString, e.scriptType);
72
- });
73
- if (commandMap.has(command)) {
74
- return commandMap.get(command);
75
- }
76
- else
77
- return commandType.say;
78
- }
79
- function addNextArg(commandToParse, thisCommandType, ADD_NEXT_ARG_LIST) {
80
- if (ADD_NEXT_ARG_LIST.includes(thisCommandType)) {
81
- commandToParse.additionalArgs.push({
82
- key: "next",
83
- value: true
84
- });
85
- }
86
- return commandToParse;
33
+ /**
34
+ * 处理命令
35
+ * @param commandRaw
36
+ * @param ADD_NEXT_ARG_LIST
37
+ * @param SCRIPT_CONFIG
38
+ * @return {parsedCommand} 处理后的命令
39
+ */
40
+ const commandParser = (commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
41
+ let returnCommand = {
42
+ type: commandType.say,
43
+ additionalArgs: []
44
+ };
45
+ // 开始处理命令内容
46
+ const type = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
47
+ returnCommand.type = type;
48
+ // 如果是对话,加上额外的参数
49
+ if (type === commandType.say) {
50
+ returnCommand.additionalArgs.push({
51
+ key: "speaker",
52
+ value: commandRaw
53
+ });
54
+ }
55
+ returnCommand = addNextArg(returnCommand, type, ADD_NEXT_ARG_LIST);
56
+ return returnCommand;
57
+ };
58
+ /**
59
+ * 根据command原始值判断是什么命令
60
+ * @param command command原始值
61
+ * @param ADD_NEXT_ARG_LIST
62
+ * @param SCRIPT_CONFIG
63
+ * @return {commandType} 得到的command类型
64
+ */
65
+ function getCommandType(command, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
66
+ // if (command.match(/if/)) {
67
+ // return commandType.if;
68
+ // }
69
+ const commandMap = new Map();
70
+ SCRIPT_CONFIG.forEach((e) => {
71
+ commandMap.set(e.scriptString, e.scriptType);
72
+ });
73
+ if (commandMap.has(command)) {
74
+ return commandMap.get(command);
75
+ }
76
+ else
77
+ return commandType.say;
78
+ }
79
+ function addNextArg(commandToParse, thisCommandType, ADD_NEXT_ARG_LIST) {
80
+ if (ADD_NEXT_ARG_LIST.includes(thisCommandType)) {
81
+ commandToParse.additionalArgs.push({
82
+ key: "next",
83
+ value: true
84
+ });
85
+ }
86
+ return commandToParse;
87
87
  }
88
88
 
89
- /**
90
- * 内置资源类型的枚举
91
- */
92
- var fileType;
93
- (function (fileType) {
94
- fileType[fileType["background"] = 0] = "background";
95
- fileType[fileType["bgm"] = 1] = "bgm";
96
- fileType[fileType["figure"] = 2] = "figure";
97
- fileType[fileType["scene"] = 3] = "scene";
98
- fileType[fileType["tex"] = 4] = "tex";
99
- fileType[fileType["vocal"] = 5] = "vocal";
100
- fileType[fileType["video"] = 6] = "video";
89
+ /**
90
+ * 内置资源类型的枚举
91
+ */
92
+ var fileType;
93
+ (function (fileType) {
94
+ fileType[fileType["background"] = 0] = "background";
95
+ fileType[fileType["bgm"] = 1] = "bgm";
96
+ fileType[fileType["figure"] = 2] = "figure";
97
+ fileType[fileType["scene"] = 3] = "scene";
98
+ fileType[fileType["tex"] = 4] = "tex";
99
+ fileType[fileType["vocal"] = 5] = "vocal";
100
+ fileType[fileType["video"] = 6] = "video";
101
101
  })(fileType || (fileType = {}));
102
102
 
103
- /**
104
- * 参数解析器
105
- * @param argsRaw 原始参数字符串
106
- * @param assetSetter
107
- * @return {Array<arg>} 解析后的参数列表
108
- */
109
- function argsParser(argsRaw, assetSetter) {
110
- const returnArrayList = [];
111
- // 处理参数
112
- // 不要去空格
113
- let newArgsRaw = argsRaw.replace(/ /g, " ");
114
- // 分割参数列表
115
- let rawArgsList = newArgsRaw.split(" -");
116
- // 去除空字符串
117
- rawArgsList = rawArgsList.filter((e) => {
118
- return e !== "";
119
- });
120
- rawArgsList.forEach((e) => {
121
- const argName = e.split("=")[0];
122
- const argValue = e.split("=")[1];
123
- // 判断是不是语音参数
124
- if (e.match(/.ogg|.mp3|.wav/)) {
125
- returnArrayList.push({
126
- key: "vocal",
127
- value: assetSetter(e, fileType.vocal)
128
- });
129
- }
130
- else {
131
- // 判断是不是省略参数
132
- if (argValue === undefined) {
133
- returnArrayList.push({
134
- key: argName,
135
- value: true
136
- });
137
- }
138
- else {
139
- // 是字符串描述的布尔值
140
- if (argValue === "true" || argValue === "false") {
141
- returnArrayList.push({
142
- key: argName,
143
- value: argValue === "true"
144
- });
145
- }
146
- else {
147
- // 是数字
148
- if (!isNaN(Number(argValue))) {
149
- returnArrayList.push({
150
- key: argName,
151
- value: Number(argValue)
152
- });
153
- }
154
- else {
155
- // 是普通参数
156
- returnArrayList.push({
157
- key: argName,
158
- value: argValue
159
- });
160
- }
161
- }
162
- }
163
- }
164
- });
165
- return returnArrayList;
103
+ /**
104
+ * 参数解析器
105
+ * @param argsRaw 原始参数字符串
106
+ * @param assetSetter
107
+ * @return {Array<arg>} 解析后的参数列表
108
+ */
109
+ function argsParser(argsRaw, assetSetter) {
110
+ const returnArrayList = [];
111
+ // 处理参数
112
+ // 不要去空格
113
+ let newArgsRaw = argsRaw.replace(/ /g, " ");
114
+ // 分割参数列表
115
+ let rawArgsList = newArgsRaw.split(" -");
116
+ // 去除空字符串
117
+ rawArgsList = rawArgsList.filter((e) => {
118
+ return e !== "";
119
+ });
120
+ rawArgsList.forEach((e) => {
121
+ const argName = e.split("=")[0];
122
+ const argValue = e.split("=")[1];
123
+ // 判断是不是语音参数
124
+ if (e.match(/.ogg|.mp3|.wav/)) {
125
+ returnArrayList.push({
126
+ key: "vocal",
127
+ value: assetSetter(e, fileType.vocal)
128
+ });
129
+ }
130
+ else {
131
+ // 判断是不是省略参数
132
+ if (argValue === undefined) {
133
+ returnArrayList.push({
134
+ key: argName,
135
+ value: true
136
+ });
137
+ }
138
+ else {
139
+ // 是字符串描述的布尔值
140
+ if (argValue === "true" || argValue === "false") {
141
+ returnArrayList.push({
142
+ key: argName,
143
+ value: argValue === "true"
144
+ });
145
+ }
146
+ else {
147
+ // 是数字
148
+ if (!isNaN(Number(argValue))) {
149
+ returnArrayList.push({
150
+ key: argName,
151
+ value: Number(argValue)
152
+ });
153
+ }
154
+ else {
155
+ // 是普通参数
156
+ returnArrayList.push({
157
+ key: argName,
158
+ value: argValue
159
+ });
160
+ }
161
+ }
162
+ }
163
+ }
164
+ });
165
+ return returnArrayList;
166
166
  }
167
167
 
168
- /**
169
- * 解析语句内容的函数,主要作用是把文件名改为绝对地址或相对地址(根据使用情况而定)
170
- * @param contentRaw 原始语句内容
171
- * @param type 语句类型
172
- * @param assetSetter
173
- * @return {string} 解析后的语句内容
174
- */
175
- const contentParser = (contentRaw, type, assetSetter) => {
176
- if (contentRaw === "none" || contentRaw === "") {
177
- return "";
178
- }
179
- switch (type) {
180
- case commandType.changeBg:
181
- return assetSetter(contentRaw, fileType.background);
182
- case commandType.changeFigure:
183
- return assetSetter(contentRaw, fileType.figure);
184
- case commandType.bgm:
185
- return assetSetter(contentRaw, fileType.bgm);
186
- case commandType.callScene:
187
- return assetSetter(contentRaw, fileType.scene);
188
- case commandType.changeScene:
189
- return assetSetter(contentRaw, fileType.scene);
190
- case commandType.miniAvatar:
191
- return assetSetter(contentRaw, fileType.figure);
192
- case commandType.video:
193
- return assetSetter(contentRaw, fileType.video);
194
- case commandType.choose:
195
- return getChooseContent(contentRaw, assetSetter);
196
- case commandType.unlockBgm:
197
- return assetSetter(contentRaw, fileType.bgm);
198
- case commandType.unlockCg:
199
- return assetSetter(contentRaw, fileType.background);
200
- default:
201
- return contentRaw;
202
- }
203
- };
204
- function getChooseContent(contentRaw, assetSetter) {
205
- const chooseList = contentRaw.split("|");
206
- const chooseKeyList = [];
207
- const chooseValueList = [];
208
- for (const e of chooseList) {
209
- chooseKeyList.push(e.split(":")[0]);
210
- chooseValueList.push(e.split(":")[1]);
211
- }
212
- const parsedChooseList = chooseValueList.map((e) => {
213
- if (e.match(/\./)) {
214
- return assetSetter(e, fileType.scene);
215
- }
216
- else {
217
- return e;
218
- }
219
- });
220
- let ret = "";
221
- for (let i = 0; i < chooseKeyList.length; i++) {
222
- if (i !== 0) {
223
- ret = ret + "|";
224
- }
225
- ret = ret + `${chooseKeyList[i]}:${parsedChooseList[i]}`;
226
- }
227
- return ret;
168
+ /**
169
+ * 解析语句内容的函数,主要作用是把文件名改为绝对地址或相对地址(根据使用情况而定)
170
+ * @param contentRaw 原始语句内容
171
+ * @param type 语句类型
172
+ * @param assetSetter
173
+ * @return {string} 解析后的语句内容
174
+ */
175
+ const contentParser = (contentRaw, type, assetSetter) => {
176
+ if (contentRaw === "none" || contentRaw === "") {
177
+ return "";
178
+ }
179
+ switch (type) {
180
+ case commandType.changeBg:
181
+ return assetSetter(contentRaw, fileType.background);
182
+ case commandType.changeFigure:
183
+ return assetSetter(contentRaw, fileType.figure);
184
+ case commandType.bgm:
185
+ return assetSetter(contentRaw, fileType.bgm);
186
+ case commandType.callScene:
187
+ return assetSetter(contentRaw, fileType.scene);
188
+ case commandType.changeScene:
189
+ return assetSetter(contentRaw, fileType.scene);
190
+ case commandType.miniAvatar:
191
+ return assetSetter(contentRaw, fileType.figure);
192
+ case commandType.video:
193
+ return assetSetter(contentRaw, fileType.video);
194
+ case commandType.choose:
195
+ return getChooseContent(contentRaw, assetSetter);
196
+ case commandType.unlockBgm:
197
+ return assetSetter(contentRaw, fileType.bgm);
198
+ case commandType.unlockCg:
199
+ return assetSetter(contentRaw, fileType.background);
200
+ default:
201
+ return contentRaw;
202
+ }
203
+ };
204
+ function getChooseContent(contentRaw, assetSetter) {
205
+ const chooseList = contentRaw.split("|");
206
+ const chooseKeyList = [];
207
+ const chooseValueList = [];
208
+ for (const e of chooseList) {
209
+ chooseKeyList.push(e.split(":")[0]);
210
+ chooseValueList.push(e.split(":")[1]);
211
+ }
212
+ const parsedChooseList = chooseValueList.map((e) => {
213
+ if (e.match(/\./)) {
214
+ return assetSetter(e, fileType.scene);
215
+ }
216
+ else {
217
+ return e;
218
+ }
219
+ });
220
+ let ret = "";
221
+ for (let i = 0; i < chooseKeyList.length; i++) {
222
+ if (i !== 0) {
223
+ ret = ret + "|";
224
+ }
225
+ ret = ret + `${chooseKeyList[i]}:${parsedChooseList[i]}`;
226
+ }
227
+ return ret;
228
228
  }
229
229
 
230
- /**
231
- * 根据语句类型、语句内容、参数列表,扫描该语句可能携带的资源
232
- * @param command 语句类型
233
- * @param content 语句内容
234
- * @param args 参数列表
235
- * @return {Array<IAsset>} 语句携带的参数列表
236
- */
237
- const assetsScanner = (command, content, args) => {
238
- const returnAssetsList = [];
239
- if (command === commandType.say) {
240
- args.forEach((e) => {
241
- if (e.key === 'vocal') {
242
- returnAssetsList.push({
243
- name: e.value,
244
- url: e.value,
245
- lineNumber: 0,
246
- type: fileType.vocal,
247
- });
248
- }
249
- });
250
- }
251
- if (content === 'none' || content === '') {
252
- return returnAssetsList;
253
- }
254
- // 处理语句携带的资源
255
- if (command === commandType.changeBg) {
256
- returnAssetsList.push({
257
- name: content,
258
- url: content,
259
- lineNumber: 0,
260
- type: fileType.background,
261
- });
262
- }
263
- if (command === commandType.changeFigure) {
264
- returnAssetsList.push({
265
- name: content,
266
- url: content,
267
- lineNumber: 0,
268
- type: fileType.figure,
269
- });
270
- }
271
- if (command === commandType.miniAvatar) {
272
- returnAssetsList.push({
273
- name: content,
274
- url: content,
275
- lineNumber: 0,
276
- type: fileType.figure,
277
- });
278
- }
279
- if (command === commandType.video) {
280
- returnAssetsList.push({
281
- name: content,
282
- url: content,
283
- lineNumber: 0,
284
- type: fileType.video,
285
- });
286
- }
287
- if (command === commandType.bgm) {
288
- returnAssetsList.push({
289
- name: content,
290
- url: content,
291
- lineNumber: 0,
292
- type: fileType.bgm,
293
- });
294
- }
295
- return returnAssetsList;
230
+ /**
231
+ * 根据语句类型、语句内容、参数列表,扫描该语句可能携带的资源
232
+ * @param command 语句类型
233
+ * @param content 语句内容
234
+ * @param args 参数列表
235
+ * @return {Array<IAsset>} 语句携带的参数列表
236
+ */
237
+ const assetsScanner = (command, content, args) => {
238
+ const returnAssetsList = [];
239
+ if (command === commandType.say) {
240
+ args.forEach((e) => {
241
+ if (e.key === 'vocal') {
242
+ returnAssetsList.push({
243
+ name: e.value,
244
+ url: e.value,
245
+ lineNumber: 0,
246
+ type: fileType.vocal,
247
+ });
248
+ }
249
+ });
250
+ }
251
+ if (content === 'none' || content === '') {
252
+ return returnAssetsList;
253
+ }
254
+ // 处理语句携带的资源
255
+ if (command === commandType.changeBg) {
256
+ returnAssetsList.push({
257
+ name: content,
258
+ url: content,
259
+ lineNumber: 0,
260
+ type: fileType.background,
261
+ });
262
+ }
263
+ if (command === commandType.changeFigure) {
264
+ returnAssetsList.push({
265
+ name: content,
266
+ url: content,
267
+ lineNumber: 0,
268
+ type: fileType.figure,
269
+ });
270
+ }
271
+ if (command === commandType.miniAvatar) {
272
+ returnAssetsList.push({
273
+ name: content,
274
+ url: content,
275
+ lineNumber: 0,
276
+ type: fileType.figure,
277
+ });
278
+ }
279
+ if (command === commandType.video) {
280
+ returnAssetsList.push({
281
+ name: content,
282
+ url: content,
283
+ lineNumber: 0,
284
+ type: fileType.video,
285
+ });
286
+ }
287
+ if (command === commandType.bgm) {
288
+ returnAssetsList.push({
289
+ name: content,
290
+ url: content,
291
+ lineNumber: 0,
292
+ type: fileType.bgm,
293
+ });
294
+ }
295
+ return returnAssetsList;
296
296
  };
297
297
 
298
- /**
299
- * 扫描子场景
300
- * @param content 语句内容
301
- * @return {Array<string>} 子场景列表
302
- */
303
- const subSceneScanner = (command, content) => {
304
- const subSceneList = [];
305
- if (command === commandType.changeScene || command === commandType.callScene) {
306
- subSceneList.push(content);
307
- }
308
- if (command === commandType.choose) {
309
- const chooseList = content.split('|');
310
- const chooseValue = chooseList.map((e) => e.split(':')[1]);
311
- chooseValue.forEach((e) => {
312
- if (e.match(/\./)) {
313
- subSceneList.push(e);
314
- }
315
- });
316
- }
317
- return subSceneList;
298
+ /**
299
+ * 扫描子场景
300
+ * @param content 语句内容
301
+ * @return {Array<string>} 子场景列表
302
+ */
303
+ const subSceneScanner = (command, content) => {
304
+ const subSceneList = [];
305
+ if (command === commandType.changeScene || command === commandType.callScene) {
306
+ subSceneList.push(content);
307
+ }
308
+ if (command === commandType.choose) {
309
+ const chooseList = content.split('|');
310
+ const chooseValue = chooseList.map((e) => e.split(':')[1]);
311
+ chooseValue.forEach((e) => {
312
+ if (e.match(/\./)) {
313
+ subSceneList.push(e);
314
+ }
315
+ });
316
+ }
317
+ return subSceneList;
318
318
  };
319
319
 
320
- /**
321
- * 语句解析器
322
- * @param sentenceRaw 原始语句
323
- * @param assetSetter
324
- * @param ADD_NEXT_ARG_LIST
325
- * @param SCRIPT_CONFIG
326
- */
327
- const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
328
- let command; // 默认为对话
329
- let content; // 语句内容
330
- let subScene; // 语句携带的子场景(可能没有)
331
- const args = []; // 语句参数列表
332
- let sentenceAssets; // 语句携带的资源列表
333
- let parsedCommand; // 解析后的命令
334
- let commandRaw;
335
- // 正式开始解析
336
- // 去分号,前面已做,这里不再需要
337
- let newSentenceRaw = sentenceRaw;
338
- // 截取命令
339
- const getCommandResult = /:/.exec(newSentenceRaw);
340
- /**
341
- * 拆分命令和语句,同时处理连续对话。
342
- */
343
- // 没有command,说明这是一条连续对话或单条语句
344
- if (getCommandResult === null) {
345
- commandRaw = newSentenceRaw;
346
- parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
347
- command = parsedCommand.type;
348
- for (const e of parsedCommand.additionalArgs) {
349
- // 由于是连续对话,所以我们去除 speaker 参数。
350
- if (command === commandType.say && e.key === "speaker") {
351
- continue;
352
- }
353
- args.push(e);
354
- }
355
- }
356
- else {
357
- commandRaw = newSentenceRaw.substring(0, getCommandResult.index);
358
- // 划分命令区域和content区域
359
- newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
360
- parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
361
- command = parsedCommand.type;
362
- for (const e of parsedCommand.additionalArgs) {
363
- args.push(e);
364
- }
365
- }
366
- // 截取参数区域
367
- const getArgsResult = / -/.exec(newSentenceRaw);
368
- // 获取到参数
369
- if (getArgsResult) {
370
- const argsRaw = newSentenceRaw.substring(getArgsResult.index, sentenceRaw.length);
371
- newSentenceRaw = newSentenceRaw.substring(0, getArgsResult.index);
372
- for (const e of argsParser(argsRaw, assetSetter)) {
373
- args.push(e);
374
- }
375
- }
376
- content = contentParser(newSentenceRaw, command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
377
- sentenceAssets = assetsScanner(command, content, args); // 扫描语句携带资源
378
- subScene = subSceneScanner(command, content); // 扫描语句携带子场景
379
- return {
380
- command: command,
381
- commandRaw: commandRaw,
382
- content: content,
383
- args: args,
384
- sentenceAssets: sentenceAssets,
385
- subScene: subScene // 语句携带的子场景
386
- };
320
+ /**
321
+ * 语句解析器
322
+ * @param sentenceRaw 原始语句
323
+ * @param assetSetter
324
+ * @param ADD_NEXT_ARG_LIST
325
+ * @param SCRIPT_CONFIG
326
+ */
327
+ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
328
+ let command; // 默认为对话
329
+ let content; // 语句内容
330
+ let subScene; // 语句携带的子场景(可能没有)
331
+ const args = []; // 语句参数列表
332
+ let sentenceAssets; // 语句携带的资源列表
333
+ let parsedCommand; // 解析后的命令
334
+ let commandRaw;
335
+ // 正式开始解析
336
+ // 去分号,前面已做,这里不再需要
337
+ let newSentenceRaw = sentenceRaw;
338
+ // 截取命令
339
+ const getCommandResult = /:/.exec(newSentenceRaw);
340
+ /**
341
+ * 拆分命令和语句,同时处理连续对话。
342
+ */
343
+ // 没有command,说明这是一条连续对话或单条语句
344
+ if (getCommandResult === null) {
345
+ commandRaw = newSentenceRaw;
346
+ parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
347
+ command = parsedCommand.type;
348
+ for (const e of parsedCommand.additionalArgs) {
349
+ // 由于是连续对话,所以我们去除 speaker 参数。
350
+ if (command === commandType.say && e.key === "speaker") {
351
+ continue;
352
+ }
353
+ args.push(e);
354
+ }
355
+ }
356
+ else {
357
+ commandRaw = newSentenceRaw.substring(0, getCommandResult.index);
358
+ // 划分命令区域和content区域
359
+ newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
360
+ parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
361
+ command = parsedCommand.type;
362
+ for (const e of parsedCommand.additionalArgs) {
363
+ args.push(e);
364
+ }
365
+ }
366
+ // 截取参数区域
367
+ const getArgsResult = / -/.exec(newSentenceRaw);
368
+ // 获取到参数
369
+ if (getArgsResult) {
370
+ const argsRaw = newSentenceRaw.substring(getArgsResult.index, sentenceRaw.length);
371
+ newSentenceRaw = newSentenceRaw.substring(0, getArgsResult.index);
372
+ for (const e of argsParser(argsRaw, assetSetter)) {
373
+ args.push(e);
374
+ }
375
+ }
376
+ content = contentParser(newSentenceRaw, command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
377
+ sentenceAssets = assetsScanner(command, content, args); // 扫描语句携带资源
378
+ subScene = subSceneScanner(command, content); // 扫描语句携带子场景
379
+ return {
380
+ command: command,
381
+ commandRaw: commandRaw,
382
+ content: content,
383
+ args: args,
384
+ sentenceAssets: sentenceAssets,
385
+ subScene: subScene // 语句携带的子场景
386
+ };
387
387
  };
388
388
 
389
- /**
390
- * 场景解析器
391
- * @param rawScene 原始场景
392
- * @param sceneName 场景名称
393
- * @param sceneUrl 场景url
394
- * @param assetsPrefetcher
395
- * @param assetSetter
396
- * @param ADD_NEXT_ARG_LIST
397
- * @param SCRIPT_CONFIG
398
- * @return {IScene} 解析后的场景
399
- */
400
- const sceneParser = (rawScene, sceneName, sceneUrl, assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
401
- const rawSentenceList = rawScene.split("\n"); // 原始句子列表
402
- // 去除冒号后的内容
403
- // 去除分号后的内容
404
- const rawSentenceListWithoutEmpty = rawSentenceList
405
- .map((sentence) => sentence.split(";")[0])
406
- .filter((sentence) => sentence.trim() !== "");
407
- let assetsList = []; // 场景资源列表
408
- let subSceneList = []; // 子场景列表
409
- const sentenceList = rawSentenceListWithoutEmpty.map((sentence) => {
410
- const returnSentence = scriptParser(sentence, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
411
- // 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
412
- assetsList = [...assetsList, ...returnSentence.sentenceAssets];
413
- subSceneList = [...subSceneList, ...returnSentence.subScene];
414
- return returnSentence;
415
- });
416
- // 开始资源的预加载
417
- assetsList = __.uniqWith(assetsList); // 去重
418
- assetsPrefetcher(assetsList);
419
- return {
420
- sceneName: sceneName,
421
- sceneUrl: sceneUrl,
422
- sentenceList: sentenceList,
423
- assetsList: assetsList,
424
- subSceneList: subSceneList // 子场景列表
425
- };
389
+ /**
390
+ * 场景解析器
391
+ * @param rawScene 原始场景
392
+ * @param sceneName 场景名称
393
+ * @param sceneUrl 场景url
394
+ * @param assetsPrefetcher
395
+ * @param assetSetter
396
+ * @param ADD_NEXT_ARG_LIST
397
+ * @param SCRIPT_CONFIG
398
+ * @return {IScene} 解析后的场景
399
+ */
400
+ const sceneParser = (rawScene, sceneName, sceneUrl, assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
401
+ const rawSentenceList = rawScene.split("\n"); // 原始句子列表
402
+ // 去除冒号后的内容
403
+ // 去除分号后的内容
404
+ const rawSentenceListWithoutEmpty = rawSentenceList
405
+ .map((sentence) => sentence.split(";")[0])
406
+ .filter((sentence) => sentence.trim() !== "");
407
+ let assetsList = []; // 场景资源列表
408
+ let subSceneList = []; // 子场景列表
409
+ const sentenceList = rawSentenceListWithoutEmpty.map((sentence) => {
410
+ const returnSentence = scriptParser(sentence, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
411
+ // 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
412
+ assetsList = [...assetsList, ...returnSentence.sentenceAssets];
413
+ subSceneList = [...subSceneList, ...returnSentence.subScene];
414
+ return returnSentence;
415
+ });
416
+ // 开始资源的预加载
417
+ assetsList = __.uniqWith(assetsList); // 去重
418
+ assetsPrefetcher(assetsList);
419
+ return {
420
+ sceneName: sceneName,
421
+ sceneUrl: sceneUrl,
422
+ sentenceList: sentenceList,
423
+ assetsList: assetsList,
424
+ subSceneList: subSceneList // 子场景列表
425
+ };
426
426
  };
427
427
 
428
- class SceneParser {
429
- assetsPrefetcher;
430
- assetSetter;
431
- ADD_NEXT_ARG_LIST;
432
- SCRIPT_CONFIG;
433
- constructor(assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
434
- this.assetsPrefetcher = assetsPrefetcher;
435
- this.assetSetter = assetSetter;
436
- this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
437
- this.SCRIPT_CONFIG = SCRIPT_CONFIG;
438
- }
439
- parse(rawScene, sceneName, sceneUrl) {
440
- return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
441
- }
428
+ class SceneParser {
429
+ assetsPrefetcher;
430
+ assetSetter;
431
+ ADD_NEXT_ARG_LIST;
432
+ SCRIPT_CONFIG;
433
+ constructor(assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
434
+ this.assetsPrefetcher = assetsPrefetcher;
435
+ this.assetSetter = assetSetter;
436
+ this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
437
+ this.SCRIPT_CONFIG = SCRIPT_CONFIG;
438
+ }
439
+ parse(rawScene, sceneName, sceneUrl) {
440
+ return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
441
+ }
442
442
  }
443
443
 
444
444
  export { SceneParser as default };