webgal-parser 4.3.13-9 → 4.4.3
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 +1 -0
- package/build/cjs/index.d.ts +4 -3
- package/build/cjs/index.js +17 -3
- package/build/cjs/interface/sceneInterface.d.ts +3 -1
- package/build/cjs/parser4/index.d.ts +1 -0
- package/build/es/configParser/configParser.d.ts +1 -0
- package/build/es/index.d.ts +4 -3
- package/build/es/index.js +17 -3
- package/build/es/interface/sceneInterface.d.ts +3 -1
- package/build/es/parser4/index.d.ts +1 -0
- package/build/types/config/scriptConfig.d.ts +6 -0
- package/build/types/configParser/configParser.d.ts +1 -0
- package/build/types/index.d.ts +13 -0
- package/build/types/interface/assets.d.ts +12 -0
- package/build/types/interface/runtimeInterface.d.ts +9 -0
- package/build/types/interface/sceneInterface.d.ts +96 -0
- package/build/types/parser4/index.d.ts +1 -0
- package/build/types/sceneParser.d.ts +14 -0
- package/build/types/scriptParser/argsParser.d.ts +9 -0
- package/build/types/scriptParser/assetsScanner.d.ts +9 -0
- package/build/types/scriptParser/commandParser.d.ts +9 -0
- package/build/types/scriptParser/contentParser.d.ts +9 -0
- package/build/types/scriptParser/scriptParser.d.ts +9 -0
- package/build/types/scriptParser/subSceneScanner.d.ts +7 -0
- package/build/umd/index.global.js +1776 -0
- package/package.json +7 -4
- package/src/config/scriptConfig.ts +46 -46
- package/src/configParser/configParser.ts +4 -0
- package/src/index.ts +11 -6
- package/src/interface/assets.ts +12 -12
- package/src/interface/runtimeInterface.ts +9 -9
- package/src/interface/sceneInterface.ts +5 -3
- package/src/parser4/index.ts +158 -0
- package/src/sceneParser.ts +47 -47
- package/src/scriptParser/argsParser.ts +68 -62
- package/src/scriptParser/assetsScanner.ts +72 -72
- package/src/scriptParser/commandParser.ts +57 -57
- package/src/scriptParser/contentParser.ts +66 -66
- package/src/scriptParser/scriptParser.ts +87 -87
- package/src/scriptParser/subSceneScanner.ts +23 -23
- package/build/cjs/index.js.map +0 -1
- package/build/es/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webgal-parser",
|
|
3
|
-
"version": "4.3
|
|
3
|
+
"version": "4.4.3",
|
|
4
4
|
"description": "WebGAL script parser",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "vitest",
|
|
7
7
|
"coverage": "vitest run --coverage",
|
|
8
|
-
"build": "rimraf -rf ./build && rollup --config"
|
|
8
|
+
"build": "rimraf -rf ./build && rollup --config",
|
|
9
|
+
"debug": "tsx test/debug.ts"
|
|
9
10
|
},
|
|
11
|
+
"types": "./build/types/index.d.ts",
|
|
10
12
|
"module": "./build/es/index.js",
|
|
11
13
|
"main": "./build/cjs/index.js",
|
|
12
14
|
"author": "Mahiru <Mahiru_@outlook.com>",
|
|
13
15
|
"license": "MPL-2.0",
|
|
14
16
|
"dependencies": {
|
|
17
|
+
"chevrotain": "^10.5.0",
|
|
15
18
|
"cloudlogjs": "^1.0.11",
|
|
16
|
-
"lodash": "^4.17.21"
|
|
19
|
+
"lodash": "^4.17.21",
|
|
20
|
+
"tsx": "^3.12.7"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
23
|
"@rollup/plugin-commonjs": "^23.0.2",
|
|
@@ -25,7 +29,6 @@
|
|
|
25
29
|
"@vitest/coverage-c8": "^0.28.5",
|
|
26
30
|
"rollup": "^3.3.0",
|
|
27
31
|
"rollup-plugin-babel": "^4.4.0",
|
|
28
|
-
"rollup-plugin-dts": "^5.0.0",
|
|
29
32
|
"rollup-plugin-terser": "^7.0.2",
|
|
30
33
|
"rollup-plugin-typescript2": "^0.34.1",
|
|
31
34
|
"ts-node": "^10.9.1",
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { commandType } from "../interface/sceneInterface";
|
|
2
|
-
|
|
3
|
-
export const SCRIPT_CONFIG = [
|
|
4
|
-
{ scriptString: 'intro', scriptType: commandType.intro },
|
|
5
|
-
{ scriptString: 'changeBg', scriptType: commandType.changeBg },
|
|
6
|
-
{ scriptString: 'changeFigure', scriptType: commandType.changeFigure },
|
|
7
|
-
{ scriptString: 'miniAvatar', scriptType: commandType.miniAvatar },
|
|
8
|
-
{ scriptString: 'changeScene', scriptType: commandType.changeScene },
|
|
9
|
-
{ scriptString: 'choose', scriptType: commandType.choose},
|
|
10
|
-
{ scriptString: 'end', scriptType: commandType.end },
|
|
11
|
-
{ scriptString: 'bgm', scriptType: commandType.bgm },
|
|
12
|
-
{ scriptString: 'playVideo', scriptType: commandType.video },
|
|
13
|
-
{
|
|
14
|
-
scriptString: 'setComplexAnimation',
|
|
15
|
-
scriptType: commandType.setComplexAnimation,
|
|
16
|
-
},
|
|
17
|
-
{ scriptString: 'setFilter', scriptType: commandType.setFilter },
|
|
18
|
-
{ scriptString: 'pixiInit', scriptType: commandType.pixiInit },
|
|
19
|
-
{ scriptString: 'pixiPerform', scriptType: commandType.pixi },
|
|
20
|
-
{ scriptString: 'label', scriptType: commandType.label},
|
|
21
|
-
{ scriptString: 'jumpLabel', scriptType: commandType.jumpLabel},
|
|
22
|
-
{ scriptString: 'setVar', scriptType: commandType.setVar },
|
|
23
|
-
{ scriptString: 'callScene', scriptType: commandType.callScene },
|
|
24
|
-
{ scriptString: 'showVars', scriptType: commandType.showVars },
|
|
25
|
-
{ scriptString: 'unlockCg', scriptType: commandType.unlockCg },
|
|
26
|
-
{ scriptString: 'unlockBgm', scriptType: commandType.unlockBgm },
|
|
27
|
-
{ scriptString: 'say', scriptType: commandType.say },
|
|
28
|
-
{ scriptString: 'filmMode', scriptType: commandType.filmMode },
|
|
29
|
-
{ scriptString: 'callScene', scriptType: commandType.callScene },
|
|
30
|
-
{ scriptString: 'setTextbox', scriptType: commandType.setTextbox},
|
|
31
|
-
{ scriptString: 'setAnimation', scriptType: commandType.setAnimation },
|
|
32
|
-
{ scriptString: 'playEffect', scriptType: commandType.playEffect },
|
|
33
|
-
];
|
|
34
|
-
export const ADD_NEXT_ARG_LIST = [
|
|
35
|
-
commandType.bgm,
|
|
36
|
-
commandType.pixi,
|
|
37
|
-
commandType.pixiInit,
|
|
38
|
-
commandType.label,
|
|
39
|
-
commandType.if,
|
|
40
|
-
commandType.miniAvatar,
|
|
41
|
-
commandType.setVar,
|
|
42
|
-
commandType.unlockBgm,
|
|
43
|
-
commandType.unlockCg,
|
|
44
|
-
commandType.filmMode,
|
|
45
|
-
commandType.playEffect,
|
|
46
|
-
];
|
|
1
|
+
import { commandType } from "../interface/sceneInterface";
|
|
2
|
+
|
|
3
|
+
export const SCRIPT_CONFIG = [
|
|
4
|
+
{ scriptString: 'intro', scriptType: commandType.intro },
|
|
5
|
+
{ scriptString: 'changeBg', scriptType: commandType.changeBg },
|
|
6
|
+
{ scriptString: 'changeFigure', scriptType: commandType.changeFigure },
|
|
7
|
+
{ scriptString: 'miniAvatar', scriptType: commandType.miniAvatar },
|
|
8
|
+
{ scriptString: 'changeScene', scriptType: commandType.changeScene },
|
|
9
|
+
{ scriptString: 'choose', scriptType: commandType.choose},
|
|
10
|
+
{ scriptString: 'end', scriptType: commandType.end },
|
|
11
|
+
{ scriptString: 'bgm', scriptType: commandType.bgm },
|
|
12
|
+
{ scriptString: 'playVideo', scriptType: commandType.video },
|
|
13
|
+
{
|
|
14
|
+
scriptString: 'setComplexAnimation',
|
|
15
|
+
scriptType: commandType.setComplexAnimation,
|
|
16
|
+
},
|
|
17
|
+
{ scriptString: 'setFilter', scriptType: commandType.setFilter },
|
|
18
|
+
{ scriptString: 'pixiInit', scriptType: commandType.pixiInit },
|
|
19
|
+
{ scriptString: 'pixiPerform', scriptType: commandType.pixi },
|
|
20
|
+
{ scriptString: 'label', scriptType: commandType.label},
|
|
21
|
+
{ scriptString: 'jumpLabel', scriptType: commandType.jumpLabel},
|
|
22
|
+
{ scriptString: 'setVar', scriptType: commandType.setVar },
|
|
23
|
+
{ scriptString: 'callScene', scriptType: commandType.callScene },
|
|
24
|
+
{ scriptString: 'showVars', scriptType: commandType.showVars },
|
|
25
|
+
{ scriptString: 'unlockCg', scriptType: commandType.unlockCg },
|
|
26
|
+
{ scriptString: 'unlockBgm', scriptType: commandType.unlockBgm },
|
|
27
|
+
{ scriptString: 'say', scriptType: commandType.say },
|
|
28
|
+
{ scriptString: 'filmMode', scriptType: commandType.filmMode },
|
|
29
|
+
{ scriptString: 'callScene', scriptType: commandType.callScene },
|
|
30
|
+
{ scriptString: 'setTextbox', scriptType: commandType.setTextbox},
|
|
31
|
+
{ scriptString: 'setAnimation', scriptType: commandType.setAnimation },
|
|
32
|
+
{ scriptString: 'playEffect', scriptType: commandType.playEffect },
|
|
33
|
+
];
|
|
34
|
+
export const ADD_NEXT_ARG_LIST = [
|
|
35
|
+
commandType.bgm,
|
|
36
|
+
commandType.pixi,
|
|
37
|
+
commandType.pixiInit,
|
|
38
|
+
commandType.label,
|
|
39
|
+
commandType.if,
|
|
40
|
+
commandType.miniAvatar,
|
|
41
|
+
commandType.setVar,
|
|
42
|
+
commandType.unlockBgm,
|
|
43
|
+
commandType.unlockCg,
|
|
44
|
+
commandType.filmMode,
|
|
45
|
+
commandType.playEffect,
|
|
46
|
+
];
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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 "@/configParser/configParser";
|
|
5
6
|
|
|
6
7
|
export default class SceneParser {
|
|
7
8
|
|
|
@@ -12,7 +13,7 @@ export default class SceneParser {
|
|
|
12
13
|
|
|
13
14
|
constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void),
|
|
14
15
|
assetSetter: (fileName: string, assetType: fileType) => string,
|
|
15
|
-
ADD_NEXT_ARG_LIST: Array<
|
|
16
|
+
ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>) {
|
|
16
17
|
this.assetsPrefetcher = assetsPrefetcher;
|
|
17
18
|
this.assetSetter = assetSetter;
|
|
18
19
|
this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
|
|
@@ -23,6 +24,10 @@ export default class SceneParser {
|
|
|
23
24
|
) {
|
|
24
25
|
return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
|
|
25
26
|
}
|
|
27
|
+
|
|
28
|
+
parseConfig(configText: string) {
|
|
29
|
+
return configParser(configText)
|
|
30
|
+
}
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
export {
|
|
33
|
+
export {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG};
|
package/src/interface/assets.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 内置资源类型的枚举
|
|
3
|
-
*/
|
|
4
|
-
export enum fileType {
|
|
5
|
-
background,
|
|
6
|
-
bgm,
|
|
7
|
-
figure,
|
|
8
|
-
scene,
|
|
9
|
-
tex,
|
|
10
|
-
vocal,
|
|
11
|
-
video,
|
|
12
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 内置资源类型的枚举
|
|
3
|
+
*/
|
|
4
|
+
export enum fileType {
|
|
5
|
+
background,
|
|
6
|
+
bgm,
|
|
7
|
+
figure,
|
|
8
|
+
scene,
|
|
9
|
+
tex,
|
|
10
|
+
vocal,
|
|
11
|
+
video,
|
|
12
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 子场景结束后回到父场景的入口
|
|
3
|
-
* @interface sceneEntry
|
|
4
|
-
*/
|
|
5
|
-
export interface sceneEntry {
|
|
6
|
-
sceneName: string; // 场景名称
|
|
7
|
-
sceneUrl: string; // 场景url
|
|
8
|
-
continueLine: number; // 继续原场景的行号
|
|
9
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 子场景结束后回到父场景的入口
|
|
3
|
+
* @interface sceneEntry
|
|
4
|
+
*/
|
|
5
|
+
export interface sceneEntry {
|
|
6
|
+
sceneName: string; // 场景名称
|
|
7
|
+
sceneUrl: string; // 场景url
|
|
8
|
+
continueLine: number; // 继续原场景的行号
|
|
9
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 语句类型
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import {sceneEntry} from "./runtimeInterface";
|
|
5
|
+
import {fileType} from "./assets";
|
|
6
6
|
|
|
7
7
|
export enum commandType {
|
|
8
8
|
say, // 对话
|
|
@@ -33,7 +33,9 @@ export enum commandType {
|
|
|
33
33
|
setAnimation,
|
|
34
34
|
playEffect,
|
|
35
35
|
setTempAnimation,
|
|
36
|
-
comment
|
|
36
|
+
comment,
|
|
37
|
+
setTransform,
|
|
38
|
+
setTransition,
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
/**
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// (function jsonGrammarOnlyExample() {
|
|
2
|
+
// // ----------------- Lexer -----------------
|
|
3
|
+
// const createToken = chevrotain.createToken;
|
|
4
|
+
// const Lexer = chevrotain.Lexer;
|
|
5
|
+
//
|
|
6
|
+
// const True = createToken({ name: "True", pattern: /true/ });
|
|
7
|
+
// const False = createToken({ name: "False", pattern: /false/ });
|
|
8
|
+
// const LCurly = createToken({ name: "LCurly", pattern: /{/ });
|
|
9
|
+
// const RCurly = createToken({ name: "RCurly", pattern: /}/ });
|
|
10
|
+
// const LSquare = createToken({ name: "LSquare", pattern: /\[/ });
|
|
11
|
+
// const RSquare = createToken({ name: "RSquare", pattern: /]/ });
|
|
12
|
+
// const Comma = createToken({ name: "Comma", pattern: /,/ });
|
|
13
|
+
// const Colon = createToken({ name: "Colon", pattern: /:/ });
|
|
14
|
+
// const Lf = createToken({ name: "LF", pattern: /\n/ });
|
|
15
|
+
// const Semi = createToken({ name: ";", pattern: /;/ });
|
|
16
|
+
// const Command = createToken({ name: "Command", pattern: /Command/ });
|
|
17
|
+
// const ArgS = createToken({ name: " -", pattern: / -/ });
|
|
18
|
+
// const StringLiteral = createToken({
|
|
19
|
+
// name: "StringLiteral", pattern: /(?!(?:true|false|Command)\b)\w+/
|
|
20
|
+
// });
|
|
21
|
+
// const NumberLiteral = createToken({
|
|
22
|
+
// name: "NumberLiteral", pattern: /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/
|
|
23
|
+
// });
|
|
24
|
+
//
|
|
25
|
+
// const Equal = createToken({
|
|
26
|
+
// name: "=",
|
|
27
|
+
// pattern: /=/
|
|
28
|
+
// });
|
|
29
|
+
//
|
|
30
|
+
// const webgalTokens = [NumberLiteral, StringLiteral, RCurly, LCurly,
|
|
31
|
+
// LSquare, RSquare, Comma, Colon, True, False, Equal, Command, ArgS, Lf, Semi];
|
|
32
|
+
//
|
|
33
|
+
// const WebGalLexer = new Lexer(webgalTokens, {
|
|
34
|
+
// // Less position info tracked, reduces verbosity of the playground output.
|
|
35
|
+
// positionTracking: "onlyStart"
|
|
36
|
+
// });
|
|
37
|
+
//
|
|
38
|
+
// // Labels only affect error messages and Diagrams.
|
|
39
|
+
// LCurly.LABEL = "'{'";
|
|
40
|
+
// RCurly.LABEL = "'}'";
|
|
41
|
+
// LSquare.LABEL = "'['";
|
|
42
|
+
// RSquare.LABEL = "']'";
|
|
43
|
+
// Comma.LABEL = "','";
|
|
44
|
+
// Colon.LABEL = "':'";
|
|
45
|
+
//
|
|
46
|
+
//
|
|
47
|
+
// // ----------------- parser -----------------
|
|
48
|
+
// const CstParser = chevrotain.CstParser;
|
|
49
|
+
//
|
|
50
|
+
// class webgalScriptParser extends CstParser {
|
|
51
|
+
// constructor() {
|
|
52
|
+
// super(webgalTokens, {
|
|
53
|
+
// recoveryEnabled: true
|
|
54
|
+
// });
|
|
55
|
+
//
|
|
56
|
+
// const $ = this;
|
|
57
|
+
//
|
|
58
|
+
// $.RULE("scene", () => {
|
|
59
|
+
// $.MANY_SEP({
|
|
60
|
+
// SEP: Lf, DEF: () => {
|
|
61
|
+
// $.SUBRULE($.sentence);
|
|
62
|
+
// }
|
|
63
|
+
// });
|
|
64
|
+
// });
|
|
65
|
+
//
|
|
66
|
+
// $.RULE("sentence", () => {
|
|
67
|
+
// $.OR([
|
|
68
|
+
// { ALT: () => $.SUBRULE($.commonSentence) },
|
|
69
|
+
// { ALT: () => $.SUBRULE($.comment) }
|
|
70
|
+
// ]);
|
|
71
|
+
// });
|
|
72
|
+
//
|
|
73
|
+
// $.RULE("commonSentence", () => {
|
|
74
|
+
// $.OR([
|
|
75
|
+
// { ALT: () => $.SUBRULE($.commandSentence) },
|
|
76
|
+
// { ALT: () => $.SUBRULE($.dialog) }
|
|
77
|
+
// ]);
|
|
78
|
+
// $.OPTION(() => {
|
|
79
|
+
// $.CONSUME(Semi);
|
|
80
|
+
// });
|
|
81
|
+
// });
|
|
82
|
+
//
|
|
83
|
+
// $.RULE("comment", () => {
|
|
84
|
+
// $.CONSUME(Semi);
|
|
85
|
+
// $.CONSUME(StringLiteral);
|
|
86
|
+
// });
|
|
87
|
+
//
|
|
88
|
+
// $.RULE("dialog", () => {
|
|
89
|
+
// $.CONSUME(StringLiteral);
|
|
90
|
+
//
|
|
91
|
+
// });
|
|
92
|
+
//
|
|
93
|
+
//
|
|
94
|
+
// $.RULE("commandSentence", () => {
|
|
95
|
+
// $.CONSUME(Command);
|
|
96
|
+
// $.CONSUME(Colon);
|
|
97
|
+
// $.CONSUME(StringLiteral);
|
|
98
|
+
// $.OPTION(() => {
|
|
99
|
+
// $.SUBRULE($.args);
|
|
100
|
+
// });
|
|
101
|
+
// });
|
|
102
|
+
//
|
|
103
|
+
// $.RULE("args", () => {
|
|
104
|
+
// $.CONSUME(ArgS);
|
|
105
|
+
// $.MANY_SEP({
|
|
106
|
+
// SEP: ArgS, DEF: () => {
|
|
107
|
+
// $.SUBRULE($.arg);
|
|
108
|
+
// }
|
|
109
|
+
// });
|
|
110
|
+
// });
|
|
111
|
+
//
|
|
112
|
+
// $.RULE("arg", () => {
|
|
113
|
+
// $.CONSUME(StringLiteral);
|
|
114
|
+
// $.CONSUME(Equal);
|
|
115
|
+
// $.SUBRULE($.argv);
|
|
116
|
+
// });
|
|
117
|
+
//
|
|
118
|
+
// $.RULE("argv", () => {
|
|
119
|
+
// $.OR([
|
|
120
|
+
// {
|
|
121
|
+
// ALT: () => {
|
|
122
|
+
// this.CONSUME(StringLiteral);
|
|
123
|
+
// }
|
|
124
|
+
// },
|
|
125
|
+
// {
|
|
126
|
+
// ALT: () => {
|
|
127
|
+
// this.CONSUME(NumberLiteral);
|
|
128
|
+
// }
|
|
129
|
+
// },
|
|
130
|
+
// {
|
|
131
|
+
// ALT: () => {
|
|
132
|
+
// this.CONSUME(True);
|
|
133
|
+
// }
|
|
134
|
+
// },
|
|
135
|
+
// {
|
|
136
|
+
// ALT: () => {
|
|
137
|
+
// this.CONSUME(False);
|
|
138
|
+
// }
|
|
139
|
+
// }]);
|
|
140
|
+
// });
|
|
141
|
+
//
|
|
142
|
+
// // very important to call this after all the rules have been setup.
|
|
143
|
+
// // otherwise the parser may not work correctly as it will lack information
|
|
144
|
+
// // derived from the self analysis.
|
|
145
|
+
// this.performSelfAnalysis();
|
|
146
|
+
// }
|
|
147
|
+
//
|
|
148
|
+
// }
|
|
149
|
+
//
|
|
150
|
+
//
|
|
151
|
+
// // for the playground to work the returned object must contain these fields
|
|
152
|
+
// return {
|
|
153
|
+
// lexer: WebGalLexer,
|
|
154
|
+
// parser: webgalScriptParser,
|
|
155
|
+
// defaultRule: "scene"
|
|
156
|
+
// };
|
|
157
|
+
// }());
|
|
158
|
+
export const parser4 = 'unreleased'
|
package/src/sceneParser.ts
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { IAsset, IScene, ISentence } from "./interface/sceneInterface";
|
|
2
|
-
import { scriptParser } from "./scriptParser/scriptParser";
|
|
3
|
-
import uniqWith from "lodash/uniqWith";
|
|
4
|
-
import { fileType } from "./interface/assets";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 场景解析器
|
|
8
|
-
* @param rawScene 原始场景
|
|
9
|
-
* @param sceneName 场景名称
|
|
10
|
-
* @param sceneUrl 场景url
|
|
11
|
-
* @param assetsPrefetcher
|
|
12
|
-
* @param assetSetter
|
|
13
|
-
* @param ADD_NEXT_ARG_LIST
|
|
14
|
-
* @param SCRIPT_CONFIG
|
|
15
|
-
* @return {IScene} 解析后的场景
|
|
16
|
-
*/
|
|
17
|
-
export const sceneParser = (rawScene: string, sceneName: string, sceneUrl: string
|
|
18
|
-
, assetsPrefetcher: ((assetList: Array<IAsset>) => void), assetSetter: (fileName: string, assetType: fileType) => string
|
|
19
|
-
, ADD_NEXT_ARG_LIST: any, SCRIPT_CONFIG: any): IScene => {
|
|
20
|
-
const rawSentenceList = rawScene.split("\n"); // 原始句子列表
|
|
21
|
-
|
|
22
|
-
// 去分号留到后面去做了,现在注释要单独处理
|
|
23
|
-
const rawSentenceListWithoutEmpty = rawSentenceList;
|
|
24
|
-
// .map((sentence) => sentence.split(";")[0])
|
|
25
|
-
// .filter((sentence) => sentence.trim() !== "");
|
|
26
|
-
let assetsList: Array<IAsset> = []; // 场景资源列表
|
|
27
|
-
let subSceneList: Array<string> = []; // 子场景列表
|
|
28
|
-
const sentenceList: Array<ISentence> = rawSentenceListWithoutEmpty.map((sentence) => {
|
|
29
|
-
const returnSentence: ISentence = scriptParser(sentence, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
30
|
-
// 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
|
|
31
|
-
assetsList = [...assetsList, ...returnSentence.sentenceAssets];
|
|
32
|
-
subSceneList = [...subSceneList, ...returnSentence.subScene];
|
|
33
|
-
return returnSentence;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// 开始资源的预加载
|
|
37
|
-
assetsList = uniqWith(assetsList); // 去重
|
|
38
|
-
assetsPrefetcher(assetsList);
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
sceneName: sceneName, // 场景名称
|
|
42
|
-
sceneUrl: sceneUrl,
|
|
43
|
-
sentenceList: sentenceList, // 语句列表
|
|
44
|
-
assetsList: assetsList, // 资源列表
|
|
45
|
-
subSceneList: subSceneList // 子场景列表
|
|
46
|
-
};
|
|
47
|
-
};
|
|
1
|
+
import { IAsset, IScene, ISentence } from "./interface/sceneInterface";
|
|
2
|
+
import { scriptParser } from "./scriptParser/scriptParser";
|
|
3
|
+
import uniqWith from "lodash/uniqWith";
|
|
4
|
+
import { fileType } from "./interface/assets";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 场景解析器
|
|
8
|
+
* @param rawScene 原始场景
|
|
9
|
+
* @param sceneName 场景名称
|
|
10
|
+
* @param sceneUrl 场景url
|
|
11
|
+
* @param assetsPrefetcher
|
|
12
|
+
* @param assetSetter
|
|
13
|
+
* @param ADD_NEXT_ARG_LIST
|
|
14
|
+
* @param SCRIPT_CONFIG
|
|
15
|
+
* @return {IScene} 解析后的场景
|
|
16
|
+
*/
|
|
17
|
+
export const sceneParser = (rawScene: string, sceneName: string, sceneUrl: string
|
|
18
|
+
, assetsPrefetcher: ((assetList: Array<IAsset>) => void), assetSetter: (fileName: string, assetType: fileType) => string
|
|
19
|
+
, ADD_NEXT_ARG_LIST: any, SCRIPT_CONFIG: any): IScene => {
|
|
20
|
+
const rawSentenceList = rawScene.split("\n"); // 原始句子列表
|
|
21
|
+
|
|
22
|
+
// 去分号留到后面去做了,现在注释要单独处理
|
|
23
|
+
const rawSentenceListWithoutEmpty = rawSentenceList;
|
|
24
|
+
// .map((sentence) => sentence.split(";")[0])
|
|
25
|
+
// .filter((sentence) => sentence.trim() !== "");
|
|
26
|
+
let assetsList: Array<IAsset> = []; // 场景资源列表
|
|
27
|
+
let subSceneList: Array<string> = []; // 子场景列表
|
|
28
|
+
const sentenceList: Array<ISentence> = rawSentenceListWithoutEmpty.map((sentence) => {
|
|
29
|
+
const returnSentence: ISentence = scriptParser(sentence, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
30
|
+
// 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
|
|
31
|
+
assetsList = [...assetsList, ...returnSentence.sentenceAssets];
|
|
32
|
+
subSceneList = [...subSceneList, ...returnSentence.subScene];
|
|
33
|
+
return returnSentence;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 开始资源的预加载
|
|
37
|
+
assetsList = uniqWith(assetsList); // 去重
|
|
38
|
+
assetsPrefetcher(assetsList);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
sceneName: sceneName, // 场景名称
|
|
42
|
+
sceneUrl: sceneUrl,
|
|
43
|
+
sentenceList: sentenceList, // 语句列表
|
|
44
|
+
assetsList: assetsList, // 资源列表
|
|
45
|
+
subSceneList: subSceneList // 子场景列表
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -1,62 +1,68 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* @param
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
returnArrayList.push({
|
|
53
|
-
key: argName,
|
|
54
|
-
value: argValue
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
1
|
+
import {arg} from "../interface/sceneInterface";
|
|
2
|
+
import {fileType} from "../interface/assets";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 参数解析器
|
|
6
|
+
* @param argsRaw 原始参数字符串
|
|
7
|
+
* @param assetSetter
|
|
8
|
+
* @return {Array<arg>} 解析后的参数列表
|
|
9
|
+
*/
|
|
10
|
+
export function argsParser(argsRaw: string, assetSetter: (fileName: string, assetType: fileType) => string): Array<arg> {
|
|
11
|
+
const returnArrayList: Array<arg> = [];
|
|
12
|
+
// 处理参数
|
|
13
|
+
// 不要去空格
|
|
14
|
+
let newArgsRaw = argsRaw.replace(/ /g, " ");
|
|
15
|
+
// 分割参数列表
|
|
16
|
+
let rawArgsList: Array<string> = newArgsRaw.split(" -");
|
|
17
|
+
// 去除空字符串
|
|
18
|
+
rawArgsList = rawArgsList.filter((e) => {
|
|
19
|
+
return e !== "";
|
|
20
|
+
});
|
|
21
|
+
rawArgsList.forEach((e) => {
|
|
22
|
+
const equalSignIndex = e.indexOf('=');
|
|
23
|
+
let argName = e.slice(0, equalSignIndex);
|
|
24
|
+
let argValue: string | undefined = e.slice(equalSignIndex + 1);
|
|
25
|
+
if (equalSignIndex < 0) {
|
|
26
|
+
argName = e;
|
|
27
|
+
argValue = undefined;
|
|
28
|
+
}
|
|
29
|
+
// 判断是不是语音参数
|
|
30
|
+
if (e.match(/.ogg|.mp3|.wav/)) {
|
|
31
|
+
returnArrayList.push({
|
|
32
|
+
key: "vocal",
|
|
33
|
+
value: assetSetter(e, fileType.vocal)
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
// 判断是不是省略参数
|
|
37
|
+
if (argValue === undefined) {
|
|
38
|
+
returnArrayList.push({
|
|
39
|
+
key: argName,
|
|
40
|
+
value: true
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
// 是字符串描述的布尔值
|
|
44
|
+
if (argValue === "true" || argValue === "false") {
|
|
45
|
+
returnArrayList.push({
|
|
46
|
+
key: argName,
|
|
47
|
+
value: argValue === "true"
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
// 是数字
|
|
51
|
+
if (!isNaN(Number(argValue))) {
|
|
52
|
+
returnArrayList.push({
|
|
53
|
+
key: argName,
|
|
54
|
+
value: Number(argValue)
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
// 是普通参数
|
|
58
|
+
returnArrayList.push({
|
|
59
|
+
key: argName,
|
|
60
|
+
value: argValue
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return returnArrayList;
|
|
68
|
+
};
|