webgal-parser 4.3.13 → 4.4.4
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/config/scriptConfig.d.ts +1 -1
- package/build/cjs/configParser/configParser.d.ts +1 -0
- package/build/cjs/index.d.ts +5 -2
- package/build/cjs/index.js +1148 -17042
- package/build/cjs/interface/sceneInterface.d.ts +3 -1
- package/build/cjs/parser4/index.d.ts +1 -0
- package/build/cjs/scriptParser/subSceneScanner.d.ts +1 -1
- package/build/es/config/scriptConfig.d.ts +1 -1
- package/build/es/configParser/configParser.d.ts +1 -0
- package/build/es/index.d.ts +5 -2
- package/build/es/index.js +1147 -17043
- package/build/es/interface/sceneInterface.d.ts +3 -1
- package/build/es/parser4/index.d.ts +1 -0
- package/build/es/scriptParser/subSceneScanner.d.ts +1 -1
- 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 +40 -35
- package/src/config/scriptConfig.ts +46 -44
- package/src/configParser/configParser.ts +60 -0
- package/src/index.ts +42 -25
- package/src/interface/assets.ts +12 -12
- package/src/interface/runtimeInterface.ts +9 -9
- package/src/interface/sceneInterface.ts +103 -101
- 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/.babelrc +0 -14
- package/build/cjs/index.js.map +0 -1
- package/build/es/index.js.map +0 -1
- package/rollup.config.js +0 -48
- package/test/parser.test.ts +0 -130
- package/tsconfig.json +0 -29
- package/tsconfig.node.json +0 -10
|
@@ -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
|
|
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
|
-
|
|
25
|
-
|
|
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 =
|
|
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
|
+
};
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { arg, commandType, IAsset } from '../interface/sceneInterface';
|
|
2
|
-
import { fileType } from '../interface/assets';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 根据语句类型、语句内容、参数列表,扫描该语句可能携带的资源
|
|
6
|
-
* @param command 语句类型
|
|
7
|
-
* @param content 语句内容
|
|
8
|
-
* @param args 参数列表
|
|
9
|
-
* @return {Array<IAsset>} 语句携带的参数列表
|
|
10
|
-
*/
|
|
11
|
-
export const assetsScanner = (command: commandType, content: string, args: Array<arg>): Array<IAsset> => {
|
|
12
|
-
let hasVocalArg = false;
|
|
13
|
-
const returnAssetsList: Array<IAsset> = [];
|
|
14
|
-
if (command === commandType.say) {
|
|
15
|
-
args.forEach((e) => {
|
|
16
|
-
if (e.key === 'vocal') {
|
|
17
|
-
hasVocalArg = true;
|
|
18
|
-
returnAssetsList.push({
|
|
19
|
-
name: e.value as string,
|
|
20
|
-
url: e.value as string,
|
|
21
|
-
lineNumber: 0,
|
|
22
|
-
type: fileType.vocal,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
if (content === 'none' || content === '') {
|
|
28
|
-
return returnAssetsList;
|
|
29
|
-
}
|
|
30
|
-
// 处理语句携带的资源
|
|
31
|
-
if (command === commandType.changeBg) {
|
|
32
|
-
returnAssetsList.push({
|
|
33
|
-
name: content,
|
|
34
|
-
url: content,
|
|
35
|
-
lineNumber: 0,
|
|
36
|
-
type: fileType.background,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
if (command === commandType.changeFigure) {
|
|
40
|
-
returnAssetsList.push({
|
|
41
|
-
name: content,
|
|
42
|
-
url: content,
|
|
43
|
-
lineNumber: 0,
|
|
44
|
-
type: fileType.figure,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
if (command === commandType.miniAvatar) {
|
|
48
|
-
returnAssetsList.push({
|
|
49
|
-
name: content,
|
|
50
|
-
url: content,
|
|
51
|
-
lineNumber: 0,
|
|
52
|
-
type: fileType.figure,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
if (command === commandType.video) {
|
|
56
|
-
returnAssetsList.push({
|
|
57
|
-
name: content,
|
|
58
|
-
url: content,
|
|
59
|
-
lineNumber: 0,
|
|
60
|
-
type: fileType.video,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (command === commandType.bgm) {
|
|
64
|
-
returnAssetsList.push({
|
|
65
|
-
name: content,
|
|
66
|
-
url: content,
|
|
67
|
-
lineNumber: 0,
|
|
68
|
-
type: fileType.bgm,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return returnAssetsList;
|
|
72
|
-
};
|
|
1
|
+
import { arg, commandType, IAsset } from '../interface/sceneInterface';
|
|
2
|
+
import { fileType } from '../interface/assets';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 根据语句类型、语句内容、参数列表,扫描该语句可能携带的资源
|
|
6
|
+
* @param command 语句类型
|
|
7
|
+
* @param content 语句内容
|
|
8
|
+
* @param args 参数列表
|
|
9
|
+
* @return {Array<IAsset>} 语句携带的参数列表
|
|
10
|
+
*/
|
|
11
|
+
export const assetsScanner = (command: commandType, content: string, args: Array<arg>): Array<IAsset> => {
|
|
12
|
+
let hasVocalArg = false;
|
|
13
|
+
const returnAssetsList: Array<IAsset> = [];
|
|
14
|
+
if (command === commandType.say) {
|
|
15
|
+
args.forEach((e) => {
|
|
16
|
+
if (e.key === 'vocal') {
|
|
17
|
+
hasVocalArg = true;
|
|
18
|
+
returnAssetsList.push({
|
|
19
|
+
name: e.value as string,
|
|
20
|
+
url: e.value as string,
|
|
21
|
+
lineNumber: 0,
|
|
22
|
+
type: fileType.vocal,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (content === 'none' || content === '') {
|
|
28
|
+
return returnAssetsList;
|
|
29
|
+
}
|
|
30
|
+
// 处理语句携带的资源
|
|
31
|
+
if (command === commandType.changeBg) {
|
|
32
|
+
returnAssetsList.push({
|
|
33
|
+
name: content,
|
|
34
|
+
url: content,
|
|
35
|
+
lineNumber: 0,
|
|
36
|
+
type: fileType.background,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (command === commandType.changeFigure) {
|
|
40
|
+
returnAssetsList.push({
|
|
41
|
+
name: content,
|
|
42
|
+
url: content,
|
|
43
|
+
lineNumber: 0,
|
|
44
|
+
type: fileType.figure,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (command === commandType.miniAvatar) {
|
|
48
|
+
returnAssetsList.push({
|
|
49
|
+
name: content,
|
|
50
|
+
url: content,
|
|
51
|
+
lineNumber: 0,
|
|
52
|
+
type: fileType.figure,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (command === commandType.video) {
|
|
56
|
+
returnAssetsList.push({
|
|
57
|
+
name: content,
|
|
58
|
+
url: content,
|
|
59
|
+
lineNumber: 0,
|
|
60
|
+
type: fileType.video,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (command === commandType.bgm) {
|
|
64
|
+
returnAssetsList.push({
|
|
65
|
+
name: content,
|
|
66
|
+
url: content,
|
|
67
|
+
lineNumber: 0,
|
|
68
|
+
type: fileType.bgm,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return returnAssetsList;
|
|
72
|
+
};
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { commandType, parsedCommand } from "../interface/sceneInterface";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 处理命令
|
|
5
|
-
* @param commandRaw
|
|
6
|
-
* @param ADD_NEXT_ARG_LIST
|
|
7
|
-
* @param SCRIPT_CONFIG
|
|
8
|
-
* @return {parsedCommand} 处理后的命令
|
|
9
|
-
*/
|
|
10
|
-
export const commandParser = (commandRaw: string, ADD_NEXT_ARG_LIST:any, SCRIPT_CONFIG:any): parsedCommand => {
|
|
11
|
-
let returnCommand: parsedCommand = {
|
|
12
|
-
type: commandType.say, // 默认是say
|
|
13
|
-
additionalArgs: []
|
|
14
|
-
};
|
|
15
|
-
// 开始处理命令内容
|
|
16
|
-
const type: commandType = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
17
|
-
returnCommand.type = type;
|
|
18
|
-
// 如果是对话,加上额外的参数
|
|
19
|
-
if (type === commandType.say) {
|
|
20
|
-
returnCommand.additionalArgs.push({
|
|
21
|
-
key: "speaker",
|
|
22
|
-
value: commandRaw
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
returnCommand = addNextArg(returnCommand, type, ADD_NEXT_ARG_LIST);
|
|
26
|
-
return returnCommand;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 根据command原始值判断是什么命令
|
|
31
|
-
* @param command command原始值
|
|
32
|
-
* @param ADD_NEXT_ARG_LIST
|
|
33
|
-
* @param SCRIPT_CONFIG
|
|
34
|
-
* @return {commandType} 得到的command类型
|
|
35
|
-
*/
|
|
36
|
-
function getCommandType(command: string, ADD_NEXT_ARG_LIST:any, SCRIPT_CONFIG:any): commandType {
|
|
37
|
-
// if (command.match(/if/)) {
|
|
38
|
-
// return commandType.if;
|
|
39
|
-
// }
|
|
40
|
-
const commandMap = new Map();
|
|
41
|
-
SCRIPT_CONFIG.forEach((e:any) => {
|
|
42
|
-
commandMap.set(e.scriptString, e.scriptType);
|
|
43
|
-
});
|
|
44
|
-
if (commandMap.has(command)) {
|
|
45
|
-
return commandMap.get(command);
|
|
46
|
-
} else return commandType.say;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function addNextArg(commandToParse: parsedCommand, thisCommandType: commandType, ADD_NEXT_ARG_LIST:any) {
|
|
50
|
-
if (ADD_NEXT_ARG_LIST.includes(thisCommandType)) {
|
|
51
|
-
commandToParse.additionalArgs.push({
|
|
52
|
-
key: "next",
|
|
53
|
-
value: true
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return commandToParse;
|
|
57
|
-
}
|
|
1
|
+
import { commandType, parsedCommand } from "../interface/sceneInterface";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 处理命令
|
|
5
|
+
* @param commandRaw
|
|
6
|
+
* @param ADD_NEXT_ARG_LIST
|
|
7
|
+
* @param SCRIPT_CONFIG
|
|
8
|
+
* @return {parsedCommand} 处理后的命令
|
|
9
|
+
*/
|
|
10
|
+
export const commandParser = (commandRaw: string, ADD_NEXT_ARG_LIST:any, SCRIPT_CONFIG:any): parsedCommand => {
|
|
11
|
+
let returnCommand: parsedCommand = {
|
|
12
|
+
type: commandType.say, // 默认是say
|
|
13
|
+
additionalArgs: []
|
|
14
|
+
};
|
|
15
|
+
// 开始处理命令内容
|
|
16
|
+
const type: commandType = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
17
|
+
returnCommand.type = type;
|
|
18
|
+
// 如果是对话,加上额外的参数
|
|
19
|
+
if (type === commandType.say) {
|
|
20
|
+
returnCommand.additionalArgs.push({
|
|
21
|
+
key: "speaker",
|
|
22
|
+
value: commandRaw
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
returnCommand = addNextArg(returnCommand, type, ADD_NEXT_ARG_LIST);
|
|
26
|
+
return returnCommand;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 根据command原始值判断是什么命令
|
|
31
|
+
* @param command command原始值
|
|
32
|
+
* @param ADD_NEXT_ARG_LIST
|
|
33
|
+
* @param SCRIPT_CONFIG
|
|
34
|
+
* @return {commandType} 得到的command类型
|
|
35
|
+
*/
|
|
36
|
+
function getCommandType(command: string, ADD_NEXT_ARG_LIST:any, SCRIPT_CONFIG:any): commandType {
|
|
37
|
+
// if (command.match(/if/)) {
|
|
38
|
+
// return commandType.if;
|
|
39
|
+
// }
|
|
40
|
+
const commandMap = new Map();
|
|
41
|
+
SCRIPT_CONFIG.forEach((e:any) => {
|
|
42
|
+
commandMap.set(e.scriptString, e.scriptType);
|
|
43
|
+
});
|
|
44
|
+
if (commandMap.has(command)) {
|
|
45
|
+
return commandMap.get(command);
|
|
46
|
+
} else return commandType.say;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function addNextArg(commandToParse: parsedCommand, thisCommandType: commandType, ADD_NEXT_ARG_LIST:any) {
|
|
50
|
+
if (ADD_NEXT_ARG_LIST.includes(thisCommandType)) {
|
|
51
|
+
commandToParse.additionalArgs.push({
|
|
52
|
+
key: "next",
|
|
53
|
+
value: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return commandToParse;
|
|
57
|
+
}
|