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