webgal-parser 4.3.2

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/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.SceneParser = void 0;
4
+ var sceneParser_1 = require("./sceneParser");
5
+ var SceneParser = /** @class */ (function () {
6
+ function SceneParser(assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
7
+ this.assetsPrefetcher = assetsPrefetcher;
8
+ this.assetSetter = assetSetter;
9
+ this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
10
+ this.SCRIPT_CONFIG = SCRIPT_CONFIG;
11
+ }
12
+ SceneParser.prototype.parse = function (rawScene, sceneName, sceneUrl) {
13
+ return (0, sceneParser_1.sceneParser)(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
14
+ };
15
+ return SceneParser;
16
+ }());
17
+ exports.SceneParser = SceneParser;
package/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { IAsset } from "./interface/sceneInterface";
2
+ import { fileType } from "./interface/assets";
3
+ import { sceneParser } from "./sceneParser";
4
+
5
+ export class SceneParser {
6
+
7
+ private assetsPrefetcher;
8
+ private assetSetter;
9
+ private ADD_NEXT_ARG_LIST;
10
+ private SCRIPT_CONFIG;
11
+
12
+ constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void),
13
+ assetSetter: (fileName: string, assetType: fileType) => string,
14
+ ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
15
+ this.assetsPrefetcher = assetsPrefetcher;
16
+ this.assetSetter = assetSetter;
17
+ this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
18
+ this.SCRIPT_CONFIG = SCRIPT_CONFIG;
19
+ }
20
+
21
+ parse(rawScene: string, sceneName: string, sceneUrl: string
22
+ ) {
23
+ return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
24
+ }
25
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.fileType = void 0;
4
+ /**
5
+ * 内置资源类型的枚举
6
+ */
7
+ var fileType;
8
+ (function (fileType) {
9
+ fileType[fileType["background"] = 0] = "background";
10
+ fileType[fileType["bgm"] = 1] = "bgm";
11
+ fileType[fileType["figure"] = 2] = "figure";
12
+ fileType[fileType["scene"] = 3] = "scene";
13
+ fileType[fileType["tex"] = 4] = "tex";
14
+ fileType[fileType["vocal"] = 5] = "vocal";
15
+ fileType[fileType["video"] = 6] = "video";
16
+ })(fileType = exports.fileType || (exports.fileType = {}));
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 内置资源类型的枚举
3
+ */
4
+ export enum fileType {
5
+ background,
6
+ bgm,
7
+ figure,
8
+ scene,
9
+ tex,
10
+ vocal,
11
+ video,
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ exports.__esModule = true;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 子场景结束后回到父场景的入口
3
+ * @interface sceneEntry
4
+ */
5
+ export interface sceneEntry {
6
+ sceneName: string; // 场景名称
7
+ sceneUrl: string; // 场景url
8
+ continueLine: number; // 继续原场景的行号
9
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.commandType = void 0;
4
+ var commandType;
5
+ (function (commandType) {
6
+ commandType[commandType["say"] = 0] = "say";
7
+ commandType[commandType["changeBg"] = 1] = "changeBg";
8
+ commandType[commandType["changeFigure"] = 2] = "changeFigure";
9
+ commandType[commandType["bgm"] = 3] = "bgm";
10
+ commandType[commandType["video"] = 4] = "video";
11
+ commandType[commandType["pixi"] = 5] = "pixi";
12
+ commandType[commandType["pixiInit"] = 6] = "pixiInit";
13
+ commandType[commandType["intro"] = 7] = "intro";
14
+ commandType[commandType["miniAvatar"] = 8] = "miniAvatar";
15
+ commandType[commandType["changeScene"] = 9] = "changeScene";
16
+ commandType[commandType["choose"] = 10] = "choose";
17
+ commandType[commandType["end"] = 11] = "end";
18
+ commandType[commandType["setComplexAnimation"] = 12] = "setComplexAnimation";
19
+ commandType[commandType["setFilter"] = 13] = "setFilter";
20
+ commandType[commandType["label"] = 14] = "label";
21
+ commandType[commandType["jumpLabel"] = 15] = "jumpLabel";
22
+ commandType[commandType["chooseLabel"] = 16] = "chooseLabel";
23
+ commandType[commandType["setVar"] = 17] = "setVar";
24
+ commandType[commandType["if"] = 18] = "if";
25
+ commandType[commandType["callScene"] = 19] = "callScene";
26
+ commandType[commandType["showVars"] = 20] = "showVars";
27
+ commandType[commandType["unlockCg"] = 21] = "unlockCg";
28
+ commandType[commandType["unlockBgm"] = 22] = "unlockBgm";
29
+ commandType[commandType["filmMode"] = 23] = "filmMode";
30
+ commandType[commandType["setTextbox"] = 24] = "setTextbox";
31
+ commandType[commandType["setAnimation"] = 25] = "setAnimation";
32
+ })(commandType = exports.commandType || (exports.commandType = {}));
@@ -0,0 +1,98 @@
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
+ }
35
+
36
+ /**
37
+ * 单个参数接口
38
+ * @interface arg
39
+ */
40
+ export interface arg {
41
+ key: string; // 参数键
42
+ value: string | boolean | number; // 参数值
43
+ }
44
+
45
+ /**
46
+ * 资源接口
47
+ * @interface IAsset
48
+ */
49
+ export interface IAsset {
50
+ name: string; // 资源名称
51
+ type: fileType; // 资源类型
52
+ url: string; // 资源url
53
+ lineNumber: number; // 触发资源语句的行号
54
+ }
55
+
56
+ /**
57
+ * 单条语句接口
58
+ * @interface ISentence
59
+ */
60
+ export interface ISentence {
61
+ command: commandType; // 语句类型
62
+ commandRaw: string; // 命令的原始内容,方便调试
63
+ content: string; // 语句内容
64
+ args: Array<arg>; // 参数列表
65
+ sentenceAssets: Array<IAsset>; // 语句携带的资源列表
66
+ subScene: Array<string>; // 语句包含子场景列表
67
+ }
68
+
69
+ /**
70
+ * 场景接口
71
+ * @interface IScene
72
+ */
73
+ export interface IScene {
74
+ sceneName: string; // 场景名称
75
+ sceneUrl: string; // 场景url
76
+ sentenceList: Array<ISentence>; // 语句列表
77
+ assetsList: Array<IAsset>; // 资源列表
78
+ subSceneList: Array<string>; // 子场景的url列表
79
+ }
80
+
81
+ /**
82
+ * 当前的场景数据
83
+ * @interface ISceneData
84
+ */
85
+ export interface ISceneData {
86
+ currentSentenceId: number; // 当前语句ID
87
+ sceneStack: Array<sceneEntry>; // 场景栈
88
+ currentScene: IScene; // 当前场景数据
89
+ }
90
+
91
+ /**
92
+ * 处理后的命令接口
93
+ * @interface parsedCommand
94
+ */
95
+ export interface parsedCommand {
96
+ type: commandType;
97
+ additionalArgs: Array<arg>;
98
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "webgal-parser",
3
+ "version": "4.3.2",
4
+ "description": "WebGAL script parser",
5
+ "scripts": {
6
+ "test": "node test/test.js"
7
+ },
8
+ "main": "index.js",
9
+ "author": "Mahiru <Mahiru_@outlook.com>",
10
+ "license": "MPL-2.0",
11
+ "dependencies": {
12
+ "cloudlogjs": "^1.0.11",
13
+ "lodash": "^4.17.21"
14
+ },
15
+ "devDependencies": {
16
+ "@types/lodash": "^4.14.189",
17
+ "ts-node": "^10.9.1"
18
+ }
19
+ }
package/sceneParser.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ exports.__esModule = true;
12
+ exports.sceneParser = void 0;
13
+ var scriptParser_1 = require("./scriptParser/scriptParser");
14
+ var __ = require("lodash");
15
+ /**
16
+ * 场景解析器
17
+ * @param rawScene 原始场景
18
+ * @param sceneName 场景名称
19
+ * @param sceneUrl 场景url
20
+ * @param assetsPrefetcher
21
+ * @param assetSetter
22
+ * @param ADD_NEXT_ARG_LIST
23
+ * @param SCRIPT_CONFIG
24
+ * @return {IScene} 解析后的场景
25
+ */
26
+ var sceneParser = function (rawScene, sceneName, sceneUrl, assetsPrefetcher, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
27
+ var rawSentenceList = rawScene.split("\n"); // 原始句子列表
28
+ // 去除冒号后的内容
29
+ // 去除分号后的内容
30
+ var rawSentenceListWithoutEmpty = rawSentenceList
31
+ .map(function (sentence) { return sentence.split(";")[0]; })
32
+ .filter(function (sentence) { return sentence.trim() !== ""; });
33
+ var assetsList = []; // 场景资源列表
34
+ var subSceneList = []; // 子场景列表
35
+ var sentenceList = rawSentenceListWithoutEmpty.map(function (sentence) {
36
+ var returnSentence = (0, scriptParser_1.scriptParser)(sentence, assetSetter, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
37
+ // 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
38
+ assetsList = __spreadArray(__spreadArray([], assetsList, true), returnSentence.sentenceAssets, true);
39
+ subSceneList = __spreadArray(__spreadArray([], subSceneList, true), returnSentence.subScene, true);
40
+ return returnSentence;
41
+ });
42
+ // 开始资源的预加载
43
+ assetsList = __.uniqWith(assetsList); // 去重
44
+ assetsPrefetcher(assetsList);
45
+ return {
46
+ sceneName: sceneName,
47
+ sceneUrl: sceneUrl,
48
+ sentenceList: sentenceList,
49
+ assetsList: assetsList,
50
+ subSceneList: subSceneList // 子场景列表
51
+ };
52
+ };
53
+ exports.sceneParser = sceneParser;
package/sceneParser.ts ADDED
@@ -0,0 +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, SCRIPT_CONFIG): 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
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.argsParser = void 0;
4
+ var assets_1 = require("../interface/assets");
5
+ /**
6
+ * 参数解析器
7
+ * @param argsRaw 原始参数字符串
8
+ * @param assetSetter
9
+ * @return {Array<arg>} 解析后的参数列表
10
+ */
11
+ function argsParser(argsRaw, assetSetter) {
12
+ var returnArrayList = [];
13
+ // 处理参数
14
+ // 不要去空格
15
+ var newArgsRaw = argsRaw.replace(/ /g, " ");
16
+ // 分割参数列表
17
+ var rawArgsList = newArgsRaw.split(" -");
18
+ // 去除空字符串
19
+ rawArgsList = rawArgsList.filter(function (e) {
20
+ return e !== "";
21
+ });
22
+ rawArgsList.forEach(function (e) {
23
+ var argName = e.split("=")[0];
24
+ var argValue = e.split("=")[1];
25
+ // 判断是不是语音参数
26
+ if (e.match(/.ogg|.mp3|.wav/)) {
27
+ returnArrayList.push({
28
+ key: "vocal",
29
+ value: assetSetter(e, assets_1.fileType.vocal)
30
+ });
31
+ }
32
+ else {
33
+ // 判断是不是省略参数
34
+ if (argValue === undefined) {
35
+ returnArrayList.push({
36
+ key: argName,
37
+ value: true
38
+ });
39
+ }
40
+ else {
41
+ // 是字符串描述的布尔值
42
+ if (argValue === "true" || argValue === "false") {
43
+ returnArrayList.push({
44
+ key: argName,
45
+ value: argValue === "true"
46
+ });
47
+ }
48
+ else {
49
+ // 是数字
50
+ if (!isNaN(Number(argValue))) {
51
+ returnArrayList.push({
52
+ key: argName,
53
+ value: Number(argValue)
54
+ });
55
+ }
56
+ else {
57
+ // 是普通参数
58
+ returnArrayList.push({
59
+ key: argName,
60
+ value: argValue
61
+ });
62
+ }
63
+ }
64
+ }
65
+ }
66
+ });
67
+ return returnArrayList;
68
+ }
69
+ exports.argsParser = argsParser;
70
+ ;
@@ -0,0 +1,62 @@
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
+ };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.assetsScanner = void 0;
4
+ var sceneInterface_1 = require("../interface/sceneInterface");
5
+ var assets_1 = require("../interface/assets");
6
+ /**
7
+ * 根据语句类型、语句内容、参数列表,扫描该语句可能携带的资源
8
+ * @param command 语句类型
9
+ * @param content 语句内容
10
+ * @param args 参数列表
11
+ * @return {Array<IAsset>} 语句携带的参数列表
12
+ */
13
+ var assetsScanner = function (command, content, args) {
14
+ var hasVocalArg = false;
15
+ var returnAssetsList = [];
16
+ if (command === sceneInterface_1.commandType.say) {
17
+ args.forEach(function (e) {
18
+ if (e.key === 'vocal') {
19
+ hasVocalArg = true;
20
+ returnAssetsList.push({
21
+ name: e.value,
22
+ url: e.value,
23
+ lineNumber: 0,
24
+ type: assets_1.fileType.vocal
25
+ });
26
+ }
27
+ });
28
+ }
29
+ if (content === 'none' || content === '') {
30
+ return returnAssetsList;
31
+ }
32
+ // 处理语句携带的资源
33
+ if (command === sceneInterface_1.commandType.changeBg) {
34
+ returnAssetsList.push({
35
+ name: content,
36
+ url: content,
37
+ lineNumber: 0,
38
+ type: assets_1.fileType.background
39
+ });
40
+ }
41
+ if (command === sceneInterface_1.commandType.changeFigure) {
42
+ returnAssetsList.push({
43
+ name: content,
44
+ url: content,
45
+ lineNumber: 0,
46
+ type: assets_1.fileType.figure
47
+ });
48
+ }
49
+ if (command === sceneInterface_1.commandType.miniAvatar) {
50
+ returnAssetsList.push({
51
+ name: content,
52
+ url: content,
53
+ lineNumber: 0,
54
+ type: assets_1.fileType.figure
55
+ });
56
+ }
57
+ if (command === sceneInterface_1.commandType.video) {
58
+ returnAssetsList.push({
59
+ name: content,
60
+ url: content,
61
+ lineNumber: 0,
62
+ type: assets_1.fileType.video
63
+ });
64
+ }
65
+ if (command === sceneInterface_1.commandType.bgm) {
66
+ returnAssetsList.push({
67
+ name: content,
68
+ url: content,
69
+ lineNumber: 0,
70
+ type: assets_1.fileType.bgm
71
+ });
72
+ }
73
+ return returnAssetsList;
74
+ };
75
+ exports.assetsScanner = assetsScanner;
@@ -0,0 +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
+ };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.commandParser = void 0;
4
+ var sceneInterface_1 = require("../interface/sceneInterface");
5
+ /**
6
+ * 处理命令
7
+ * @param commandRaw
8
+ * @param ADD_NEXT_ARG_LIST
9
+ * @param SCRIPT_CONFIG
10
+ * @return {parsedCommand} 处理后的命令
11
+ */
12
+ var commandParser = function (commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
13
+ var returnCommand = {
14
+ type: sceneInterface_1.commandType.say,
15
+ additionalArgs: []
16
+ };
17
+ // 开始处理命令内容
18
+ var type = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
19
+ returnCommand.type = type;
20
+ // 如果是对话,加上额外的参数
21
+ if (type === sceneInterface_1.commandType.say) {
22
+ returnCommand.additionalArgs.push({
23
+ key: "speaker",
24
+ value: commandRaw
25
+ });
26
+ }
27
+ returnCommand = addNextArg(returnCommand, type, ADD_NEXT_ARG_LIST);
28
+ return returnCommand;
29
+ };
30
+ exports.commandParser = commandParser;
31
+ /**
32
+ * 根据command原始值判断是什么命令
33
+ * @param command command原始值
34
+ * @param ADD_NEXT_ARG_LIST
35
+ * @param SCRIPT_CONFIG
36
+ * @return {commandType} 得到的command类型
37
+ */
38
+ function getCommandType(command, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) {
39
+ // if (command.match(/if/)) {
40
+ // return commandType.if;
41
+ // }
42
+ var commandMap = new Map();
43
+ SCRIPT_CONFIG.forEach(function (e) {
44
+ commandMap.set(e.scriptString, e.scriptType);
45
+ });
46
+ if (commandMap.has(command)) {
47
+ return commandMap.get(command);
48
+ }
49
+ else
50
+ return sceneInterface_1.commandType.say;
51
+ }
52
+ function addNextArg(commandToParse, thisCommandType, ADD_NEXT_ARG_LIST) {
53
+ if (ADD_NEXT_ARG_LIST.includes(thisCommandType)) {
54
+ commandToParse.additionalArgs.push({
55
+ key: "next",
56
+ value: true
57
+ });
58
+ }
59
+ return commandToParse;
60
+ }