webgal-parser 4.4.9 → 4.4.14-1

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