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