webgal-parser 4.4.4 → 4.4.5-fix2
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/configParser/configParser.d.ts +12 -1
- package/build/cjs/index.d.ts +3 -1
- package/build/cjs/index.js +47 -4
- package/build/es/configParser/configParser.d.ts +12 -1
- package/build/es/index.d.ts +3 -1
- package/build/es/index.js +47 -4
- package/build/types/configParser/configParser.d.ts +12 -1
- package/build/types/index.d.ts +3 -1
- package/build/umd/index.global.js +47 -4
- package/package.json +1 -1
- package/src/scriptParser/argsParser.ts +1 -1
- package/src/scriptParser/commandParser.ts +1 -1
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
interface IOptionItem {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string | number | boolean;
|
|
4
|
+
}
|
|
5
|
+
interface IConfigItem {
|
|
6
|
+
command: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
options: IOptionItem[];
|
|
9
|
+
}
|
|
10
|
+
export type WebgalConfig = IConfigItem[];
|
|
11
|
+
export declare function configParser(configText: string): WebgalConfig;
|
|
12
|
+
export {};
|
package/build/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAsset } from "./interface/sceneInterface";
|
|
2
2
|
import { fileType } from "./interface/assets";
|
|
3
3
|
import { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG } from "./config/scriptConfig";
|
|
4
|
+
import { WebgalConfig } from "./configParser/configParser";
|
|
4
5
|
export default class SceneParser {
|
|
5
6
|
private readonly assetsPrefetcher;
|
|
6
7
|
private readonly assetSetter;
|
|
@@ -8,6 +9,7 @@ export default class SceneParser {
|
|
|
8
9
|
private readonly SCRIPT_CONFIG;
|
|
9
10
|
constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void), assetSetter: (fileName: string, assetType: fileType) => string, ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>);
|
|
10
11
|
parse(rawScene: string, sceneName: string, sceneUrl: string): import("./interface/sceneInterface").IScene;
|
|
11
|
-
parseConfig(configText: string):
|
|
12
|
+
parseConfig(configText: string): WebgalConfig;
|
|
13
|
+
stringifyConfig(config: WebgalConfig): string;
|
|
12
14
|
}
|
|
13
15
|
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
|
package/build/cjs/index.js
CHANGED
|
@@ -53,7 +53,7 @@ const commandParser = (commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
|
|
|
53
53
|
const type = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
54
54
|
returnCommand.type = type;
|
|
55
55
|
// 如果是对话,加上额外的参数
|
|
56
|
-
if (type === commandType.say) {
|
|
56
|
+
if (type === commandType.say && commandRaw !== 'say') {
|
|
57
57
|
returnCommand.additionalArgs.push({
|
|
58
58
|
key: "speaker",
|
|
59
59
|
value: commandRaw
|
|
@@ -133,7 +133,7 @@ function argsParser(argsRaw, assetSetter) {
|
|
|
133
133
|
argValue = undefined;
|
|
134
134
|
}
|
|
135
135
|
// 判断是不是语音参数
|
|
136
|
-
if (
|
|
136
|
+
if (argName.match(/.ogg|.mp3|.wav/)) {
|
|
137
137
|
returnArrayList.push({
|
|
138
138
|
key: "vocal",
|
|
139
139
|
value: assetSetter(e, fileType.vocal)
|
|
@@ -1742,9 +1742,48 @@ const ADD_NEXT_ARG_LIST = [
|
|
|
1742
1742
|
commandType.playEffect,
|
|
1743
1743
|
];
|
|
1744
1744
|
|
|
1745
|
+
function configLineParser(inputLine) {
|
|
1746
|
+
const options = [];
|
|
1747
|
+
let command;
|
|
1748
|
+
let newSentenceRaw = inputLine.split(";")[0];
|
|
1749
|
+
if (newSentenceRaw === "") {
|
|
1750
|
+
// 注释提前返回
|
|
1751
|
+
return {
|
|
1752
|
+
command: '',
|
|
1753
|
+
args: [],
|
|
1754
|
+
options: []
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
// 截取命令
|
|
1758
|
+
const getCommandResult = /:/.exec(newSentenceRaw);
|
|
1759
|
+
// 没有command
|
|
1760
|
+
if (getCommandResult === null) {
|
|
1761
|
+
command = '';
|
|
1762
|
+
}
|
|
1763
|
+
else {
|
|
1764
|
+
command = newSentenceRaw.substring(0, getCommandResult.index);
|
|
1765
|
+
// 划分命令区域和content区域
|
|
1766
|
+
newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
|
|
1767
|
+
}
|
|
1768
|
+
// 截取 Options 区域
|
|
1769
|
+
const getOptionsResult = / -/.exec(newSentenceRaw);
|
|
1770
|
+
// 获取到参数
|
|
1771
|
+
if (getOptionsResult) {
|
|
1772
|
+
const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
|
|
1773
|
+
newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
|
|
1774
|
+
for (const e of argsParser(optionsRaw, (name, _) => { return name; })) {
|
|
1775
|
+
options.push(e);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
return {
|
|
1779
|
+
command,
|
|
1780
|
+
args: newSentenceRaw.split('|').map(e => e.trim()).filter(e => e !== ''),
|
|
1781
|
+
options
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1745
1784
|
function configParser(configText) {
|
|
1746
|
-
|
|
1747
|
-
return
|
|
1785
|
+
const configLines = configText.replaceAll(`\r`, '').split('\n');
|
|
1786
|
+
return configLines.map(e => configLineParser(e)).filter(e => e.command !== '');
|
|
1748
1787
|
}
|
|
1749
1788
|
|
|
1750
1789
|
class SceneParser {
|
|
@@ -1764,6 +1803,10 @@ class SceneParser {
|
|
|
1764
1803
|
parseConfig(configText) {
|
|
1765
1804
|
return configParser(configText);
|
|
1766
1805
|
}
|
|
1806
|
+
stringifyConfig(config) {
|
|
1807
|
+
return config
|
|
1808
|
+
.reduce((previousValue, curr) => (previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`), '');
|
|
1809
|
+
}
|
|
1767
1810
|
}
|
|
1768
1811
|
|
|
1769
1812
|
exports.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
interface IOptionItem {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string | number | boolean;
|
|
4
|
+
}
|
|
5
|
+
interface IConfigItem {
|
|
6
|
+
command: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
options: IOptionItem[];
|
|
9
|
+
}
|
|
10
|
+
export type WebgalConfig = IConfigItem[];
|
|
11
|
+
export declare function configParser(configText: string): WebgalConfig;
|
|
12
|
+
export {};
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAsset } from "./interface/sceneInterface";
|
|
2
2
|
import { fileType } from "./interface/assets";
|
|
3
3
|
import { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG } from "./config/scriptConfig";
|
|
4
|
+
import { WebgalConfig } from "./configParser/configParser";
|
|
4
5
|
export default class SceneParser {
|
|
5
6
|
private readonly assetsPrefetcher;
|
|
6
7
|
private readonly assetSetter;
|
|
@@ -8,6 +9,7 @@ export default class SceneParser {
|
|
|
8
9
|
private readonly SCRIPT_CONFIG;
|
|
9
10
|
constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void), assetSetter: (fileName: string, assetType: fileType) => string, ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>);
|
|
10
11
|
parse(rawScene: string, sceneName: string, sceneUrl: string): import("./interface/sceneInterface").IScene;
|
|
11
|
-
parseConfig(configText: string):
|
|
12
|
+
parseConfig(configText: string): WebgalConfig;
|
|
13
|
+
stringifyConfig(config: WebgalConfig): string;
|
|
12
14
|
}
|
|
13
15
|
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
|
package/build/es/index.js
CHANGED
|
@@ -49,7 +49,7 @@ const commandParser = (commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG) => {
|
|
|
49
49
|
const type = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
50
50
|
returnCommand.type = type;
|
|
51
51
|
// 如果是对话,加上额外的参数
|
|
52
|
-
if (type === commandType.say) {
|
|
52
|
+
if (type === commandType.say && commandRaw !== 'say') {
|
|
53
53
|
returnCommand.additionalArgs.push({
|
|
54
54
|
key: "speaker",
|
|
55
55
|
value: commandRaw
|
|
@@ -129,7 +129,7 @@ function argsParser(argsRaw, assetSetter) {
|
|
|
129
129
|
argValue = undefined;
|
|
130
130
|
}
|
|
131
131
|
// 判断是不是语音参数
|
|
132
|
-
if (
|
|
132
|
+
if (argName.match(/.ogg|.mp3|.wav/)) {
|
|
133
133
|
returnArrayList.push({
|
|
134
134
|
key: "vocal",
|
|
135
135
|
value: assetSetter(e, fileType.vocal)
|
|
@@ -1738,9 +1738,48 @@ const ADD_NEXT_ARG_LIST = [
|
|
|
1738
1738
|
commandType.playEffect,
|
|
1739
1739
|
];
|
|
1740
1740
|
|
|
1741
|
+
function configLineParser(inputLine) {
|
|
1742
|
+
const options = [];
|
|
1743
|
+
let command;
|
|
1744
|
+
let newSentenceRaw = inputLine.split(";")[0];
|
|
1745
|
+
if (newSentenceRaw === "") {
|
|
1746
|
+
// 注释提前返回
|
|
1747
|
+
return {
|
|
1748
|
+
command: '',
|
|
1749
|
+
args: [],
|
|
1750
|
+
options: []
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
// 截取命令
|
|
1754
|
+
const getCommandResult = /:/.exec(newSentenceRaw);
|
|
1755
|
+
// 没有command
|
|
1756
|
+
if (getCommandResult === null) {
|
|
1757
|
+
command = '';
|
|
1758
|
+
}
|
|
1759
|
+
else {
|
|
1760
|
+
command = newSentenceRaw.substring(0, getCommandResult.index);
|
|
1761
|
+
// 划分命令区域和content区域
|
|
1762
|
+
newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
|
|
1763
|
+
}
|
|
1764
|
+
// 截取 Options 区域
|
|
1765
|
+
const getOptionsResult = / -/.exec(newSentenceRaw);
|
|
1766
|
+
// 获取到参数
|
|
1767
|
+
if (getOptionsResult) {
|
|
1768
|
+
const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
|
|
1769
|
+
newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
|
|
1770
|
+
for (const e of argsParser(optionsRaw, (name, _) => { return name; })) {
|
|
1771
|
+
options.push(e);
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
return {
|
|
1775
|
+
command,
|
|
1776
|
+
args: newSentenceRaw.split('|').map(e => e.trim()).filter(e => e !== ''),
|
|
1777
|
+
options
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1741
1780
|
function configParser(configText) {
|
|
1742
|
-
|
|
1743
|
-
return
|
|
1781
|
+
const configLines = configText.replaceAll(`\r`, '').split('\n');
|
|
1782
|
+
return configLines.map(e => configLineParser(e)).filter(e => e.command !== '');
|
|
1744
1783
|
}
|
|
1745
1784
|
|
|
1746
1785
|
class SceneParser {
|
|
@@ -1760,6 +1799,10 @@ class SceneParser {
|
|
|
1760
1799
|
parseConfig(configText) {
|
|
1761
1800
|
return configParser(configText);
|
|
1762
1801
|
}
|
|
1802
|
+
stringifyConfig(config) {
|
|
1803
|
+
return config
|
|
1804
|
+
.reduce((previousValue, curr) => (previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`), '');
|
|
1805
|
+
}
|
|
1763
1806
|
}
|
|
1764
1807
|
|
|
1765
1808
|
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG, SceneParser as default };
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
interface IOptionItem {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string | number | boolean;
|
|
4
|
+
}
|
|
5
|
+
interface IConfigItem {
|
|
6
|
+
command: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
options: IOptionItem[];
|
|
9
|
+
}
|
|
10
|
+
export type WebgalConfig = IConfigItem[];
|
|
11
|
+
export declare function configParser(configText: string): WebgalConfig;
|
|
12
|
+
export {};
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAsset } from "./interface/sceneInterface";
|
|
2
2
|
import { fileType } from "./interface/assets";
|
|
3
3
|
import { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG } from "./config/scriptConfig";
|
|
4
|
+
import { WebgalConfig } from "./configParser/configParser";
|
|
4
5
|
export default class SceneParser {
|
|
5
6
|
private readonly assetsPrefetcher;
|
|
6
7
|
private readonly assetSetter;
|
|
@@ -8,6 +9,7 @@ export default class SceneParser {
|
|
|
8
9
|
private readonly SCRIPT_CONFIG;
|
|
9
10
|
constructor(assetsPrefetcher: ((assetList: Array<IAsset>) => void), assetSetter: (fileName: string, assetType: fileType) => string, ADD_NEXT_ARG_LIST: Array<number>, SCRIPT_CONFIG: Array<any>);
|
|
10
11
|
parse(rawScene: string, sceneName: string, sceneUrl: string): import("./interface/sceneInterface").IScene;
|
|
11
|
-
parseConfig(configText: string):
|
|
12
|
+
parseConfig(configText: string): WebgalConfig;
|
|
13
|
+
stringifyConfig(config: WebgalConfig): string;
|
|
12
14
|
}
|
|
13
15
|
export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
|
|
@@ -52,7 +52,7 @@ var webgalParser = (function (exports) {
|
|
|
52
52
|
const type = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
53
53
|
returnCommand.type = type;
|
|
54
54
|
// 如果是对话,加上额外的参数
|
|
55
|
-
if (type === commandType.say) {
|
|
55
|
+
if (type === commandType.say && commandRaw !== 'say') {
|
|
56
56
|
returnCommand.additionalArgs.push({
|
|
57
57
|
key: "speaker",
|
|
58
58
|
value: commandRaw
|
|
@@ -132,7 +132,7 @@ var webgalParser = (function (exports) {
|
|
|
132
132
|
argValue = undefined;
|
|
133
133
|
}
|
|
134
134
|
// 判断是不是语音参数
|
|
135
|
-
if (
|
|
135
|
+
if (argName.match(/.ogg|.mp3|.wav/)) {
|
|
136
136
|
returnArrayList.push({
|
|
137
137
|
key: "vocal",
|
|
138
138
|
value: assetSetter(e, fileType.vocal)
|
|
@@ -1741,9 +1741,48 @@ var webgalParser = (function (exports) {
|
|
|
1741
1741
|
commandType.playEffect,
|
|
1742
1742
|
];
|
|
1743
1743
|
|
|
1744
|
+
function configLineParser(inputLine) {
|
|
1745
|
+
const options = [];
|
|
1746
|
+
let command;
|
|
1747
|
+
let newSentenceRaw = inputLine.split(";")[0];
|
|
1748
|
+
if (newSentenceRaw === "") {
|
|
1749
|
+
// 注释提前返回
|
|
1750
|
+
return {
|
|
1751
|
+
command: '',
|
|
1752
|
+
args: [],
|
|
1753
|
+
options: []
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
// 截取命令
|
|
1757
|
+
const getCommandResult = /:/.exec(newSentenceRaw);
|
|
1758
|
+
// 没有command
|
|
1759
|
+
if (getCommandResult === null) {
|
|
1760
|
+
command = '';
|
|
1761
|
+
}
|
|
1762
|
+
else {
|
|
1763
|
+
command = newSentenceRaw.substring(0, getCommandResult.index);
|
|
1764
|
+
// 划分命令区域和content区域
|
|
1765
|
+
newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
|
|
1766
|
+
}
|
|
1767
|
+
// 截取 Options 区域
|
|
1768
|
+
const getOptionsResult = / -/.exec(newSentenceRaw);
|
|
1769
|
+
// 获取到参数
|
|
1770
|
+
if (getOptionsResult) {
|
|
1771
|
+
const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
|
|
1772
|
+
newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
|
|
1773
|
+
for (const e of argsParser(optionsRaw, (name, _) => { return name; })) {
|
|
1774
|
+
options.push(e);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
return {
|
|
1778
|
+
command,
|
|
1779
|
+
args: newSentenceRaw.split('|').map(e => e.trim()).filter(e => e !== ''),
|
|
1780
|
+
options
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1744
1783
|
function configParser(configText) {
|
|
1745
|
-
|
|
1746
|
-
return
|
|
1784
|
+
const configLines = configText.replaceAll(`\r`, '').split('\n');
|
|
1785
|
+
return configLines.map(e => configLineParser(e)).filter(e => e.command !== '');
|
|
1747
1786
|
}
|
|
1748
1787
|
|
|
1749
1788
|
class SceneParser {
|
|
@@ -1763,6 +1802,10 @@ var webgalParser = (function (exports) {
|
|
|
1763
1802
|
parseConfig(configText) {
|
|
1764
1803
|
return configParser(configText);
|
|
1765
1804
|
}
|
|
1805
|
+
stringifyConfig(config) {
|
|
1806
|
+
return config
|
|
1807
|
+
.reduce((previousValue, curr) => (previousValue + `${curr.command}:${curr.args.join('|')}${curr.options.length <= 0 ? '' : curr.options.reduce((p, c) => (p + ' -' + c.key + '=' + c.value), '')};\n`), '');
|
|
1808
|
+
}
|
|
1766
1809
|
}
|
|
1767
1810
|
|
|
1768
1811
|
exports.ADD_NEXT_ARG_LIST = ADD_NEXT_ARG_LIST;
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ export function argsParser(argsRaw: string, assetSetter: (fileName: string, asse
|
|
|
27
27
|
argValue = undefined;
|
|
28
28
|
}
|
|
29
29
|
// 判断是不是语音参数
|
|
30
|
-
if (
|
|
30
|
+
if (argName.match(/.ogg|.mp3|.wav/)) {
|
|
31
31
|
returnArrayList.push({
|
|
32
32
|
key: "vocal",
|
|
33
33
|
value: assetSetter(e, fileType.vocal)
|
|
@@ -16,7 +16,7 @@ export const commandParser = (commandRaw: string, ADD_NEXT_ARG_LIST:any, SCRIPT_
|
|
|
16
16
|
const type: commandType = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
|
|
17
17
|
returnCommand.type = type;
|
|
18
18
|
// 如果是对话,加上额外的参数
|
|
19
|
-
if (type === commandType.say) {
|
|
19
|
+
if (type === commandType.say && commandRaw!== 'say') {
|
|
20
20
|
returnCommand.additionalArgs.push({
|
|
21
21
|
key: "speaker",
|
|
22
22
|
value: commandRaw
|