webgal-parser 4.5.2 → 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/cjs/index.cjs +216 -13
- package/build/cjs/index.d.ts +2 -0
- package/build/cjs/interface/sceneInterface.d.ts +2 -1
- package/build/cjs/sceneTextPreProcessor.d.ts +11 -0
- package/build/es/index.d.ts +2 -0
- package/build/es/index.js +216 -14
- package/build/es/interface/sceneInterface.d.ts +2 -1
- package/build/es/sceneTextPreProcessor.d.ts +11 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/interface/sceneInterface.d.ts +2 -1
- package/build/types/sceneTextPreProcessor.d.ts +11 -0
- package/build/umd/index.global.js +216 -13
- package/package.json +4 -3
- package/src/config/scriptConfig.ts +18 -9
- package/src/configParser/configParser.ts +1 -1
- package/src/index.ts +3 -1
- package/src/interface/sceneInterface.ts +2 -1
- package/src/sceneTextPreProcessor.ts +223 -0
- package/src/scriptParser/contentParser.ts +3 -3
package/build/cjs/index.cjs
CHANGED
|
@@ -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: '
|
|
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 =
|
|
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(
|
|
312
|
-
chooseValueList.push(e.split(
|
|
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(/\./)) {
|
|
@@ -1817,6 +1827,198 @@ function parseCSS(css) {
|
|
|
1817
1827
|
return [result, specialRules.trim()];
|
|
1818
1828
|
}
|
|
1819
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
|
+
|
|
1820
2022
|
class SceneParser {
|
|
1821
2023
|
assetsPrefetcher;
|
|
1822
2024
|
assetSetter;
|
|
@@ -1863,3 +2065,4 @@ class SceneParser {
|
|
|
1863
2065
|
exports.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
|
|
1864
2066
|
exports.SCRIPT_CONFIG = SCRIPT_CONFIG;
|
|
1865
2067
|
exports.default = SceneParser;
|
|
2068
|
+
exports.sceneTextPreProcess = sceneTextPreProcess;
|
package/build/cjs/index.d.ts
CHANGED
|
@@ -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 };
|
|
@@ -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;
|
package/build/es/index.d.ts
CHANGED
|
@@ -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 };
|
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: '
|
|
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 =
|
|
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(
|
|
308
|
-
chooseValueList.push(e.split(
|
|
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(/\./)) {
|
|
@@ -1813,6 +1823,198 @@ function parseCSS(css) {
|
|
|
1813
1823
|
return [result, specialRules.trim()];
|
|
1814
1824
|
}
|
|
1815
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
|
+
|
|
1816
2018
|
class SceneParser {
|
|
1817
2019
|
assetsPrefetcher;
|
|
1818
2020
|
assetSetter;
|
|
@@ -1856,4 +2058,4 @@ class SceneParser {
|
|
|
1856
2058
|
}
|
|
1857
2059
|
}
|
|
1858
2060
|
|
|
1859
|
-
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG, SceneParser as default };
|
|
2061
|
+
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG, SceneParser as default, sceneTextPreProcess };
|
|
@@ -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;
|
package/build/types/index.d.ts
CHANGED
|
@@ -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 };
|