webgal-parser 4.4.5 → 4.4.8

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.
@@ -1,103 +1,104 @@
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
- playEffect,
35
- setTempAnimation,
36
- comment,
37
- setTransform,
38
- setTransition,
39
- }
40
-
41
- /**
42
- * 单个参数接口
43
- * @interface arg
44
- */
45
- export interface arg {
46
- key: string; // 参数键
47
- value: string | boolean | number; // 参数值
48
- }
49
-
50
- /**
51
- * 资源接口
52
- * @interface IAsset
53
- */
54
- export interface IAsset {
55
- name: string; // 资源名称
56
- type: fileType; // 资源类型
57
- url: string; // 资源url
58
- lineNumber: number; // 触发资源语句的行号
59
- }
60
-
61
- /**
62
- * 单条语句接口
63
- * @interface ISentence
64
- */
65
- export interface ISentence {
66
- command: commandType; // 语句类型
67
- commandRaw: string; // 命令的原始内容,方便调试
68
- content: string; // 语句内容
69
- args: Array<arg>; // 参数列表
70
- sentenceAssets: Array<IAsset>; // 语句携带的资源列表
71
- subScene: Array<string>; // 语句包含子场景列表
72
- }
73
-
74
- /**
75
- * 场景接口
76
- * @interface IScene
77
- */
78
- export interface IScene {
79
- sceneName: string; // 场景名称
80
- sceneUrl: string; // 场景url
81
- sentenceList: Array<ISentence>; // 语句列表
82
- assetsList: Array<IAsset>; // 资源列表
83
- subSceneList: Array<string>; // 子场景的url列表
84
- }
85
-
86
- /**
87
- * 当前的场景数据
88
- * @interface ISceneData
89
- */
90
- export interface ISceneData {
91
- currentSentenceId: number; // 当前语句ID
92
- sceneStack: Array<sceneEntry>; // 场景栈
93
- currentScene: IScene; // 当前场景数据
94
- }
95
-
96
- /**
97
- * 处理后的命令接口
98
- * @interface parsedCommand
99
- */
100
- export interface parsedCommand {
101
- type: commandType;
102
- additionalArgs: Array<arg>;
103
- }
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
+ playEffect,
35
+ setTempAnimation,
36
+ comment,
37
+ setTransform,
38
+ setTransition,
39
+ getUserInput
40
+ }
41
+
42
+ /**
43
+ * 单个参数接口
44
+ * @interface arg
45
+ */
46
+ export interface arg {
47
+ key: string; // 参数键
48
+ value: string | boolean | number; // 参数值
49
+ }
50
+
51
+ /**
52
+ * 资源接口
53
+ * @interface IAsset
54
+ */
55
+ export interface IAsset {
56
+ name: string; // 资源名称
57
+ type: fileType; // 资源类型
58
+ url: string; // 资源url
59
+ lineNumber: number; // 触发资源语句的行号
60
+ }
61
+
62
+ /**
63
+ * 单条语句接口
64
+ * @interface ISentence
65
+ */
66
+ export interface ISentence {
67
+ command: commandType; // 语句类型
68
+ commandRaw: string; // 命令的原始内容,方便调试
69
+ content: string; // 语句内容
70
+ args: Array<arg>; // 参数列表
71
+ sentenceAssets: Array<IAsset>; // 语句携带的资源列表
72
+ subScene: Array<string>; // 语句包含子场景列表
73
+ }
74
+
75
+ /**
76
+ * 场景接口
77
+ * @interface IScene
78
+ */
79
+ export interface IScene {
80
+ sceneName: string; // 场景名称
81
+ sceneUrl: string; // 场景url
82
+ sentenceList: Array<ISentence>; // 语句列表
83
+ assetsList: Array<IAsset>; // 资源列表
84
+ subSceneList: Array<string>; // 子场景的url列表
85
+ }
86
+
87
+ /**
88
+ * 当前的场景数据
89
+ * @interface ISceneData
90
+ */
91
+ export interface ISceneData {
92
+ currentSentenceId: number; // 当前语句ID
93
+ sceneStack: Array<sceneEntry>; // 场景栈
94
+ currentScene: IScene; // 当前场景数据
95
+ }
96
+
97
+ /**
98
+ * 处理后的命令接口
99
+ * @interface parsedCommand
100
+ */
101
+ export interface parsedCommand {
102
+ type: commandType;
103
+ additionalArgs: Array<arg>;
104
+ }
@@ -1,158 +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
+ // (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 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
+ };