webgal-parser 4.3.13 → 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.
Files changed (51) hide show
  1. package/build/cjs/config/scriptConfig.d.ts +1 -1
  2. package/build/cjs/configParser/configParser.d.ts +1 -0
  3. package/build/cjs/index.d.ts +5 -2
  4. package/build/cjs/index.js +1148 -17042
  5. package/build/cjs/interface/sceneInterface.d.ts +3 -1
  6. package/build/cjs/parser4/index.d.ts +1 -0
  7. package/build/cjs/scriptParser/subSceneScanner.d.ts +1 -1
  8. package/build/es/config/scriptConfig.d.ts +1 -1
  9. package/build/es/configParser/configParser.d.ts +1 -0
  10. package/build/es/index.d.ts +5 -2
  11. package/build/es/index.js +1147 -17043
  12. package/build/es/interface/sceneInterface.d.ts +3 -1
  13. package/build/es/parser4/index.d.ts +1 -0
  14. package/build/es/scriptParser/subSceneScanner.d.ts +1 -1
  15. package/build/types/config/scriptConfig.d.ts +6 -0
  16. package/build/types/configParser/configParser.d.ts +1 -0
  17. package/build/types/index.d.ts +13 -0
  18. package/build/types/interface/assets.d.ts +12 -0
  19. package/build/types/interface/runtimeInterface.d.ts +9 -0
  20. package/build/types/interface/sceneInterface.d.ts +96 -0
  21. package/build/types/parser4/index.d.ts +1 -0
  22. package/build/types/sceneParser.d.ts +14 -0
  23. package/build/types/scriptParser/argsParser.d.ts +9 -0
  24. package/build/types/scriptParser/assetsScanner.d.ts +9 -0
  25. package/build/types/scriptParser/commandParser.d.ts +9 -0
  26. package/build/types/scriptParser/contentParser.d.ts +9 -0
  27. package/build/types/scriptParser/scriptParser.d.ts +9 -0
  28. package/build/types/scriptParser/subSceneScanner.d.ts +7 -0
  29. package/build/umd/index.global.js +1776 -0
  30. package/package.json +9 -4
  31. package/src/config/scriptConfig.ts +46 -44
  32. package/src/configParser/configParser.ts +4 -0
  33. package/src/index.ts +12 -4
  34. package/src/interface/assets.ts +12 -12
  35. package/src/interface/runtimeInterface.ts +9 -9
  36. package/src/interface/sceneInterface.ts +5 -3
  37. package/src/parser4/index.ts +158 -0
  38. package/src/sceneParser.ts +47 -47
  39. package/src/scriptParser/argsParser.ts +68 -62
  40. package/src/scriptParser/assetsScanner.ts +72 -72
  41. package/src/scriptParser/commandParser.ts +57 -57
  42. package/src/scriptParser/contentParser.ts +66 -66
  43. package/src/scriptParser/scriptParser.ts +87 -87
  44. package/src/scriptParser/subSceneScanner.ts +23 -23
  45. package/.babelrc +0 -14
  46. package/build/cjs/index.js.map +0 -1
  47. package/build/es/index.js.map +0 -1
  48. package/rollup.config.js +0 -48
  49. package/test/parser.test.ts +0 -130
  50. package/tsconfig.json +0 -29
  51. package/tsconfig.node.json +0 -10
package/package.json CHANGED
@@ -1,18 +1,23 @@
1
1
  {
2
2
  "name": "webgal-parser",
3
- "version": "4.3.13",
3
+ "version": "4.4.3",
4
4
  "description": "WebGAL script parser",
5
5
  "scripts": {
6
6
  "test": "vitest",
7
- "build": "rimraf -rf ./build && rollup --config"
7
+ "coverage": "vitest run --coverage",
8
+ "build": "rimraf -rf ./build && rollup --config",
9
+ "debug": "tsx test/debug.ts"
8
10
  },
11
+ "types": "./build/types/index.d.ts",
9
12
  "module": "./build/es/index.js",
10
13
  "main": "./build/cjs/index.js",
11
14
  "author": "Mahiru <Mahiru_@outlook.com>",
12
15
  "license": "MPL-2.0",
13
16
  "dependencies": {
17
+ "chevrotain": "^10.5.0",
14
18
  "cloudlogjs": "^1.0.11",
15
- "lodash": "^4.17.21"
19
+ "lodash": "^4.17.21",
20
+ "tsx": "^3.12.7"
16
21
  },
17
22
  "devDependencies": {
18
23
  "@rollup/plugin-commonjs": "^23.0.2",
@@ -21,9 +26,9 @@
21
26
  "@rollup/plugin-typescript": "^9.0.2",
22
27
  "@types/lodash": "^4.14.189",
23
28
  "@types/node": "^18.14.0",
29
+ "@vitest/coverage-c8": "^0.28.5",
24
30
  "rollup": "^3.3.0",
25
31
  "rollup-plugin-babel": "^4.4.0",
26
- "rollup-plugin-dts": "^5.0.0",
27
32
  "rollup-plugin-terser": "^7.0.2",
28
33
  "rollup-plugin-typescript2": "^0.34.1",
29
34
  "ts-node": "^10.9.1",
@@ -1,44 +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
- ];
33
- export const ADD_NEXT_ARG_LIST = [
34
- commandType.bgm,
35
- commandType.pixi,
36
- commandType.pixiInit,
37
- commandType.label,
38
- commandType.if,
39
- commandType.miniAvatar,
40
- commandType.setVar,
41
- commandType.unlockBgm,
42
- commandType.unlockCg,
43
- commandType.filmMode,
44
- ];
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
+ ];
@@ -0,0 +1,4 @@
1
+ export function configParser(configText:string){
2
+ // TODO
3
+ return configText
4
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { commandType, IAsset } from "./interface/sceneInterface";
2
- import { fileType } from "./interface/assets";
3
- import { sceneParser } from "./sceneParser";
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";
4
6
 
5
7
  export default class SceneParser {
6
8
 
@@ -11,7 +13,7 @@ export default class SceneParser {
11
13
 
12
14
  constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void),
13
15
  assetSetter: (fileName: string, assetType: fileType) => string,
14
- ADD_NEXT_ARG_LIST: Array<commandType>, SCRIPT_CONFIG: Array<any>) {
16
+ ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>) {
15
17
  this.assetsPrefetcher = assetsPrefetcher;
16
18
  this.assetSetter = assetSetter;
17
19
  this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
@@ -22,4 +24,10 @@ export default class SceneParser {
22
24
  ) {
23
25
  return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
24
26
  }
27
+
28
+ parseConfig(configText: string) {
29
+ return configParser(configText)
30
+ }
25
31
  }
32
+
33
+ export {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG};
@@ -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 { sceneEntry } from "./runtimeInterface";
5
- import { fileType } from "./assets";
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'
@@ -1,47 +1,47 @@
1
- import { IAsset, IScene, ISentence } from "./interface/sceneInterface";
2
- import { scriptParser } from "./scriptParser/scriptParser";
3
- import * as __ from "lodash";
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 { arg } from "../interface/sceneInterface";
2
- import { fileType } from "../interface/assets";
3
- /**
4
- * 参数解析器
5
- * @param argsRaw 原始参数字符串
6
- * @param assetSetter
7
- * @return {Array<arg>} 解析后的参数列表
8
- */
9
- export function argsParser(argsRaw: string, assetSetter: (fileName: string, assetType: fileType) => string): Array<arg> {
10
- const returnArrayList: Array<arg> = [];
11
- // 处理参数
12
- // 不要去空格
13
- let newArgsRaw = argsRaw.replace(/ /g, " ");
14
- // 分割参数列表
15
- let rawArgsList: Array<string> = newArgsRaw.split(" -");
16
- // 去除空字符串
17
- rawArgsList = rawArgsList.filter((e) => {
18
- return e !== "";
19
- });
20
- rawArgsList.forEach((e) => {
21
- const argName = e.split("=")[0];
22
- const argValue = e.split("=")[1];
23
- // 判断是不是语音参数
24
- if (e.match(/.ogg|.mp3|.wav/)) {
25
- returnArrayList.push({
26
- key: "vocal",
27
- value: assetSetter(e, fileType.vocal)
28
- });
29
- } else {
30
- // 判断是不是省略参数
31
- if (argValue === undefined) {
32
- returnArrayList.push({
33
- key: argName,
34
- value: true
35
- });
36
- } else {
37
- // 是字符串描述的布尔值
38
- if (argValue === "true" || argValue === "false") {
39
- returnArrayList.push({
40
- key: argName,
41
- value: argValue === "true"
42
- });
43
- } else {
44
- // 是数字
45
- if (!isNaN(Number(argValue))) {
46
- returnArrayList.push({
47
- key: argName,
48
- value: Number(argValue)
49
- });
50
- } else {
51
- // 是普通参数
52
- returnArrayList.push({
53
- key: argName,
54
- value: argValue
55
- });
56
- }
57
- }
58
- }
59
- }
60
- });
61
- return returnArrayList;
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
+ };