webgal-parser 4.4.5-fix2 → 4.4.7

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.
@@ -35,6 +35,7 @@ var commandType;
35
35
  commandType[commandType["comment"] = 28] = "comment";
36
36
  commandType[commandType["setTransform"] = 29] = "setTransform";
37
37
  commandType[commandType["setTransition"] = 30] = "setTransition";
38
+ commandType[commandType["getUserInput"] = 31] = "getUserInput";
38
39
  })(commandType || (commandType = {}));
39
40
 
40
41
  /**
@@ -34,7 +34,8 @@ export declare enum commandType {
34
34
  setTempAnimation = 27,
35
35
  comment = 28,
36
36
  setTransform = 29,
37
- setTransition = 30
37
+ setTransition = 30,
38
+ getUserInput = 31
38
39
  }
39
40
  /**
40
41
  * 单个参数接口
package/build/es/index.js CHANGED
@@ -31,6 +31,7 @@ var commandType;
31
31
  commandType[commandType["comment"] = 28] = "comment";
32
32
  commandType[commandType["setTransform"] = 29] = "setTransform";
33
33
  commandType[commandType["setTransition"] = 30] = "setTransition";
34
+ commandType[commandType["getUserInput"] = 31] = "getUserInput";
34
35
  })(commandType || (commandType = {}));
35
36
 
36
37
  /**
@@ -34,7 +34,8 @@ export declare enum commandType {
34
34
  setTempAnimation = 27,
35
35
  comment = 28,
36
36
  setTransform = 29,
37
- setTransition = 30
37
+ setTransition = 30,
38
+ getUserInput = 31
38
39
  }
39
40
  /**
40
41
  * 单个参数接口
@@ -34,7 +34,8 @@ export declare enum commandType {
34
34
  setTempAnimation = 27,
35
35
  comment = 28,
36
36
  setTransform = 29,
37
- setTransition = 30
37
+ setTransition = 30,
38
+ getUserInput = 31
38
39
  }
39
40
  /**
40
41
  * 单个参数接口
@@ -34,6 +34,7 @@ var webgalParser = (function (exports) {
34
34
  commandType[commandType["comment"] = 28] = "comment";
35
35
  commandType[commandType["setTransform"] = 29] = "setTransform";
36
36
  commandType[commandType["setTransition"] = 30] = "setTransition";
37
+ commandType[commandType["getUserInput"] = 31] = "getUserInput";
37
38
  })(commandType || (commandType = {}));
38
39
 
39
40
  /**
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "webgal-parser",
3
- "version": "4.4.5-fix2",
4
- "description": "WebGAL script parser",
5
- "scripts": {
6
- "test": "vitest",
7
- "coverage": "vitest run --coverage",
8
- "build": "rimraf -rf ./build && rollup --config",
9
- "debug": "tsx test/debug.ts"
10
- },
11
- "types": "./build/types/index.d.ts",
12
- "module": "./build/es/index.js",
13
- "main": "./build/cjs/index.js",
14
- "author": "Mahiru <Mahiru_@outlook.com>",
15
- "license": "MPL-2.0",
16
- "dependencies": {
17
- "chevrotain": "^10.5.0",
18
- "cloudlogjs": "^1.0.11",
19
- "lodash": "^4.17.21",
20
- "tsx": "^3.12.7"
21
- },
22
- "devDependencies": {
23
- "@rollup/plugin-commonjs": "^23.0.2",
24
- "@rollup/plugin-json": "^5.0.1",
25
- "@rollup/plugin-node-resolve": "^15.0.1",
26
- "@rollup/plugin-typescript": "^9.0.2",
27
- "@types/lodash": "^4.14.189",
28
- "@types/node": "^18.14.0",
29
- "@vitest/coverage-c8": "^0.28.5",
30
- "rollup": "^3.3.0",
31
- "rollup-plugin-babel": "^4.4.0",
32
- "rollup-plugin-terser": "^7.0.2",
33
- "rollup-plugin-typescript2": "^0.34.1",
34
- "ts-node": "^10.9.1",
35
- "tslib": "^2.4.1",
36
- "typescript": "^4.9.3",
37
- "vitest": "^0.28.5"
38
- },
39
- "type": "module"
40
- }
1
+ {
2
+ "name": "webgal-parser",
3
+ "version": "4.4.7",
4
+ "description": "WebGAL script parser",
5
+ "scripts": {
6
+ "test": "vitest",
7
+ "coverage": "vitest run --coverage",
8
+ "build": "rimraf -rf ./build && rollup --config",
9
+ "debug": "tsx test/debug.ts"
10
+ },
11
+ "types": "./build/types/index.d.ts",
12
+ "module": "./build/es/index.js",
13
+ "main": "./build/cjs/index.js",
14
+ "author": "Mahiru <Mahiru_@outlook.com>",
15
+ "license": "MPL-2.0",
16
+ "dependencies": {
17
+ "chevrotain": "^10.5.0",
18
+ "cloudlogjs": "^1.0.11",
19
+ "lodash": "^4.17.21",
20
+ "tsx": "^3.12.7"
21
+ },
22
+ "devDependencies": {
23
+ "@rollup/plugin-commonjs": "^23.0.2",
24
+ "@rollup/plugin-json": "^5.0.1",
25
+ "@rollup/plugin-node-resolve": "^15.0.1",
26
+ "@rollup/plugin-typescript": "^9.0.2",
27
+ "@types/lodash": "^4.14.189",
28
+ "@types/node": "^18.14.0",
29
+ "@vitest/coverage-c8": "^0.28.5",
30
+ "rollup": "^3.3.0",
31
+ "rollup-plugin-babel": "^4.4.0",
32
+ "rollup-plugin-terser": "^7.0.2",
33
+ "rollup-plugin-typescript2": "^0.34.1",
34
+ "ts-node": "^10.9.1",
35
+ "tslib": "^2.4.1",
36
+ "typescript": "^4.9.3",
37
+ "vitest": "^0.28.5"
38
+ },
39
+ "type": "module"
40
+ }
@@ -1,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
+ ];
@@ -1,60 +1,60 @@
1
- import {argsParser} from "../scriptParser/argsParser";
2
-
3
- interface IOptionItem{
4
- key:string;
5
- value:string | number | boolean;
6
- }
7
- interface IConfigItem{
8
- command:string;
9
- args:string[]
10
- options:IOptionItem[];
11
- }
12
-
13
- export type WebgalConfig = IConfigItem[]
14
-
15
-
16
- function configLineParser(inputLine:string):IConfigItem{
17
- const options:Array<IOptionItem> = [];
18
- let command: string;
19
-
20
- let newSentenceRaw = inputLine.split(";")[0];
21
- if (newSentenceRaw === "") {
22
- // 注释提前返回
23
- return {
24
- command:'',
25
- args:[],
26
- options:[]
27
- };
28
- }
29
- // 截取命令
30
- const getCommandResult = /:/.exec(newSentenceRaw);
31
-
32
- // 没有command
33
- if (getCommandResult === null) {
34
- command = '';
35
- } else {
36
- command = newSentenceRaw.substring(0, getCommandResult.index);
37
- // 划分命令区域和content区域
38
- newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
39
- }
40
- // 截取 Options 区域
41
- const getOptionsResult = / -/.exec(newSentenceRaw);
42
- // 获取到参数
43
- if (getOptionsResult) {
44
- const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
45
- newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
46
- for (const e of argsParser(optionsRaw, (name,_)=>{return name})) {
47
- options.push(e);
48
- }
49
- }
50
- return {
51
- command,
52
- args:newSentenceRaw.split('|').map(e=>e.trim()).filter(e=>e!==''),
53
- options
54
- };
55
- }
56
-
57
- export function configParser(configText:string):WebgalConfig{
58
- const configLines = configText.replaceAll(`\r`,'').split('\n');
59
- return configLines.map(e=>configLineParser(e)).filter(e=>e.command!=='');
60
- }
1
+ import {argsParser} from "../scriptParser/argsParser";
2
+
3
+ interface IOptionItem{
4
+ key:string;
5
+ value:string | number | boolean;
6
+ }
7
+ interface IConfigItem{
8
+ command:string;
9
+ args:string[]
10
+ options:IOptionItem[];
11
+ }
12
+
13
+ export type WebgalConfig = IConfigItem[]
14
+
15
+
16
+ function configLineParser(inputLine:string):IConfigItem{
17
+ const options:Array<IOptionItem> = [];
18
+ let command: string;
19
+
20
+ let newSentenceRaw = inputLine.split(";")[0];
21
+ if (newSentenceRaw === "") {
22
+ // 注释提前返回
23
+ return {
24
+ command:'',
25
+ args:[],
26
+ options:[]
27
+ };
28
+ }
29
+ // 截取命令
30
+ const getCommandResult = /:/.exec(newSentenceRaw);
31
+
32
+ // 没有command
33
+ if (getCommandResult === null) {
34
+ command = '';
35
+ } else {
36
+ command = newSentenceRaw.substring(0, getCommandResult.index);
37
+ // 划分命令区域和content区域
38
+ newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
39
+ }
40
+ // 截取 Options 区域
41
+ const getOptionsResult = / -/.exec(newSentenceRaw);
42
+ // 获取到参数
43
+ if (getOptionsResult) {
44
+ const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
45
+ newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
46
+ for (const e of argsParser(optionsRaw, (name,_)=>{return name})) {
47
+ options.push(e);
48
+ }
49
+ }
50
+ return {
51
+ command,
52
+ args:newSentenceRaw.split('|').map(e=>e.trim()).filter(e=>e!==''),
53
+ options
54
+ };
55
+ }
56
+
57
+ export function configParser(configText:string):WebgalConfig{
58
+ const configLines = configText.replaceAll(`\r`,'').split('\n');
59
+ return configLines.map(e=>configLineParser(e)).filter(e=>e.command!=='');
60
+ }
package/src/index.ts CHANGED
@@ -1,42 +1,42 @@
1
- import {commandType, IAsset} from "./interface/sceneInterface";
2
- import {fileType} from "./interface/assets";
3
- import {sceneParser} from "./sceneParser";
4
- import {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG} from "./config/scriptConfig";
5
- import {configParser, WebgalConfig} from "./configParser/configParser";
6
-
7
- export default class SceneParser {
8
-
9
- private readonly assetsPrefetcher;
10
- private readonly assetSetter;
11
- private readonly ADD_NEXT_ARG_LIST;
12
- private readonly SCRIPT_CONFIG;
13
-
14
- constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void),
15
- assetSetter: (fileName: string, assetType: fileType) => string,
16
- ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>) {
17
- this.assetsPrefetcher = assetsPrefetcher;
18
- this.assetSetter = assetSetter;
19
- this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
20
- this.SCRIPT_CONFIG = SCRIPT_CONFIG;
21
- }
22
-
23
- parse(rawScene: string, sceneName: string, sceneUrl: string
24
- ) {
25
- return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
26
- }
27
-
28
- parseConfig(configText: string) {
29
- return configParser(configText)
30
- }
31
-
32
- stringifyConfig(config: WebgalConfig) {
33
- return config
34
- .reduce(
35
- (previousValue, curr) =>
36
- (previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`),
37
- ''
38
- )
39
- }
40
- }
41
-
42
- export {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG};
1
+ import {commandType, IAsset} from "./interface/sceneInterface";
2
+ import {fileType} from "./interface/assets";
3
+ import {sceneParser} from "./sceneParser";
4
+ import {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG} from "./config/scriptConfig";
5
+ import {configParser, WebgalConfig} from "./configParser/configParser";
6
+
7
+ export default class SceneParser {
8
+
9
+ private readonly assetsPrefetcher;
10
+ private readonly assetSetter;
11
+ private readonly ADD_NEXT_ARG_LIST;
12
+ private readonly SCRIPT_CONFIG;
13
+
14
+ constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void),
15
+ assetSetter: (fileName: string, assetType: fileType) => string,
16
+ ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>) {
17
+ this.assetsPrefetcher = assetsPrefetcher;
18
+ this.assetSetter = assetSetter;
19
+ this.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
20
+ this.SCRIPT_CONFIG = SCRIPT_CONFIG;
21
+ }
22
+
23
+ parse(rawScene: string, sceneName: string, sceneUrl: string
24
+ ) {
25
+ return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
26
+ }
27
+
28
+ parseConfig(configText: string) {
29
+ return configParser(configText)
30
+ }
31
+
32
+ stringifyConfig(config: WebgalConfig) {
33
+ return config
34
+ .reduce(
35
+ (previousValue, curr) =>
36
+ (previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`),
37
+ ''
38
+ )
39
+ }
40
+ }
41
+
42
+ export {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG};
@@ -1,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
+ }