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