webgal-parser 4.4.9 → 4.4.14-2

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 (48) hide show
  1. package/.prettierrc +19 -0
  2. package/build/cjs/config/scriptConfig.d.ts +6 -1
  3. package/build/cjs/index.cjs +232 -182
  4. package/build/cjs/index.d.ts +15 -6
  5. package/build/cjs/interface/sceneInterface.d.ts +4 -3
  6. package/build/cjs/sceneParser.d.ts +5 -4
  7. package/build/cjs/scriptParser/argsParser.d.ts +2 -2
  8. package/build/cjs/scriptParser/commandParser.d.ts +4 -3
  9. package/build/cjs/scriptParser/contentParser.d.ts +1 -1
  10. package/build/cjs/scriptParser/scriptParser.d.ts +4 -3
  11. package/build/cjs/scriptParser/subSceneScanner.d.ts +1 -1
  12. package/build/cjs/styleParser/index.d.ts +5 -0
  13. package/build/es/config/scriptConfig.d.ts +6 -1
  14. package/build/es/index.d.ts +15 -6
  15. package/build/es/index.js +232 -182
  16. package/build/es/interface/sceneInterface.d.ts +4 -3
  17. package/build/es/sceneParser.d.ts +5 -4
  18. package/build/es/scriptParser/argsParser.d.ts +2 -2
  19. package/build/es/scriptParser/commandParser.d.ts +4 -3
  20. package/build/es/scriptParser/contentParser.d.ts +1 -1
  21. package/build/es/scriptParser/scriptParser.d.ts +4 -3
  22. package/build/es/scriptParser/subSceneScanner.d.ts +1 -1
  23. package/build/es/styleParser/index.d.ts +5 -0
  24. package/build/types/config/scriptConfig.d.ts +6 -1
  25. package/build/types/index.d.ts +15 -6
  26. package/build/types/interface/sceneInterface.d.ts +4 -3
  27. package/build/types/sceneParser.d.ts +5 -4
  28. package/build/types/scriptParser/argsParser.d.ts +2 -2
  29. package/build/types/scriptParser/commandParser.d.ts +4 -3
  30. package/build/types/scriptParser/contentParser.d.ts +1 -1
  31. package/build/types/scriptParser/scriptParser.d.ts +4 -3
  32. package/build/types/scriptParser/subSceneScanner.d.ts +1 -1
  33. package/build/types/styleParser/index.d.ts +5 -0
  34. package/build/umd/index.global.js +232 -182
  35. package/package.json +2 -2
  36. package/src/config/scriptConfig.ts +9 -5
  37. package/src/configParser/configParser.ts +37 -25
  38. package/src/index.ts +66 -30
  39. package/src/interface/sceneInterface.ts +4 -3
  40. package/src/parser4/index.ts +1 -1
  41. package/src/sceneParser.ts +36 -17
  42. package/src/scriptParser/argsParser.ts +17 -14
  43. package/src/scriptParser/assetsScanner.ts +5 -1
  44. package/src/scriptParser/commandParser.ts +31 -23
  45. package/src/scriptParser/contentParser.ts +14 -10
  46. package/src/scriptParser/scriptParser.ts +38 -20
  47. package/src/scriptParser/subSceneScanner.ts +11 -5
  48. package/src/styleParser/index.ts +39 -0
package/build/es/index.js CHANGED
@@ -32,63 +32,54 @@ var commandType;
32
32
  commandType[commandType["setTransform"] = 29] = "setTransform";
33
33
  commandType[commandType["setTransition"] = 30] = "setTransition";
34
34
  commandType[commandType["getUserInput"] = 31] = "getUserInput";
35
+ commandType[commandType["applyStyle"] = 32] = "applyStyle";
35
36
  })(commandType || (commandType = {}));
36
37
 
37
- /**
38
- * 处理命令
39
- * @param commandRaw
40
- * @param ADD_NEXT_ARG_LIST
41
- * @param SCRIPT_CONFIG
42
- * @return {parsedCommand} 处理后的命令
43
- */
44
- const commandParser = (commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
45
- let returnCommand = {
46
- type: commandType.say,
47
- additionalArgs: []
48
- };
49
- // 开始处理命令内容
50
- const type = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
51
- returnCommand.type = type;
52
- // 如果是对话,加上额外的参数
53
- if (type === commandType.say && commandRaw !== 'say') {
54
- returnCommand.additionalArgs.push({
55
- key: "speaker",
56
- value: commandRaw
57
- });
58
- }
59
- returnCommand = addNextArg(returnCommand, type, ADD_NEXT_ARG_LIST);
60
- return returnCommand;
61
- };
62
- /**
63
- * 根据command原始值判断是什么命令
64
- * @param command command原始值
65
- * @param ADD_NEXT_ARG_LIST
66
- * @param SCRIPT_CONFIG
67
- * @return {commandType} 得到的command类型
68
- */
69
- function getCommandType(command, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
70
- // if (command.match(/if/)) {
71
- // return commandType.if;
72
- // }
73
- const commandMap = new Map();
74
- SCRIPT_CONFIG.forEach((e) => {
75
- commandMap.set(e.scriptString, e.scriptType);
76
- });
77
- if (commandMap.has(command)) {
78
- return commandMap.get(command);
79
- }
80
- else
81
- return commandType.say;
82
- }
83
- function addNextArg(commandToParse, thisCommandType, ADD_NEXT_ARG_LIST) {
84
- if (ADD_NEXT_ARG_LIST.includes(thisCommandType)) {
85
- commandToParse.additionalArgs.push({
86
- key: "next",
87
- value: true
88
- });
89
- }
90
- return commandToParse;
91
- }
38
+ const SCRIPT_CONFIG = [
39
+ { scriptString: 'intro', scriptType: commandType.intro },
40
+ { scriptString: 'changeBg', scriptType: commandType.changeBg },
41
+ { scriptString: 'changeFigure', scriptType: commandType.changeFigure },
42
+ { scriptString: 'miniAvatar', scriptType: commandType.miniAvatar },
43
+ { scriptString: 'changeScene', scriptType: commandType.changeScene },
44
+ { scriptString: 'choose', scriptType: commandType.choose },
45
+ { scriptString: 'end', scriptType: commandType.end },
46
+ { scriptString: 'bgm', scriptType: commandType.bgm },
47
+ { scriptString: 'playVideo', scriptType: commandType.video },
48
+ {
49
+ scriptString: 'setComplexAnimation',
50
+ scriptType: commandType.setComplexAnimation,
51
+ },
52
+ { scriptString: 'setFilter', scriptType: commandType.setFilter },
53
+ { scriptString: 'pixiInit', scriptType: commandType.pixiInit },
54
+ { scriptString: 'pixiPerform', scriptType: commandType.pixi },
55
+ { scriptString: 'label', scriptType: commandType.label },
56
+ { scriptString: 'jumpLabel', scriptType: commandType.jumpLabel },
57
+ { scriptString: 'setVar', scriptType: commandType.setVar },
58
+ { scriptString: 'callScene', scriptType: commandType.callScene },
59
+ { scriptString: 'showVars', scriptType: commandType.showVars },
60
+ { scriptString: 'unlockCg', scriptType: commandType.unlockCg },
61
+ { scriptString: 'unlockBgm', scriptType: commandType.unlockBgm },
62
+ { scriptString: 'say', scriptType: commandType.say },
63
+ { scriptString: 'filmMode', scriptType: commandType.filmMode },
64
+ { scriptString: 'callScene', scriptType: commandType.callScene },
65
+ { scriptString: 'setTextbox', scriptType: commandType.setTextbox },
66
+ { scriptString: 'setAnimation', scriptType: commandType.setAnimation },
67
+ { scriptString: 'playEffect', scriptType: commandType.playEffect },
68
+ { scriptString: 'applyStyle', scriptType: commandType.applyStyle },
69
+ ];
70
+ const ADD_NEXT_ARG_LIST = [
71
+ commandType.bgm,
72
+ commandType.pixi,
73
+ commandType.pixiInit,
74
+ commandType.label,
75
+ commandType.if,
76
+ commandType.miniAvatar,
77
+ commandType.setVar,
78
+ commandType.unlockBgm,
79
+ commandType.unlockCg,
80
+ commandType.filmMode,
81
+ commandType.playEffect,
82
+ ];
92
83
 
93
84
  /**
94
85
  * 内置资源类型的枚举
@@ -114,12 +105,12 @@ function argsParser(argsRaw, assetSetter) {
114
105
  const returnArrayList = [];
115
106
  // 处理参数
116
107
  // 不要去空格
117
- let newArgsRaw = argsRaw.replace(/ /g, " ");
108
+ let newArgsRaw = argsRaw.replace(/ /g, ' ');
118
109
  // 分割参数列表
119
- let rawArgsList = newArgsRaw.split(" -");
110
+ let rawArgsList = newArgsRaw.split(' -');
120
111
  // 去除空字符串
121
112
  rawArgsList = rawArgsList.filter((e) => {
122
- return e !== "";
113
+ return e !== '';
123
114
  });
124
115
  rawArgsList.forEach((e) => {
125
116
  const equalSignIndex = e.indexOf('=');
@@ -132,8 +123,8 @@ function argsParser(argsRaw, assetSetter) {
132
123
  // 判断是不是语音参数
133
124
  if (argName.toLowerCase().match(/.ogg|.mp3|.wav/)) {
134
125
  returnArrayList.push({
135
- key: "vocal",
136
- value: assetSetter(e, fileType.vocal)
126
+ key: 'vocal',
127
+ value: assetSetter(e, fileType.vocal),
137
128
  });
138
129
  }
139
130
  else {
@@ -141,15 +132,15 @@ function argsParser(argsRaw, assetSetter) {
141
132
  if (argValue === undefined) {
142
133
  returnArrayList.push({
143
134
  key: argName,
144
- value: true
135
+ value: true,
145
136
  });
146
137
  }
147
138
  else {
148
139
  // 是字符串描述的布尔值
149
- if (argValue === "true" || argValue === "false") {
140
+ if (argValue === 'true' || argValue === 'false') {
150
141
  returnArrayList.push({
151
142
  key: argName,
152
- value: argValue === "true"
143
+ value: argValue === 'true',
153
144
  });
154
145
  }
155
146
  else {
@@ -157,14 +148,14 @@ function argsParser(argsRaw, assetSetter) {
157
148
  if (!isNaN(Number(argValue))) {
158
149
  returnArrayList.push({
159
150
  key: argName,
160
- value: Number(argValue)
151
+ value: Number(argValue),
161
152
  });
162
153
  }
163
154
  else {
164
155
  // 是普通参数
165
156
  returnArrayList.push({
166
157
  key: argName,
167
- value: argValue
158
+ value: argValue,
168
159
  });
169
160
  }
170
161
  }
@@ -174,6 +165,102 @@ function argsParser(argsRaw, assetSetter) {
174
165
  return returnArrayList;
175
166
  }
176
167
 
168
+ function configLineParser(inputLine) {
169
+ const options = [];
170
+ let command;
171
+ let newSentenceRaw = inputLine.split(';')[0];
172
+ if (newSentenceRaw === '') {
173
+ // 注释提前返回
174
+ return {
175
+ command: '',
176
+ args: [],
177
+ options: [],
178
+ };
179
+ }
180
+ // 截取命令
181
+ const getCommandResult = /:/.exec(newSentenceRaw);
182
+ // 没有command
183
+ if (getCommandResult === null) {
184
+ command = '';
185
+ }
186
+ else {
187
+ command = newSentenceRaw.substring(0, getCommandResult.index);
188
+ // 划分命令区域和content区域
189
+ newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
190
+ }
191
+ // 截取 Options 区域
192
+ const getOptionsResult = / -/.exec(newSentenceRaw);
193
+ // 获取到参数
194
+ if (getOptionsResult) {
195
+ const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
196
+ newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
197
+ for (const e of argsParser(optionsRaw, (name, _) => {
198
+ return name;
199
+ })) {
200
+ options.push(e);
201
+ }
202
+ }
203
+ return {
204
+ command,
205
+ args: newSentenceRaw
206
+ .split('|')
207
+ .map((e) => e.trim())
208
+ .filter((e) => e !== ''),
209
+ options,
210
+ };
211
+ }
212
+ function configParser(configText) {
213
+ const configLines = configText.replaceAll(`\r`, '').split('\n');
214
+ return configLines
215
+ .map((e) => configLineParser(e))
216
+ .filter((e) => e.command !== '');
217
+ }
218
+
219
+ /**
220
+ * 处理命令
221
+ * @param commandRaw
222
+ * @param ADD_NEXT_ARG_LIST
223
+ * @param SCRIPT_CONFIG_MAP
224
+ * @return {parsedCommand} 处理后的命令
225
+ */
226
+ const commandParser = (commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP) => {
227
+ let returnCommand = {
228
+ type: commandType.say,
229
+ additionalArgs: [],
230
+ };
231
+ // 开始处理命令内容
232
+ const type = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP);
233
+ returnCommand.type = type;
234
+ // 如果是对话,加上额外的参数
235
+ if (type === commandType.say && commandRaw !== 'say') {
236
+ returnCommand.additionalArgs.push({
237
+ key: 'speaker',
238
+ value: commandRaw,
239
+ });
240
+ }
241
+ returnCommand = addNextArg(returnCommand, type, ADD_NEXT_ARG_LIST);
242
+ return returnCommand;
243
+ };
244
+ /**
245
+ * 根据command原始值判断是什么命令
246
+ * @param command command原始值
247
+ * @param ADD_NEXT_ARG_LIST
248
+ * @param SCRIPT_CONFIG_MAP
249
+ * @return {commandType} 得到的command类型
250
+ */
251
+ function getCommandType(command, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP) {
252
+ return SCRIPT_CONFIG_MAP.get(command)?.scriptType ?? commandType.say;
253
+ }
254
+ function addNextArg(commandToParse, thisCommandType, ADD_NEXT_ARG_LIST) {
255
+ if (ADD_NEXT_ARG_LIST.includes(thisCommandType)) {
256
+ commandToParse.additionalArgs.push({
257
+ key: 'next',
258
+ value: true,
259
+ });
260
+ }
261
+ return commandToParse;
262
+ }
263
+
177
264
  /**
178
265
  * 解析语句内容的函数,主要作用是把文件名改为绝对地址或相对地址(根据使用情况而定)
179
266
  * @param contentRaw 原始语句内容
@@ -182,8 +269,8 @@ function argsParser(argsRaw, assetSetter) {
182
269
  * @return {string} 解析后的语句内容
183
270
  */
184
271
  const contentParser = (contentRaw, type, assetSetter) => {
185
- if (contentRaw === "none" || contentRaw === "") {
186
- return "";
272
+ if (contentRaw === 'none' || contentRaw === '') {
273
+ return '';
187
274
  }
188
275
  switch (type) {
189
276
  case commandType.playEffect:
@@ -213,12 +300,12 @@ const contentParser = (contentRaw, type, assetSetter) => {
213
300
  }
214
301
  };
215
302
  function getChooseContent(contentRaw, assetSetter) {
216
- const chooseList = contentRaw.split("|");
303
+ const chooseList = contentRaw.split('|');
217
304
  const chooseKeyList = [];
218
305
  const chooseValueList = [];
219
306
  for (const e of chooseList) {
220
- chooseKeyList.push(e.split(":")[0] ?? "");
221
- chooseValueList.push(e.split(":")[1] ?? "");
307
+ chooseKeyList.push(e.split(':')[0] ?? '');
308
+ chooseValueList.push(e.split(':')[1] ?? '');
222
309
  }
223
310
  const parsedChooseList = chooseValueList.map((e) => {
224
311
  if (e.match(/\./)) {
@@ -228,10 +315,10 @@ function getChooseContent(contentRaw, assetSetter) {
228
315
  return e;
229
316
  }
230
317
  });
231
- let ret = "";
318
+ let ret = '';
232
319
  for (let i = 0; i < chooseKeyList.length; i++) {
233
320
  if (i !== 0) {
234
- ret = ret + "|";
321
+ ret = ret + '|';
235
322
  }
236
323
  ret = ret + `${chooseKeyList[i]}:${parsedChooseList[i]}`;
237
324
  }
@@ -313,12 +400,13 @@ const assetsScanner = (command, content, args) => {
313
400
  */
314
401
  const subSceneScanner = (command, content) => {
315
402
  const subSceneList = [];
316
- if (command === commandType.changeScene || command === commandType.callScene) {
403
+ if (command === commandType.changeScene ||
404
+ command === commandType.callScene) {
317
405
  subSceneList.push(content);
318
406
  }
319
407
  if (command === commandType.choose) {
320
- const chooseList = content.split("|");
321
- const chooseValue = chooseList.map((e) => e.split(":")[1] ?? "");
408
+ const chooseList = content.split('|');
409
+ const chooseValue = chooseList.map((e) => e.split(':')[1] ?? '');
322
410
  chooseValue.forEach((e) => {
323
411
  if (e.match(/\./)) {
324
412
  subSceneList.push(e);
@@ -333,9 +421,9 @@ const subSceneScanner = (command, content) => {
333
421
  * @param sentenceRaw 原始语句
334
422
  * @param assetSetter
335
423
  * @param ADD_NEXT_ARG_LIST
336
- * @param SCRIPT_CONFIG
424
+ * @param SCRIPT_CONFIG_MAP
337
425
  */
338
- const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
426
+ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP) => {
339
427
  let command; // 默认为对话
340
428
  let content; // 语句内容
341
429
  let subScene; // 语句携带的子场景(可能没有)
@@ -345,16 +433,16 @@ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG
345
433
  let commandRaw;
346
434
  // 正式开始解析
347
435
  // 去分号,前面已做,这里不再需要
348
- let newSentenceRaw = sentenceRaw.split(";")[0];
349
- if (newSentenceRaw === "") {
436
+ let newSentenceRaw = sentenceRaw.split(';')[0];
437
+ if (newSentenceRaw === '') {
350
438
  // 注释提前返回
351
439
  return {
352
440
  command: commandType.comment,
353
- commandRaw: "comment",
354
- content: sentenceRaw.split(";")[1] ?? "",
355
- args: [{ key: "next", value: true }],
441
+ commandRaw: 'comment',
442
+ content: sentenceRaw.split(';')[1] ?? '',
443
+ args: [{ key: 'next', value: true }],
356
444
  sentenceAssets: [],
357
- subScene: [] // 语句携带的子场景
445
+ subScene: [], // 语句携带的子场景
358
446
  };
359
447
  }
360
448
  // 截取命令
@@ -365,11 +453,11 @@ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG
365
453
  // 没有command,说明这是一条连续对话或单条语句
366
454
  if (getCommandResult === null) {
367
455
  commandRaw = newSentenceRaw;
368
- parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
456
+ parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP);
369
457
  command = parsedCommand.type;
370
458
  for (const e of parsedCommand.additionalArgs) {
371
459
  // 由于是连续对话,所以我们去除 speaker 参数。
372
- if (command === commandType.say && e.key === "speaker") {
460
+ if (command === commandType.say && e.key === 'speaker') {
373
461
  continue;
374
462
  }
375
463
  args.push(e);
@@ -379,7 +467,7 @@ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG
379
467
  commandRaw = newSentenceRaw.substring(0, getCommandResult.index);
380
468
  // 划分命令区域和content区域
381
469
  newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
382
- parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
470
+ parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP);
383
471
  command = parsedCommand.type;
384
472
  for (const e of parsedCommand.additionalArgs) {
385
473
  args.push(e);
@@ -404,7 +492,7 @@ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG
404
492
  content: content,
405
493
  args: args,
406
494
  sentenceAssets: sentenceAssets,
407
- subScene: subScene // 语句携带的子场景
495
+ subScene: subScene, // 语句携带的子场景
408
496
  };
409
497
  };
410
498
 
@@ -1664,11 +1752,11 @@ var uniqWith_1 = uniqWith;
1664
1752
  * @param assetsPrefetcher
1665
1753
  * @param assetSetter
1666
1754
  * @param ADD_NEXT_ARG_LIST
1667
- * @param SCRIPT_CONFIG
1755
+ * @param SCRIPT_CONFIG_MAP
1668
1756
  * @return {IScene} 解析后的场景
1669
1757
  */
1670
- const sceneParser = (rawScene, sceneName, sceneUrl, assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
1671
- const rawSentenceList = rawScene.split("\n"); // 原始句子列表
1758
+ const sceneParser = (rawScene, sceneName, sceneUrl, assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP) => {
1759
+ const rawSentenceList = rawScene.split('\n'); // 原始句子列表
1672
1760
  // 去分号留到后面去做了,现在注释要单独处理
1673
1761
  const rawSentenceListWithoutEmpty = rawSentenceList;
1674
1762
  // .map((sentence) => sentence.split(";")[0])
@@ -1676,7 +1764,7 @@ const sceneParser = (rawScene, sceneName, sceneUrl, assetsPrefetcher, assetSette
1676
1764
  let assetsList = []; // 场景资源列表
1677
1765
  let subSceneList = []; // 子场景列表
1678
1766
  const sentenceList = rawSentenceListWithoutEmpty.map((sentence) => {
1679
- const returnSentence = scriptParser(sentence, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
1767
+ const returnSentence = scriptParser(sentence, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP);
1680
1768
  // 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
1681
1769
  assetsList = [...assetsList, ...returnSentence.sentenceAssets];
1682
1770
  subSceneList = [...subSceneList, ...returnSentence.subScene];
@@ -1690,119 +1778,81 @@ const sceneParser = (rawScene, sceneName, sceneUrl, assetsPrefetcher, assetSette
1690
1778
  sceneUrl: sceneUrl,
1691
1779
  sentenceList: sentenceList,
1692
1780
  assetsList: assetsList,
1693
- subSceneList: subSceneList // 子场景列表
1781
+ subSceneList: subSceneList, // 子场景列表
1694
1782
  };
1695
1783
  };
1696
1784
 
1697
- const SCRIPT_CONFIG = [
1698
- { scriptString: 'intro', scriptType: commandType.intro },
1699
- { scriptString: 'changeBg', scriptType: commandType.changeBg },
1700
- { scriptString: 'changeFigure', scriptType: commandType.changeFigure },
1701
- { scriptString: 'miniAvatar', scriptType: commandType.miniAvatar },
1702
- { scriptString: 'changeScene', scriptType: commandType.changeScene },
1703
- { scriptString: 'choose', scriptType: commandType.choose },
1704
- { scriptString: 'end', scriptType: commandType.end },
1705
- { scriptString: 'bgm', scriptType: commandType.bgm },
1706
- { scriptString: 'playVideo', scriptType: commandType.video },
1707
- {
1708
- scriptString: 'setComplexAnimation',
1709
- scriptType: commandType.setComplexAnimation,
1710
- },
1711
- { scriptString: 'setFilter', scriptType: commandType.setFilter },
1712
- { scriptString: 'pixiInit', scriptType: commandType.pixiInit },
1713
- { scriptString: 'pixiPerform', scriptType: commandType.pixi },
1714
- { scriptString: 'label', scriptType: commandType.label },
1715
- { scriptString: 'jumpLabel', scriptType: commandType.jumpLabel },
1716
- { scriptString: 'setVar', scriptType: commandType.setVar },
1717
- { scriptString: 'callScene', scriptType: commandType.callScene },
1718
- { scriptString: 'showVars', scriptType: commandType.showVars },
1719
- { scriptString: 'unlockCg', scriptType: commandType.unlockCg },
1720
- { scriptString: 'unlockBgm', scriptType: commandType.unlockBgm },
1721
- { scriptString: 'say', scriptType: commandType.say },
1722
- { scriptString: 'filmMode', scriptType: commandType.filmMode },
1723
- { scriptString: 'callScene', scriptType: commandType.callScene },
1724
- { scriptString: 'setTextbox', scriptType: commandType.setTextbox },
1725
- { scriptString: 'setAnimation', scriptType: commandType.setAnimation },
1726
- { scriptString: 'playEffect', scriptType: commandType.playEffect },
1727
- ];
1728
- const ADD_NEXT_ARG_LIST = [
1729
- commandType.bgm,
1730
- commandType.pixi,
1731
- commandType.pixiInit,
1732
- commandType.label,
1733
- commandType.if,
1734
- commandType.miniAvatar,
1735
- commandType.setVar,
1736
- commandType.unlockBgm,
1737
- commandType.unlockCg,
1738
- commandType.filmMode,
1739
- commandType.playEffect,
1740
- ];
1741
-
1742
- function configLineParser(inputLine) {
1743
- const options = [];
1744
- let command;
1745
- let newSentenceRaw = inputLine.split(";")[0];
1746
- if (newSentenceRaw === "") {
1747
- // 注释提前返回
1748
- return {
1749
- command: '',
1750
- args: [],
1751
- options: []
1752
- };
1753
- }
1754
- // 截取命令
1755
- const getCommandResult = /:/.exec(newSentenceRaw);
1756
- // 没有command
1757
- if (getCommandResult === null) {
1758
- command = '';
1759
- }
1760
- else {
1761
- command = newSentenceRaw.substring(0, getCommandResult.index);
1762
- // 划分命令区域和content区域
1763
- newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
1764
- }
1765
- // 截取 Options 区域
1766
- const getOptionsResult = / -/.exec(newSentenceRaw);
1767
- // 获取到参数
1768
- if (getOptionsResult) {
1769
- const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
1770
- newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
1771
- for (const e of argsParser(optionsRaw, (name, _) => { return name; })) {
1772
- options.push(e);
1773
- }
1774
- }
1785
+ function scss2cssinjsParser(scssString) {
1786
+ const [classNameStyles, others] = parseCSS(scssString);
1775
1787
  return {
1776
- command,
1777
- args: newSentenceRaw.split('|').map(e => e.trim()).filter(e => e !== ''),
1778
- options
1788
+ classNameStyles,
1789
+ others,
1779
1790
  };
1780
1791
  }
1781
- function configParser(configText) {
1782
- const configLines = configText.replaceAll(`\r`, '').split('\n');
1783
- return configLines.map(e => configLineParser(e)).filter(e => e.command !== '');
1792
+ /**
1793
+ * GPT 4 写的,临时用,以后要重构!!!
1794
+ * TODO:用人类智能重构,要是用着一直没问题,也不是不可以 trust AI
1795
+ * @param css
1796
+ */
1797
+ function parseCSS(css) {
1798
+ const result = {};
1799
+ let specialRules = '';
1800
+ let matches;
1801
+ // 匹配类选择器和其内容,包括一层嵌套
1802
+ const classRegex = /\.([^{\s]+)\s*{([^}]*?(?:\{[^}]*?\}[^}]*?)?)}/g;
1803
+ // 更新特殊规则正则表达式以正确处理一层嵌套,并确保大括号成对出现
1804
+ const specialRegex = /(@[^{]+{\s*(?:[^{}]*{[^}]*}[^{}]*)+\s*})/g;
1805
+ // 提取类和样式
1806
+ while ((matches = classRegex.exec(css)) !== null) {
1807
+ result[matches[1]] = matches[2].trim().replace(/\s*;\s*/g, ';\n');
1808
+ }
1809
+ // 提取特殊规则,并确保包含所有的大括号
1810
+ while ((matches = specialRegex.exec(css)) !== null) {
1811
+ specialRules += matches[1].trim() + '\n';
1812
+ }
1813
+ return [result, specialRules.trim()];
1784
1814
  }
1785
1815
 
1786
1816
  class SceneParser {
1787
1817
  assetsPrefetcher;
1788
1818
  assetSetter;
1789
1819
  ADD_NEXT_ARG_LIST;
1790
- SCRIPT_CONFIG;
1791
- constructor(assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
1820
+ SCRIPT_CONFIG_MAP;
1821
+ constructor(assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_INPUT) {
1792
1822
  this.assetsPrefetcher = assetsPrefetcher;
1793
1823
  this.assetSetter = assetSetter;
1794
1824
  this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
1795
- this.SCRIPT_CONFIG = SCRIPT_CONFIG;
1825
+ if (Array.isArray(SCRIPT_CONFIG_INPUT)) {
1826
+ this.SCRIPT_CONFIG_MAP = new Map();
1827
+ SCRIPT_CONFIG_INPUT.forEach((config) => {
1828
+ this.SCRIPT_CONFIG_MAP.set(config.scriptString, config);
1829
+ });
1830
+ }
1831
+ else {
1832
+ this.SCRIPT_CONFIG_MAP = SCRIPT_CONFIG_INPUT;
1833
+ }
1796
1834
  }
1835
+ /**
1836
+ * 解析场景
1837
+ * @param rawScene 原始场景
1838
+ * @param sceneName 场景名称
1839
+ * @param sceneUrl 场景url
1840
+ * @return 解析后的场景
1841
+ */
1797
1842
  parse(rawScene, sceneName, sceneUrl) {
1798
- return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
1843
+ return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG_MAP);
1799
1844
  }
1800
1845
  parseConfig(configText) {
1801
1846
  return configParser(configText);
1802
1847
  }
1803
1848
  stringifyConfig(config) {
1804
- return config
1805
- .reduce((previousValue, curr) => (previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`), '');
1849
+ return config.reduce((previousValue, curr) => previousValue +
1850
+ `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0
1851
+ ? ''
1852
+ : curr.options.reduce((p, c) => p + ' -' + c.key + '=' + c.value, '')};\n`, '');
1853
+ }
1854
+ parseScssToWebgalStyleObj(scssString) {
1855
+ return scss2cssinjsParser(scssString);
1806
1856
  }
1807
1857
  }
1808
1858
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * 语句类型
3
3
  */
4
- import { sceneEntry } from "./runtimeInterface";
5
- import { fileType } from "./assets";
4
+ import { sceneEntry } from './runtimeInterface';
5
+ import { fileType } from './assets';
6
6
  export declare enum commandType {
7
7
  say = 0,
8
8
  changeBg = 1,
@@ -35,7 +35,8 @@ export declare enum commandType {
35
35
  comment = 28,
36
36
  setTransform = 29,
37
37
  setTransition = 30,
38
- getUserInput = 31
38
+ getUserInput = 31,
39
+ applyStyle = 32
39
40
  }
40
41
  /**
41
42
  * 单个参数接口
@@ -1,5 +1,6 @@
1
- import { IAsset, IScene } from "./interface/sceneInterface";
2
- import { fileType } from "./interface/assets";
1
+ import { commandType, IAsset, IScene } from './interface/sceneInterface';
2
+ import { fileType } from './interface/assets';
3
+ import { ConfigMap } from './config/scriptConfig';
3
4
  /**
4
5
  * 场景解析器
5
6
  * @param rawScene 原始场景
@@ -8,7 +9,7 @@ import { fileType } from "./interface/assets";
8
9
  * @param assetsPrefetcher
9
10
  * @param assetSetter
10
11
  * @param ADD_NEXT_ARG_LIST
11
- * @param SCRIPT_CONFIG
12
+ * @param SCRIPT_CONFIG_MAP
12
13
  * @return {IScene} 解析后的场景
13
14
  */
14
- export declare const sceneParser: (rawScene: string, sceneName: string, sceneUrl: string, assetsPrefetcher: (assetList: Array<IAsset>) => void, assetSetter: (fileName: string, assetType: fileType) => string, ADD_NEXT_ARG_LIST: any, SCRIPT_CONFIG: any) => IScene;
15
+ export declare const sceneParser: (rawScene: string, sceneName: string, sceneUrl: string, assetsPrefetcher: (assetList: Array<IAsset>) => void, assetSetter: (fileName: string, assetType: fileType) => string, ADD_NEXT_ARG_LIST: commandType[], SCRIPT_CONFIG_MAP: ConfigMap) => IScene;
@@ -1,5 +1,5 @@
1
- import { arg } from "../interface/sceneInterface";
2
- import { fileType } from "../interface/assets";
1
+ import { arg } from '../interface/sceneInterface';
2
+ import { fileType } from '../interface/assets';
3
3
  /**
4
4
  * 参数解析器
5
5
  * @param argsRaw 原始参数字符串
@@ -1,9 +1,10 @@
1
- import { parsedCommand } from "../interface/sceneInterface";
1
+ import { ConfigMap } from '../config/scriptConfig';
2
+ import { commandType, parsedCommand } from '../interface/sceneInterface';
2
3
  /**
3
4
  * 处理命令
4
5
  * @param commandRaw
5
6
  * @param ADD_NEXT_ARG_LIST
6
- * @param SCRIPT_CONFIG
7
+ * @param SCRIPT_CONFIG_MAP
7
8
  * @return {parsedCommand} 处理后的命令
8
9
  */
9
- export declare const commandParser: (commandRaw: string, ADD_NEXT_ARG_LIST: any, SCRIPT_CONFIG: any) => parsedCommand;
10
+ export declare const commandParser: (commandRaw: string, ADD_NEXT_ARG_LIST: commandType[], SCRIPT_CONFIG_MAP: ConfigMap) => parsedCommand;
@@ -1,4 +1,4 @@
1
- import { commandType } from "../interface/sceneInterface";
1
+ import { commandType } from '../interface/sceneInterface';
2
2
  /**
3
3
  * 解析语句内容的函数,主要作用是把文件名改为绝对地址或相对地址(根据使用情况而定)
4
4
  * @param contentRaw 原始语句内容