webgal-parser 4.4.15 → 4.5.13

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.
@@ -37,52 +37,62 @@ var commandType;
37
37
  commandType[commandType["setTransition"] = 30] = "setTransition";
38
38
  commandType[commandType["getUserInput"] = 31] = "getUserInput";
39
39
  commandType[commandType["applyStyle"] = 32] = "applyStyle";
40
+ commandType[commandType["wait"] = 33] = "wait";
40
41
  })(commandType || (commandType = {}));
41
42
 
42
43
  const SCRIPT_CONFIG = [
43
- { scriptString: 'intro', scriptType: commandType.intro },
44
+ { scriptString: 'say', scriptType: commandType.say },
44
45
  { scriptString: 'changeBg', scriptType: commandType.changeBg },
45
46
  { scriptString: 'changeFigure', scriptType: commandType.changeFigure },
47
+ { scriptString: 'bgm', scriptType: commandType.bgm },
48
+ { scriptString: 'playVideo', scriptType: commandType.video },
49
+ { scriptString: 'pixiPerform', scriptType: commandType.pixi },
50
+ { scriptString: 'pixiInit', scriptType: commandType.pixiInit },
51
+ { scriptString: 'intro', scriptType: commandType.intro },
46
52
  { scriptString: 'miniAvatar', scriptType: commandType.miniAvatar },
47
53
  { scriptString: 'changeScene', scriptType: commandType.changeScene },
48
54
  { scriptString: 'choose', scriptType: commandType.choose },
49
55
  { scriptString: 'end', scriptType: commandType.end },
50
- { scriptString: 'bgm', scriptType: commandType.bgm },
51
- { scriptString: 'playVideo', scriptType: commandType.video },
52
56
  {
53
57
  scriptString: 'setComplexAnimation',
54
58
  scriptType: commandType.setComplexAnimation,
55
59
  },
56
60
  { scriptString: 'setFilter', scriptType: commandType.setFilter },
57
- { scriptString: 'pixiInit', scriptType: commandType.pixiInit },
58
- { scriptString: 'pixiPerform', scriptType: commandType.pixi },
59
61
  { scriptString: 'label', scriptType: commandType.label },
60
62
  { scriptString: 'jumpLabel', scriptType: commandType.jumpLabel },
63
+ { scriptString: 'chooseLabel', scriptType: commandType.chooseLabel },
61
64
  { scriptString: 'setVar', scriptType: commandType.setVar },
65
+ { scriptString: 'if', scriptType: commandType.if },
62
66
  { scriptString: 'callScene', scriptType: commandType.callScene },
63
67
  { scriptString: 'showVars', scriptType: commandType.showVars },
64
68
  { scriptString: 'unlockCg', scriptType: commandType.unlockCg },
65
69
  { scriptString: 'unlockBgm', scriptType: commandType.unlockBgm },
66
- { scriptString: 'say', scriptType: commandType.say },
67
70
  { scriptString: 'filmMode', scriptType: commandType.filmMode },
68
- { scriptString: 'callScene', scriptType: commandType.callScene },
69
71
  { scriptString: 'setTextbox', scriptType: commandType.setTextbox },
70
72
  { scriptString: 'setAnimation', scriptType: commandType.setAnimation },
71
73
  { scriptString: 'playEffect', scriptType: commandType.playEffect },
74
+ { scriptString: 'setTempAnimation', scriptType: commandType.setTempAnimation },
75
+ // comment?
76
+ { scriptString: 'setTransform', scriptType: commandType.setTransform },
77
+ { scriptString: 'setTransition', scriptType: commandType.setTransition },
78
+ { scriptString: 'getUserInput', scriptType: commandType.getUserInput },
72
79
  { scriptString: 'applyStyle', scriptType: commandType.applyStyle },
80
+ { scriptString: 'wait', scriptType: commandType.wait },
73
81
  ];
74
82
  const ADD_NEXT_ARG_LIST = [
75
83
  commandType.bgm,
76
84
  commandType.pixi,
77
85
  commandType.pixiInit,
86
+ commandType.miniAvatar,
78
87
  commandType.label,
79
88
  commandType.if,
80
- commandType.miniAvatar,
81
89
  commandType.setVar,
82
- commandType.unlockBgm,
83
90
  commandType.unlockCg,
91
+ commandType.unlockBgm,
84
92
  commandType.filmMode,
85
93
  commandType.playEffect,
94
+ commandType.setTransition,
95
+ commandType.applyStyle,
86
96
  ];
87
97
 
88
98
  /**
@@ -182,7 +192,7 @@ function configLineParser(inputLine) {
182
192
  };
183
193
  }
184
194
  // 截取命令
185
- const getCommandResult = /:/.exec(newSentenceRaw);
195
+ const getCommandResult = /\s*:\s*/.exec(newSentenceRaw);
186
196
  // 没有command
187
197
  if (getCommandResult === null) {
188
198
  command = '';
@@ -304,12 +314,12 @@ const contentParser = (contentRaw, type, assetSetter) => {
304
314
  }
305
315
  };
306
316
  function getChooseContent(contentRaw, assetSetter) {
307
- const chooseList = contentRaw.split('|');
317
+ const chooseList = contentRaw.split(/(?<!\\)\|/);
308
318
  const chooseKeyList = [];
309
319
  const chooseValueList = [];
310
320
  for (const e of chooseList) {
311
- chooseKeyList.push(e.split(':')[0] ?? '');
312
- chooseValueList.push(e.split(':')[1] ?? '');
321
+ chooseKeyList.push(e.split(/(?<!\\):/)[0] ?? '');
322
+ chooseValueList.push(e.split(/(?<!\\):/)[1] ?? '');
313
323
  }
314
324
  const parsedChooseList = chooseValueList.map((e) => {
315
325
  if (e.match(/\./)) {
@@ -436,8 +446,9 @@ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG
436
446
  let parsedCommand; // 解析后的命令
437
447
  let commandRaw;
438
448
  // 正式开始解析
439
- // 去分号,前面已做,这里不再需要
440
- let newSentenceRaw = sentenceRaw.split(';')[0];
449
+ // 去分号
450
+ let newSentenceRaw = sentenceRaw.split(/(?<!\\);/)[0];
451
+ newSentenceRaw = newSentenceRaw.replaceAll('\\;', ';');
441
452
  if (newSentenceRaw === '') {
442
453
  // 注释提前返回
443
454
  return {
@@ -487,12 +498,12 @@ const scriptParser = (sentenceRaw, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG
487
498
  args.push(e);
488
499
  }
489
500
  }
490
- content = contentParser(newSentenceRaw, command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
501
+ content = contentParser(newSentenceRaw.trim(), command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
491
502
  sentenceAssets = assetsScanner(command, content, args); // 扫描语句携带资源
492
503
  subScene = subSceneScanner(command, content); // 扫描语句携带子场景
493
504
  return {
494
505
  command: command,
495
- commandRaw: commandRaw,
506
+ commandRaw: commandRaw.trim(),
496
507
  content: content,
497
508
  args: args,
498
509
  sentenceAssets: sentenceAssets,
@@ -1816,6 +1827,198 @@ function parseCSS(css) {
1816
1827
  return [result, specialRules.trim()];
1817
1828
  }
1818
1829
 
1830
+ /**
1831
+ * Preprocessor for scene text.
1832
+ *
1833
+ * Use two-pass to generate a new scene text that concats multiline sequences
1834
+ * into a single line and add placeholder lines to preserve the original number
1835
+ * of lines.
1836
+ *
1837
+ * @param sceneText The original scene text
1838
+ * @returns The processed scene text
1839
+ */
1840
+ function sceneTextPreProcess(sceneText) {
1841
+ let lines = sceneText.replaceAll('\r', '').split('\n');
1842
+ lines = sceneTextPreProcessPassOne(lines);
1843
+ lines = sceneTextPreProcessPassTwo(lines);
1844
+ return lines.join('\n');
1845
+ }
1846
+ /**
1847
+ * Pass one.
1848
+ *
1849
+ * Add escape character to all lines that should be multiline.
1850
+ *
1851
+ * @param lines The original lines
1852
+ * @returns The processed lines
1853
+ */
1854
+ function sceneTextPreProcessPassOne(lines) {
1855
+ const processedLines = [];
1856
+ let lastLineIsMultiline = false;
1857
+ let thisLineIsMultiline = false;
1858
+ for (const line of lines) {
1859
+ thisLineIsMultiline = false;
1860
+ if (canBeMultiline(line)) {
1861
+ thisLineIsMultiline = true;
1862
+ }
1863
+ if (shouldNotBeMultiline(line, lastLineIsMultiline)) {
1864
+ thisLineIsMultiline = false;
1865
+ }
1866
+ if (thisLineIsMultiline) {
1867
+ processedLines[processedLines.length - 1] += '\\';
1868
+ }
1869
+ processedLines.push(line);
1870
+ lastLineIsMultiline = thisLineIsMultiline;
1871
+ }
1872
+ return processedLines;
1873
+ }
1874
+ function canBeMultiline(line) {
1875
+ if (!line.startsWith(' ')) {
1876
+ return false;
1877
+ }
1878
+ const trimmedLine = line.trimStart();
1879
+ return trimmedLine.startsWith('|') || trimmedLine.startsWith('-');
1880
+ }
1881
+ /**
1882
+ * Logic to check if a line should not be multiline.
1883
+ *
1884
+ * @param line The line to check
1885
+ * @returns If the line should not be multiline
1886
+ */
1887
+ function shouldNotBeMultiline(line, lastLineIsMultiline) {
1888
+ if (!lastLineIsMultiline && isEmptyLine(line)) {
1889
+ return true;
1890
+ }
1891
+ // Custom logic: if the line contains -concat, it should not be multiline
1892
+ if (line.indexOf('-concat') !== -1) {
1893
+ return true;
1894
+ }
1895
+ return false;
1896
+ }
1897
+ function isEmptyLine(line) {
1898
+ return line.trim() === '';
1899
+ }
1900
+ /**
1901
+ * Pass two.
1902
+ *
1903
+ * Traverse the lines to
1904
+ * - remove escape characters
1905
+ * - add placeholder lines to preserve the original number of lines.
1906
+ *
1907
+ * @param lines The lines in pass one
1908
+ * @returns The processed lines
1909
+ */
1910
+ function sceneTextPreProcessPassTwo(lines) {
1911
+ const processedLines = [];
1912
+ let currentMultilineContent = "";
1913
+ let placeHolderLines = [];
1914
+ function concat(line) {
1915
+ let trimmed = line.trim();
1916
+ if (trimmed.startsWith('-')) {
1917
+ trimmed = " " + trimmed;
1918
+ }
1919
+ currentMultilineContent = currentMultilineContent + trimmed;
1920
+ placeHolderLines.push(placeholderLine(line));
1921
+ }
1922
+ for (const line of lines) {
1923
+ console.log(line);
1924
+ if (line.endsWith('\\')) {
1925
+ const trueLine = line.slice(0, -1);
1926
+ if (currentMultilineContent === "") {
1927
+ // first line
1928
+ currentMultilineContent = trueLine;
1929
+ }
1930
+ else {
1931
+ // middle line
1932
+ concat(trueLine);
1933
+ }
1934
+ continue;
1935
+ }
1936
+ if (currentMultilineContent !== "") {
1937
+ // end line
1938
+ concat(line);
1939
+ processedLines.push(currentMultilineContent);
1940
+ processedLines.push(...placeHolderLines);
1941
+ placeHolderLines = [];
1942
+ currentMultilineContent = "";
1943
+ continue;
1944
+ }
1945
+ processedLines.push(line);
1946
+ }
1947
+ return processedLines;
1948
+ }
1949
+ /**
1950
+ * Placeholder Line. Adding this line preserves the original number of lines
1951
+ * in the scene text, so that it can be compatible with the graphical editor.
1952
+ *
1953
+ * @param content The original content on this line
1954
+ * @returns The placeholder line
1955
+ */
1956
+ function placeholderLine(content = "") {
1957
+ return ";_WEBGAL_LINE_BREAK_" + content;
1958
+ }
1959
+ // export function sceneTextPreProcess(sceneText: string): string {
1960
+ // const lines = sceneText.replaceAll('\r', '').split('\n');
1961
+ // const processedLines: string[] = [];
1962
+ // let lastNonMultilineIndex = -1;
1963
+ // let isInMultilineSequence = false;
1964
+ // function isMultiline(line: string): boolean {
1965
+ // if (!line.startsWith(' ')) return false;
1966
+ // const trimmedLine = line.trimStart();
1967
+ // return trimmedLine.startsWith('|') || trimmedLine.startsWith('-');
1968
+ // }
1969
+ // for (let i = 0; i < lines.length; i++) {
1970
+ // const line = lines[i];
1971
+ // if (line.trim() === '') {
1972
+ // // Empty line handling
1973
+ // if (isInMultilineSequence) {
1974
+ // // Check if the next line is a multiline line
1975
+ // let isStillInMulti = false;
1976
+ // for (let j = i + 1; j < lines.length; j++) {
1977
+ // const lookForwardLine = lines[j] || '';
1978
+ // // 遇到正常语句了,直接中断
1979
+ // if (lookForwardLine.trim() !== '' && !isMultiline(lookForwardLine)) {
1980
+ // isStillInMulti = false;
1981
+ // break;
1982
+ // }
1983
+ // // 必须找到后面接的是参数,并且中间没有遇到任何正常语句才行
1984
+ // if (lookForwardLine.trim() !== '' && isMultiline(lookForwardLine)) {
1985
+ // isStillInMulti = true;
1986
+ // break;
1987
+ // }
1988
+ // }
1989
+ // if (isStillInMulti) {
1990
+ // // Still within a multiline sequence
1991
+ // processedLines.push(';_WEBGAL_LINE_BREAK_');
1992
+ // } else {
1993
+ // // End of multiline sequence
1994
+ // isInMultilineSequence = false;
1995
+ // processedLines.push(line);
1996
+ // }
1997
+ // } else {
1998
+ // // Preserve empty lines outside of multiline sequences
1999
+ // processedLines.push(line);
2000
+ // }
2001
+ // } else if (isMultiline(line)) {
2002
+ // // Multiline statement handling
2003
+ // if (lastNonMultilineIndex >= 0) {
2004
+ // // Concatenate to the previous non-multiline statement
2005
+ // const trimedLine = line.trimStart();
2006
+ // const addBlank = trimedLine.startsWith('-') ? ' ' : '';
2007
+ // processedLines[lastNonMultilineIndex] += addBlank + trimedLine;
2008
+ // }
2009
+ // // Add the special comment line
2010
+ // processedLines.push(';_WEBGAL_LINE_BREAK_' + line);
2011
+ // isInMultilineSequence = true;
2012
+ // } else {
2013
+ // // Non-multiline statement handling
2014
+ // processedLines.push(line);
2015
+ // lastNonMultilineIndex = processedLines.length - 1;
2016
+ // isInMultilineSequence = false;
2017
+ // }
2018
+ // }
2019
+ // return processedLines.join('\n');
2020
+ // }
2021
+
1819
2022
  class SceneParser {
1820
2023
  assetsPrefetcher;
1821
2024
  assetSetter;
@@ -1862,3 +2065,4 @@ class SceneParser {
1862
2065
  exports.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
1863
2066
  exports.SCRIPT_CONFIG = SCRIPT_CONFIG;
1864
2067
  exports.default = SceneParser;
2068
+ exports.sceneTextPreProcess = sceneTextPreProcess;
@@ -3,6 +3,7 @@ import { WebgalConfig } from './configParser/configParser';
3
3
  import { fileType } from './interface/assets';
4
4
  import { IAsset } from './interface/sceneInterface';
5
5
  import { IWebGALStyleObj } from "./styleParser";
6
+ import { sceneTextPreProcess } from "./sceneTextPreProcessor";
6
7
  export default class SceneParser {
7
8
  private readonly assetsPrefetcher;
8
9
  private readonly assetSetter;
@@ -22,3 +23,4 @@ export default class SceneParser {
22
23
  parseScssToWebgalStyleObj(scssString: string): IWebGALStyleObj;
23
24
  }
24
25
  export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
26
+ export { sceneTextPreProcess };
@@ -36,7 +36,8 @@ export declare enum commandType {
36
36
  setTransform = 29,
37
37
  setTransition = 30,
38
38
  getUserInput = 31,
39
- applyStyle = 32
39
+ applyStyle = 32,
40
+ wait = 33
40
41
  }
41
42
  /**
42
43
  * 单个参数接口
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Preprocessor for scene text.
3
+ *
4
+ * Use two-pass to generate a new scene text that concats multiline sequences
5
+ * into a single line and add placeholder lines to preserve the original number
6
+ * of lines.
7
+ *
8
+ * @param sceneText The original scene text
9
+ * @returns The processed scene text
10
+ */
11
+ export declare function sceneTextPreProcess(sceneText: string): string;
@@ -3,6 +3,7 @@ import { WebgalConfig } from './configParser/configParser';
3
3
  import { fileType } from './interface/assets';
4
4
  import { IAsset } from './interface/sceneInterface';
5
5
  import { IWebGALStyleObj } from "./styleParser";
6
+ import { sceneTextPreProcess } from "./sceneTextPreProcessor";
6
7
  export default class SceneParser {
7
8
  private readonly assetsPrefetcher;
8
9
  private readonly assetSetter;
@@ -22,3 +23,4 @@ export default class SceneParser {
22
23
  parseScssToWebgalStyleObj(scssString: string): IWebGALStyleObj;
23
24
  }
24
25
  export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
26
+ export { sceneTextPreProcess };