webgal-parser 4.4.3 → 4.4.5
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/configParser/configParser.d.ts +12 -1
- package/build/cjs/index.d.ts +3 -1
- package/build/cjs/index.js +45 -2
- package/build/es/configParser/configParser.d.ts +12 -1
- package/build/es/index.d.ts +3 -1
- package/build/es/index.js +45 -2
- package/build/types/configParser/configParser.d.ts +12 -1
- package/build/types/index.d.ts +3 -1
- package/build/umd/index.global.js +45 -2
- package/package.json +40 -40
- package/src/configParser/configParser.ts +59 -3
- package/src/index.ts +42 -33
- package/src/interface/sceneInterface.ts +103 -103
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
interface IOptionItem {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string | number | boolean;
|
|
4
|
+
}
|
|
5
|
+
interface IConfigItem {
|
|
6
|
+
command: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
options: IOptionItem[];
|
|
9
|
+
}
|
|
10
|
+
export type WebgalConfig = IConfigItem[];
|
|
11
|
+
export declare function configParser(configText: string): WebgalConfig;
|
|
12
|
+
export {};
|
package/build/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAsset } from "./interface/sceneInterface";
|
|
2
2
|
import { fileType } from "./interface/assets";
|
|
3
3
|
import { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG } from "./config/scriptConfig";
|
|
4
|
+
import { WebgalConfig } from "./configParser/configParser";
|
|
4
5
|
export default class SceneParser {
|
|
5
6
|
private readonly assetsPrefetcher;
|
|
6
7
|
private readonly assetSetter;
|
|
@@ -8,6 +9,7 @@ export default class SceneParser {
|
|
|
8
9
|
private readonly SCRIPT_CONFIG;
|
|
9
10
|
constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void), assetSetter: (fileName: string, assetType: fileType) => string, ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>);
|
|
10
11
|
parse(rawScene: string, sceneName: string, sceneUrl: string): import("./interface/sceneInterface").IScene;
|
|
11
|
-
parseConfig(configText: string):
|
|
12
|
+
parseConfig(configText: string): WebgalConfig;
|
|
13
|
+
stringifyConfig(config: WebgalConfig): string;
|
|
12
14
|
}
|
|
13
15
|
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
|
package/build/cjs/index.js
CHANGED
|
@@ -1742,9 +1742,48 @@ const ADD_NEXT_ARG_LIST = [
|
|
|
1742
1742
|
commandType.playEffect,
|
|
1743
1743
|
];
|
|
1744
1744
|
|
|
1745
|
+
function configLineParser(inputLine) {
|
|
1746
|
+
const options = [];
|
|
1747
|
+
let command;
|
|
1748
|
+
let newSentenceRaw = inputLine.split(";")[0];
|
|
1749
|
+
if (newSentenceRaw === "") {
|
|
1750
|
+
// 注释提前返回
|
|
1751
|
+
return {
|
|
1752
|
+
command: '',
|
|
1753
|
+
args: [],
|
|
1754
|
+
options: []
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
// 截取命令
|
|
1758
|
+
const getCommandResult = /:/.exec(newSentenceRaw);
|
|
1759
|
+
// 没有command
|
|
1760
|
+
if (getCommandResult === null) {
|
|
1761
|
+
command = '';
|
|
1762
|
+
}
|
|
1763
|
+
else {
|
|
1764
|
+
command = newSentenceRaw.substring(0, getCommandResult.index);
|
|
1765
|
+
// 划分命令区域和content区域
|
|
1766
|
+
newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
|
|
1767
|
+
}
|
|
1768
|
+
// 截取 Options 区域
|
|
1769
|
+
const getOptionsResult = / -/.exec(newSentenceRaw);
|
|
1770
|
+
// 获取到参数
|
|
1771
|
+
if (getOptionsResult) {
|
|
1772
|
+
const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
|
|
1773
|
+
newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
|
|
1774
|
+
for (const e of argsParser(optionsRaw, (name, _) => { return name; })) {
|
|
1775
|
+
options.push(e);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
return {
|
|
1779
|
+
command,
|
|
1780
|
+
args: newSentenceRaw.split('|').map(e => e.trim()).filter(e => e !== ''),
|
|
1781
|
+
options
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1745
1784
|
function configParser(configText) {
|
|
1746
|
-
|
|
1747
|
-
return
|
|
1785
|
+
const configLines = configText.replaceAll(`\r`, '').split('\n');
|
|
1786
|
+
return configLines.map(e => configLineParser(e)).filter(e => e.command !== '');
|
|
1748
1787
|
}
|
|
1749
1788
|
|
|
1750
1789
|
class SceneParser {
|
|
@@ -1764,6 +1803,10 @@ class SceneParser {
|
|
|
1764
1803
|
parseConfig(configText) {
|
|
1765
1804
|
return configParser(configText);
|
|
1766
1805
|
}
|
|
1806
|
+
stringifyConfig(config) {
|
|
1807
|
+
return config
|
|
1808
|
+
.reduce((previousValue, curr) => (previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`), '');
|
|
1809
|
+
}
|
|
1767
1810
|
}
|
|
1768
1811
|
|
|
1769
1812
|
exports.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
interface IOptionItem {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string | number | boolean;
|
|
4
|
+
}
|
|
5
|
+
interface IConfigItem {
|
|
6
|
+
command: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
options: IOptionItem[];
|
|
9
|
+
}
|
|
10
|
+
export type WebgalConfig = IConfigItem[];
|
|
11
|
+
export declare function configParser(configText: string): WebgalConfig;
|
|
12
|
+
export {};
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAsset } from "./interface/sceneInterface";
|
|
2
2
|
import { fileType } from "./interface/assets";
|
|
3
3
|
import { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG } from "./config/scriptConfig";
|
|
4
|
+
import { WebgalConfig } from "./configParser/configParser";
|
|
4
5
|
export default class SceneParser {
|
|
5
6
|
private readonly assetsPrefetcher;
|
|
6
7
|
private readonly assetSetter;
|
|
@@ -8,6 +9,7 @@ export default class SceneParser {
|
|
|
8
9
|
private readonly SCRIPT_CONFIG;
|
|
9
10
|
constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void), assetSetter: (fileName: string, assetType: fileType) => string, ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>);
|
|
10
11
|
parse(rawScene: string, sceneName: string, sceneUrl: string): import("./interface/sceneInterface").IScene;
|
|
11
|
-
parseConfig(configText: string):
|
|
12
|
+
parseConfig(configText: string): WebgalConfig;
|
|
13
|
+
stringifyConfig(config: WebgalConfig): string;
|
|
12
14
|
}
|
|
13
15
|
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
|
package/build/es/index.js
CHANGED
|
@@ -1738,9 +1738,48 @@ const ADD_NEXT_ARG_LIST = [
|
|
|
1738
1738
|
commandType.playEffect,
|
|
1739
1739
|
];
|
|
1740
1740
|
|
|
1741
|
+
function configLineParser(inputLine) {
|
|
1742
|
+
const options = [];
|
|
1743
|
+
let command;
|
|
1744
|
+
let newSentenceRaw = inputLine.split(";")[0];
|
|
1745
|
+
if (newSentenceRaw === "") {
|
|
1746
|
+
// 注释提前返回
|
|
1747
|
+
return {
|
|
1748
|
+
command: '',
|
|
1749
|
+
args: [],
|
|
1750
|
+
options: []
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
// 截取命令
|
|
1754
|
+
const getCommandResult = /:/.exec(newSentenceRaw);
|
|
1755
|
+
// 没有command
|
|
1756
|
+
if (getCommandResult === null) {
|
|
1757
|
+
command = '';
|
|
1758
|
+
}
|
|
1759
|
+
else {
|
|
1760
|
+
command = newSentenceRaw.substring(0, getCommandResult.index);
|
|
1761
|
+
// 划分命令区域和content区域
|
|
1762
|
+
newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
|
|
1763
|
+
}
|
|
1764
|
+
// 截取 Options 区域
|
|
1765
|
+
const getOptionsResult = / -/.exec(newSentenceRaw);
|
|
1766
|
+
// 获取到参数
|
|
1767
|
+
if (getOptionsResult) {
|
|
1768
|
+
const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
|
|
1769
|
+
newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
|
|
1770
|
+
for (const e of argsParser(optionsRaw, (name, _) => { return name; })) {
|
|
1771
|
+
options.push(e);
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
return {
|
|
1775
|
+
command,
|
|
1776
|
+
args: newSentenceRaw.split('|').map(e => e.trim()).filter(e => e !== ''),
|
|
1777
|
+
options
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1741
1780
|
function configParser(configText) {
|
|
1742
|
-
|
|
1743
|
-
return
|
|
1781
|
+
const configLines = configText.replaceAll(`\r`, '').split('\n');
|
|
1782
|
+
return configLines.map(e => configLineParser(e)).filter(e => e.command !== '');
|
|
1744
1783
|
}
|
|
1745
1784
|
|
|
1746
1785
|
class SceneParser {
|
|
@@ -1760,6 +1799,10 @@ class SceneParser {
|
|
|
1760
1799
|
parseConfig(configText) {
|
|
1761
1800
|
return configParser(configText);
|
|
1762
1801
|
}
|
|
1802
|
+
stringifyConfig(config) {
|
|
1803
|
+
return config
|
|
1804
|
+
.reduce((previousValue, curr) => (previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`), '');
|
|
1805
|
+
}
|
|
1763
1806
|
}
|
|
1764
1807
|
|
|
1765
1808
|
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG, SceneParser as default };
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
interface IOptionItem {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string | number | boolean;
|
|
4
|
+
}
|
|
5
|
+
interface IConfigItem {
|
|
6
|
+
command: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
options: IOptionItem[];
|
|
9
|
+
}
|
|
10
|
+
export type WebgalConfig = IConfigItem[];
|
|
11
|
+
export declare function configParser(configText: string): WebgalConfig;
|
|
12
|
+
export {};
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAsset } from "./interface/sceneInterface";
|
|
2
2
|
import { fileType } from "./interface/assets";
|
|
3
3
|
import { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG } from "./config/scriptConfig";
|
|
4
|
+
import { WebgalConfig } from "./configParser/configParser";
|
|
4
5
|
export default class SceneParser {
|
|
5
6
|
private readonly assetsPrefetcher;
|
|
6
7
|
private readonly assetSetter;
|
|
@@ -8,6 +9,7 @@ export default class SceneParser {
|
|
|
8
9
|
private readonly SCRIPT_CONFIG;
|
|
9
10
|
constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void), assetSetter: (fileName: string, assetType: fileType) => string, ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>);
|
|
10
11
|
parse(rawScene: string, sceneName: string, sceneUrl: string): import("./interface/sceneInterface").IScene;
|
|
11
|
-
parseConfig(configText: string):
|
|
12
|
+
parseConfig(configText: string): WebgalConfig;
|
|
13
|
+
stringifyConfig(config: WebgalConfig): string;
|
|
12
14
|
}
|
|
13
15
|
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
|
|
@@ -1741,9 +1741,48 @@ var webgalParser = (function (exports) {
|
|
|
1741
1741
|
commandType.playEffect,
|
|
1742
1742
|
];
|
|
1743
1743
|
|
|
1744
|
+
function configLineParser(inputLine) {
|
|
1745
|
+
const options = [];
|
|
1746
|
+
let command;
|
|
1747
|
+
let newSentenceRaw = inputLine.split(";")[0];
|
|
1748
|
+
if (newSentenceRaw === "") {
|
|
1749
|
+
// 注释提前返回
|
|
1750
|
+
return {
|
|
1751
|
+
command: '',
|
|
1752
|
+
args: [],
|
|
1753
|
+
options: []
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
// 截取命令
|
|
1757
|
+
const getCommandResult = /:/.exec(newSentenceRaw);
|
|
1758
|
+
// 没有command
|
|
1759
|
+
if (getCommandResult === null) {
|
|
1760
|
+
command = '';
|
|
1761
|
+
}
|
|
1762
|
+
else {
|
|
1763
|
+
command = newSentenceRaw.substring(0, getCommandResult.index);
|
|
1764
|
+
// 划分命令区域和content区域
|
|
1765
|
+
newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
|
|
1766
|
+
}
|
|
1767
|
+
// 截取 Options 区域
|
|
1768
|
+
const getOptionsResult = / -/.exec(newSentenceRaw);
|
|
1769
|
+
// 获取到参数
|
|
1770
|
+
if (getOptionsResult) {
|
|
1771
|
+
const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
|
|
1772
|
+
newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
|
|
1773
|
+
for (const e of argsParser(optionsRaw, (name, _) => { return name; })) {
|
|
1774
|
+
options.push(e);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
return {
|
|
1778
|
+
command,
|
|
1779
|
+
args: newSentenceRaw.split('|').map(e => e.trim()).filter(e => e !== ''),
|
|
1780
|
+
options
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1744
1783
|
function configParser(configText) {
|
|
1745
|
-
|
|
1746
|
-
return
|
|
1784
|
+
const configLines = configText.replaceAll(`\r`, '').split('\n');
|
|
1785
|
+
return configLines.map(e => configLineParser(e)).filter(e => e.command !== '');
|
|
1747
1786
|
}
|
|
1748
1787
|
|
|
1749
1788
|
class SceneParser {
|
|
@@ -1763,6 +1802,10 @@ var webgalParser = (function (exports) {
|
|
|
1763
1802
|
parseConfig(configText) {
|
|
1764
1803
|
return configParser(configText);
|
|
1765
1804
|
}
|
|
1805
|
+
stringifyConfig(config) {
|
|
1806
|
+
return config
|
|
1807
|
+
.reduce((previousValue, curr) => (previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`), '');
|
|
1808
|
+
}
|
|
1766
1809
|
}
|
|
1767
1810
|
|
|
1768
1811
|
exports.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "webgal-parser",
|
|
3
|
-
"version": "4.4.
|
|
4
|
-
"description": "WebGAL script parser",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "vitest",
|
|
7
|
-
"coverage": "vitest run --coverage",
|
|
8
|
-
"build": "rimraf -rf ./build && rollup --config",
|
|
9
|
-
"debug": "tsx test/debug.ts"
|
|
10
|
-
},
|
|
11
|
-
"types": "./build/types/index.d.ts",
|
|
12
|
-
"module": "./build/es/index.js",
|
|
13
|
-
"main": "./build/cjs/index.js",
|
|
14
|
-
"author": "Mahiru <Mahiru_@outlook.com>",
|
|
15
|
-
"license": "MPL-2.0",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"chevrotain": "^10.5.0",
|
|
18
|
-
"cloudlogjs": "^1.0.11",
|
|
19
|
-
"lodash": "^4.17.21",
|
|
20
|
-
"tsx": "^3.12.7"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@rollup/plugin-commonjs": "^23.0.2",
|
|
24
|
-
"@rollup/plugin-json": "^5.0.1",
|
|
25
|
-
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
26
|
-
"@rollup/plugin-typescript": "^9.0.2",
|
|
27
|
-
"@types/lodash": "^4.14.189",
|
|
28
|
-
"@types/node": "^18.14.0",
|
|
29
|
-
"@vitest/coverage-c8": "^0.28.5",
|
|
30
|
-
"rollup": "^3.3.0",
|
|
31
|
-
"rollup-plugin-babel": "^4.4.0",
|
|
32
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
33
|
-
"rollup-plugin-typescript2": "^0.34.1",
|
|
34
|
-
"ts-node": "^10.9.1",
|
|
35
|
-
"tslib": "^2.4.1",
|
|
36
|
-
"typescript": "^4.9.3",
|
|
37
|
-
"vitest": "^0.28.5"
|
|
38
|
-
},
|
|
39
|
-
"type": "module"
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "webgal-parser",
|
|
3
|
+
"version": "4.4.5",
|
|
4
|
+
"description": "WebGAL script parser",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "vitest",
|
|
7
|
+
"coverage": "vitest run --coverage",
|
|
8
|
+
"build": "rimraf -rf ./build && rollup --config",
|
|
9
|
+
"debug": "tsx test/debug.ts"
|
|
10
|
+
},
|
|
11
|
+
"types": "./build/types/index.d.ts",
|
|
12
|
+
"module": "./build/es/index.js",
|
|
13
|
+
"main": "./build/cjs/index.js",
|
|
14
|
+
"author": "Mahiru <Mahiru_@outlook.com>",
|
|
15
|
+
"license": "MPL-2.0",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"chevrotain": "^10.5.0",
|
|
18
|
+
"cloudlogjs": "^1.0.11",
|
|
19
|
+
"lodash": "^4.17.21",
|
|
20
|
+
"tsx": "^3.12.7"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@rollup/plugin-commonjs": "^23.0.2",
|
|
24
|
+
"@rollup/plugin-json": "^5.0.1",
|
|
25
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
26
|
+
"@rollup/plugin-typescript": "^9.0.2",
|
|
27
|
+
"@types/lodash": "^4.14.189",
|
|
28
|
+
"@types/node": "^18.14.0",
|
|
29
|
+
"@vitest/coverage-c8": "^0.28.5",
|
|
30
|
+
"rollup": "^3.3.0",
|
|
31
|
+
"rollup-plugin-babel": "^4.4.0",
|
|
32
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
33
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
34
|
+
"ts-node": "^10.9.1",
|
|
35
|
+
"tslib": "^2.4.1",
|
|
36
|
+
"typescript": "^4.9.3",
|
|
37
|
+
"vitest": "^0.28.5"
|
|
38
|
+
},
|
|
39
|
+
"type": "module"
|
|
40
|
+
}
|
|
@@ -1,4 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {argsParser} from "../scriptParser/argsParser";
|
|
2
|
+
|
|
3
|
+
interface IOptionItem{
|
|
4
|
+
key:string;
|
|
5
|
+
value:string | number | boolean;
|
|
6
|
+
}
|
|
7
|
+
interface IConfigItem{
|
|
8
|
+
command:string;
|
|
9
|
+
args:string[]
|
|
10
|
+
options:IOptionItem[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type WebgalConfig = IConfigItem[]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function configLineParser(inputLine:string):IConfigItem{
|
|
17
|
+
const options:Array<IOptionItem> = [];
|
|
18
|
+
let command: string;
|
|
19
|
+
|
|
20
|
+
let newSentenceRaw = inputLine.split(";")[0];
|
|
21
|
+
if (newSentenceRaw === "") {
|
|
22
|
+
// 注释提前返回
|
|
23
|
+
return {
|
|
24
|
+
command:'',
|
|
25
|
+
args:[],
|
|
26
|
+
options:[]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// 截取命令
|
|
30
|
+
const getCommandResult = /:/.exec(newSentenceRaw);
|
|
31
|
+
|
|
32
|
+
// 没有command
|
|
33
|
+
if (getCommandResult === null) {
|
|
34
|
+
command = '';
|
|
35
|
+
} else {
|
|
36
|
+
command = newSentenceRaw.substring(0, getCommandResult.index);
|
|
37
|
+
// 划分命令区域和content区域
|
|
38
|
+
newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
|
|
39
|
+
}
|
|
40
|
+
// 截取 Options 区域
|
|
41
|
+
const getOptionsResult = / -/.exec(newSentenceRaw);
|
|
42
|
+
// 获取到参数
|
|
43
|
+
if (getOptionsResult) {
|
|
44
|
+
const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
|
|
45
|
+
newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
|
|
46
|
+
for (const e of argsParser(optionsRaw, (name,_)=>{return name})) {
|
|
47
|
+
options.push(e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
command,
|
|
52
|
+
args:newSentenceRaw.split('|').map(e=>e.trim()).filter(e=>e!==''),
|
|
53
|
+
options
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function configParser(configText:string):WebgalConfig{
|
|
58
|
+
const configLines = configText.replaceAll(`\r`,'').split('\n');
|
|
59
|
+
return configLines.map(e=>configLineParser(e)).filter(e=>e.command!=='');
|
|
4
60
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,33 +1,42 @@
|
|
|
1
|
-
import {commandType, IAsset} from "./interface/sceneInterface";
|
|
2
|
-
import {fileType} from "./interface/assets";
|
|
3
|
-
import {sceneParser} from "./sceneParser";
|
|
4
|
-
import {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG} from "./config/scriptConfig";
|
|
5
|
-
import {configParser} from "
|
|
6
|
-
|
|
7
|
-
export default class SceneParser {
|
|
8
|
-
|
|
9
|
-
private readonly assetsPrefetcher;
|
|
10
|
-
private readonly assetSetter;
|
|
11
|
-
private readonly ADD_NEXT_ARG_LIST;
|
|
12
|
-
private readonly SCRIPT_CONFIG;
|
|
13
|
-
|
|
14
|
-
constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void),
|
|
15
|
-
assetSetter: (fileName: string, assetType: fileType) => string,
|
|
16
|
-
ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>) {
|
|
17
|
-
this.assetsPrefetcher = assetsPrefetcher;
|
|
18
|
-
this.assetSetter = assetSetter;
|
|
19
|
-
this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
|
|
20
|
-
this.SCRIPT_CONFIG = SCRIPT_CONFIG;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
parse(rawScene: string, sceneName: string, sceneUrl: string
|
|
24
|
-
) {
|
|
25
|
-
return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
parseConfig(configText: string) {
|
|
29
|
-
return configParser(configText)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import {commandType, IAsset} from "./interface/sceneInterface";
|
|
2
|
+
import {fileType} from "./interface/assets";
|
|
3
|
+
import {sceneParser} from "./sceneParser";
|
|
4
|
+
import {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG} from "./config/scriptConfig";
|
|
5
|
+
import {configParser, WebgalConfig} from "./configParser/configParser";
|
|
6
|
+
|
|
7
|
+
export default class SceneParser {
|
|
8
|
+
|
|
9
|
+
private readonly assetsPrefetcher;
|
|
10
|
+
private readonly assetSetter;
|
|
11
|
+
private readonly ADD_NEXT_ARG_LIST;
|
|
12
|
+
private readonly SCRIPT_CONFIG;
|
|
13
|
+
|
|
14
|
+
constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void),
|
|
15
|
+
assetSetter: (fileName: string, assetType: fileType) => string,
|
|
16
|
+
ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>) {
|
|
17
|
+
this.assetsPrefetcher = assetsPrefetcher;
|
|
18
|
+
this.assetSetter = assetSetter;
|
|
19
|
+
this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
|
|
20
|
+
this.SCRIPT_CONFIG = SCRIPT_CONFIG;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
parse(rawScene: string, sceneName: string, sceneUrl: string
|
|
24
|
+
) {
|
|
25
|
+
return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
parseConfig(configText: string) {
|
|
29
|
+
return configParser(configText)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
stringifyConfig(config: WebgalConfig) {
|
|
33
|
+
return config
|
|
34
|
+
.reduce(
|
|
35
|
+
(previousValue, curr) =>
|
|
36
|
+
(previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`),
|
|
37
|
+
''
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG};
|
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 语句类型
|
|
3
|
-
*/
|
|
4
|
-
import {sceneEntry} from "./runtimeInterface";
|
|
5
|
-
import {fileType} from "./assets";
|
|
6
|
-
|
|
7
|
-
export enum commandType {
|
|
8
|
-
say, // 对话
|
|
9
|
-
changeBg, // 更改背景
|
|
10
|
-
changeFigure, // 更改立绘
|
|
11
|
-
bgm, // 更改背景音乐
|
|
12
|
-
video, // 播放视频
|
|
13
|
-
pixi, // pixi演出
|
|
14
|
-
pixiInit, // pixi初始化
|
|
15
|
-
intro, // 黑屏文字演示
|
|
16
|
-
miniAvatar, // 小头像
|
|
17
|
-
changeScene, // 切换场景
|
|
18
|
-
choose, // 分支选择
|
|
19
|
-
end, // 结束游戏
|
|
20
|
-
setComplexAnimation, // 动画演出
|
|
21
|
-
setFilter, // 设置效果
|
|
22
|
-
label, // 标签
|
|
23
|
-
jumpLabel, // 跳转标签
|
|
24
|
-
chooseLabel, // 选择标签
|
|
25
|
-
setVar, // 设置变量
|
|
26
|
-
if, // 条件跳转
|
|
27
|
-
callScene, // 调用场景
|
|
28
|
-
showVars,
|
|
29
|
-
unlockCg,
|
|
30
|
-
unlockBgm,
|
|
31
|
-
filmMode,
|
|
32
|
-
setTextbox,
|
|
33
|
-
setAnimation,
|
|
34
|
-
playEffect,
|
|
35
|
-
setTempAnimation,
|
|
36
|
-
comment,
|
|
37
|
-
setTransform,
|
|
38
|
-
setTransition,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 单个参数接口
|
|
43
|
-
* @interface arg
|
|
44
|
-
*/
|
|
45
|
-
export interface arg {
|
|
46
|
-
key: string; // 参数键
|
|
47
|
-
value: string | boolean | number; // 参数值
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 资源接口
|
|
52
|
-
* @interface IAsset
|
|
53
|
-
*/
|
|
54
|
-
export interface IAsset {
|
|
55
|
-
name: string; // 资源名称
|
|
56
|
-
type: fileType; // 资源类型
|
|
57
|
-
url: string; // 资源url
|
|
58
|
-
lineNumber: number; // 触发资源语句的行号
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 单条语句接口
|
|
63
|
-
* @interface ISentence
|
|
64
|
-
*/
|
|
65
|
-
export interface ISentence {
|
|
66
|
-
command: commandType; // 语句类型
|
|
67
|
-
commandRaw: string; // 命令的原始内容,方便调试
|
|
68
|
-
content: string; // 语句内容
|
|
69
|
-
args: Array<arg>; // 参数列表
|
|
70
|
-
sentenceAssets: Array<IAsset>; // 语句携带的资源列表
|
|
71
|
-
subScene: Array<string>; // 语句包含子场景列表
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 场景接口
|
|
76
|
-
* @interface IScene
|
|
77
|
-
*/
|
|
78
|
-
export interface IScene {
|
|
79
|
-
sceneName: string; // 场景名称
|
|
80
|
-
sceneUrl: string; // 场景url
|
|
81
|
-
sentenceList: Array<ISentence>; // 语句列表
|
|
82
|
-
assetsList: Array<IAsset>; // 资源列表
|
|
83
|
-
subSceneList: Array<string>; // 子场景的url列表
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 当前的场景数据
|
|
88
|
-
* @interface ISceneData
|
|
89
|
-
*/
|
|
90
|
-
export interface ISceneData {
|
|
91
|
-
currentSentenceId: number; // 当前语句ID
|
|
92
|
-
sceneStack: Array<sceneEntry>; // 场景栈
|
|
93
|
-
currentScene: IScene; // 当前场景数据
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 处理后的命令接口
|
|
98
|
-
* @interface parsedCommand
|
|
99
|
-
*/
|
|
100
|
-
export interface parsedCommand {
|
|
101
|
-
type: commandType;
|
|
102
|
-
additionalArgs: Array<arg>;
|
|
103
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 语句类型
|
|
3
|
+
*/
|
|
4
|
+
import {sceneEntry} from "./runtimeInterface";
|
|
5
|
+
import {fileType} from "./assets";
|
|
6
|
+
|
|
7
|
+
export enum commandType {
|
|
8
|
+
say, // 对话
|
|
9
|
+
changeBg, // 更改背景
|
|
10
|
+
changeFigure, // 更改立绘
|
|
11
|
+
bgm, // 更改背景音乐
|
|
12
|
+
video, // 播放视频
|
|
13
|
+
pixi, // pixi演出
|
|
14
|
+
pixiInit, // pixi初始化
|
|
15
|
+
intro, // 黑屏文字演示
|
|
16
|
+
miniAvatar, // 小头像
|
|
17
|
+
changeScene, // 切换场景
|
|
18
|
+
choose, // 分支选择
|
|
19
|
+
end, // 结束游戏
|
|
20
|
+
setComplexAnimation, // 动画演出
|
|
21
|
+
setFilter, // 设置效果
|
|
22
|
+
label, // 标签
|
|
23
|
+
jumpLabel, // 跳转标签
|
|
24
|
+
chooseLabel, // 选择标签
|
|
25
|
+
setVar, // 设置变量
|
|
26
|
+
if, // 条件跳转
|
|
27
|
+
callScene, // 调用场景
|
|
28
|
+
showVars,
|
|
29
|
+
unlockCg,
|
|
30
|
+
unlockBgm,
|
|
31
|
+
filmMode,
|
|
32
|
+
setTextbox,
|
|
33
|
+
setAnimation,
|
|
34
|
+
playEffect,
|
|
35
|
+
setTempAnimation,
|
|
36
|
+
comment,
|
|
37
|
+
setTransform,
|
|
38
|
+
setTransition,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 单个参数接口
|
|
43
|
+
* @interface arg
|
|
44
|
+
*/
|
|
45
|
+
export interface arg {
|
|
46
|
+
key: string; // 参数键
|
|
47
|
+
value: string | boolean | number; // 参数值
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 资源接口
|
|
52
|
+
* @interface IAsset
|
|
53
|
+
*/
|
|
54
|
+
export interface IAsset {
|
|
55
|
+
name: string; // 资源名称
|
|
56
|
+
type: fileType; // 资源类型
|
|
57
|
+
url: string; // 资源url
|
|
58
|
+
lineNumber: number; // 触发资源语句的行号
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 单条语句接口
|
|
63
|
+
* @interface ISentence
|
|
64
|
+
*/
|
|
65
|
+
export interface ISentence {
|
|
66
|
+
command: commandType; // 语句类型
|
|
67
|
+
commandRaw: string; // 命令的原始内容,方便调试
|
|
68
|
+
content: string; // 语句内容
|
|
69
|
+
args: Array<arg>; // 参数列表
|
|
70
|
+
sentenceAssets: Array<IAsset>; // 语句携带的资源列表
|
|
71
|
+
subScene: Array<string>; // 语句包含子场景列表
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 场景接口
|
|
76
|
+
* @interface IScene
|
|
77
|
+
*/
|
|
78
|
+
export interface IScene {
|
|
79
|
+
sceneName: string; // 场景名称
|
|
80
|
+
sceneUrl: string; // 场景url
|
|
81
|
+
sentenceList: Array<ISentence>; // 语句列表
|
|
82
|
+
assetsList: Array<IAsset>; // 资源列表
|
|
83
|
+
subSceneList: Array<string>; // 子场景的url列表
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 当前的场景数据
|
|
88
|
+
* @interface ISceneData
|
|
89
|
+
*/
|
|
90
|
+
export interface ISceneData {
|
|
91
|
+
currentSentenceId: number; // 当前语句ID
|
|
92
|
+
sceneStack: Array<sceneEntry>; // 场景栈
|
|
93
|
+
currentScene: IScene; // 当前场景数据
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 处理后的命令接口
|
|
98
|
+
* @interface parsedCommand
|
|
99
|
+
*/
|
|
100
|
+
export interface parsedCommand {
|
|
101
|
+
type: commandType;
|
|
102
|
+
additionalArgs: Array<arg>;
|
|
103
|
+
}
|