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.
- package/build/cjs/index.js +1 -0
- package/build/cjs/interface/sceneInterface.d.ts +2 -1
- package/build/es/index.js +1 -0
- package/build/es/interface/sceneInterface.d.ts +2 -1
- package/build/types/interface/sceneInterface.d.ts +2 -1
- package/build/umd/index.global.js +1 -0
- package/package.json +40 -40
- package/src/config/scriptConfig.ts +46 -46
- package/src/configParser/configParser.ts +60 -60
- package/src/index.ts +42 -42
- package/src/interface/assets.ts +12 -12
- package/src/interface/runtimeInterface.ts +9 -9
- package/src/interface/sceneInterface.ts +104 -103
- package/src/parser4/index.ts +158 -158
- package/src/sceneParser.ts +47 -47
- package/src/scriptParser/argsParser.ts +68 -68
- 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
|
@@ -1,68 +1,68 @@
|
|
|
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 (argName.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
|
+
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 (argName.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 && commandRaw!== '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 && commandRaw!== '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,66 +1,66 @@
|
|
|
1
|
-
import { commandType } from "../interface/sceneInterface";
|
|
2
|
-
import { fileType } from "../interface/assets";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 解析语句内容的函数,主要作用是把文件名改为绝对地址或相对地址(根据使用情况而定)
|
|
6
|
-
* @param contentRaw 原始语句内容
|
|
7
|
-
* @param type 语句类型
|
|
8
|
-
* @param assetSetter
|
|
9
|
-
* @return {string} 解析后的语句内容
|
|
10
|
-
*/
|
|
11
|
-
export const contentParser = (contentRaw: string, type: commandType, assetSetter: any) => {
|
|
12
|
-
if (contentRaw === "none" || contentRaw === "") {
|
|
13
|
-
return "";
|
|
14
|
-
}
|
|
15
|
-
switch (type) {
|
|
16
|
-
case commandType.playEffect:
|
|
17
|
-
return assetSetter(contentRaw, fileType.vocal);
|
|
18
|
-
case commandType.changeBg:
|
|
19
|
-
return assetSetter(contentRaw, fileType.background);
|
|
20
|
-
case commandType.changeFigure:
|
|
21
|
-
return assetSetter(contentRaw, fileType.figure);
|
|
22
|
-
case commandType.bgm:
|
|
23
|
-
return assetSetter(contentRaw, fileType.bgm);
|
|
24
|
-
case commandType.callScene:
|
|
25
|
-
return assetSetter(contentRaw, fileType.scene);
|
|
26
|
-
case commandType.changeScene:
|
|
27
|
-
return assetSetter(contentRaw, fileType.scene);
|
|
28
|
-
case commandType.miniAvatar:
|
|
29
|
-
return assetSetter(contentRaw, fileType.figure);
|
|
30
|
-
case commandType.video:
|
|
31
|
-
return assetSetter(contentRaw, fileType.video);
|
|
32
|
-
case commandType.choose:
|
|
33
|
-
return getChooseContent(contentRaw, assetSetter);
|
|
34
|
-
case commandType.unlockBgm:
|
|
35
|
-
return assetSetter(contentRaw, fileType.bgm);
|
|
36
|
-
case commandType.unlockCg:
|
|
37
|
-
return assetSetter(contentRaw, fileType.background);
|
|
38
|
-
default:
|
|
39
|
-
return contentRaw;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
function getChooseContent(contentRaw: string, assetSetter: any): string {
|
|
44
|
-
const chooseList = contentRaw.split("|");
|
|
45
|
-
const chooseKeyList: Array<string> = [];
|
|
46
|
-
const chooseValueList: Array<string> = [];
|
|
47
|
-
for (const e of chooseList) {
|
|
48
|
-
chooseKeyList.push(e.split(":")[0] ?? "");
|
|
49
|
-
chooseValueList.push(e.split(":")[1] ?? "");
|
|
50
|
-
}
|
|
51
|
-
const parsedChooseList = chooseValueList.map((e) => {
|
|
52
|
-
if (e.match(/\./)) {
|
|
53
|
-
return assetSetter(e, fileType.scene);
|
|
54
|
-
} else {
|
|
55
|
-
return e;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
let ret = "";
|
|
59
|
-
for (let i = 0; i < chooseKeyList.length; i++) {
|
|
60
|
-
if (i !== 0) {
|
|
61
|
-
ret = ret + "|";
|
|
62
|
-
}
|
|
63
|
-
ret = ret + `${chooseKeyList[i]}:${parsedChooseList[i]}`;
|
|
64
|
-
}
|
|
65
|
-
return ret;
|
|
66
|
-
}
|
|
1
|
+
import { commandType } from "../interface/sceneInterface";
|
|
2
|
+
import { fileType } from "../interface/assets";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 解析语句内容的函数,主要作用是把文件名改为绝对地址或相对地址(根据使用情况而定)
|
|
6
|
+
* @param contentRaw 原始语句内容
|
|
7
|
+
* @param type 语句类型
|
|
8
|
+
* @param assetSetter
|
|
9
|
+
* @return {string} 解析后的语句内容
|
|
10
|
+
*/
|
|
11
|
+
export const contentParser = (contentRaw: string, type: commandType, assetSetter: any) => {
|
|
12
|
+
if (contentRaw === "none" || contentRaw === "") {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
switch (type) {
|
|
16
|
+
case commandType.playEffect:
|
|
17
|
+
return assetSetter(contentRaw, fileType.vocal);
|
|
18
|
+
case commandType.changeBg:
|
|
19
|
+
return assetSetter(contentRaw, fileType.background);
|
|
20
|
+
case commandType.changeFigure:
|
|
21
|
+
return assetSetter(contentRaw, fileType.figure);
|
|
22
|
+
case commandType.bgm:
|
|
23
|
+
return assetSetter(contentRaw, fileType.bgm);
|
|
24
|
+
case commandType.callScene:
|
|
25
|
+
return assetSetter(contentRaw, fileType.scene);
|
|
26
|
+
case commandType.changeScene:
|
|
27
|
+
return assetSetter(contentRaw, fileType.scene);
|
|
28
|
+
case commandType.miniAvatar:
|
|
29
|
+
return assetSetter(contentRaw, fileType.figure);
|
|
30
|
+
case commandType.video:
|
|
31
|
+
return assetSetter(contentRaw, fileType.video);
|
|
32
|
+
case commandType.choose:
|
|
33
|
+
return getChooseContent(contentRaw, assetSetter);
|
|
34
|
+
case commandType.unlockBgm:
|
|
35
|
+
return assetSetter(contentRaw, fileType.bgm);
|
|
36
|
+
case commandType.unlockCg:
|
|
37
|
+
return assetSetter(contentRaw, fileType.background);
|
|
38
|
+
default:
|
|
39
|
+
return contentRaw;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function getChooseContent(contentRaw: string, assetSetter: any): string {
|
|
44
|
+
const chooseList = contentRaw.split("|");
|
|
45
|
+
const chooseKeyList: Array<string> = [];
|
|
46
|
+
const chooseValueList: Array<string> = [];
|
|
47
|
+
for (const e of chooseList) {
|
|
48
|
+
chooseKeyList.push(e.split(":")[0] ?? "");
|
|
49
|
+
chooseValueList.push(e.split(":")[1] ?? "");
|
|
50
|
+
}
|
|
51
|
+
const parsedChooseList = chooseValueList.map((e) => {
|
|
52
|
+
if (e.match(/\./)) {
|
|
53
|
+
return assetSetter(e, fileType.scene);
|
|
54
|
+
} else {
|
|
55
|
+
return e;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
let ret = "";
|
|
59
|
+
for (let i = 0; i < chooseKeyList.length; i++) {
|
|
60
|
+
if (i !== 0) {
|
|
61
|
+
ret = ret + "|";
|
|
62
|
+
}
|
|
63
|
+
ret = ret + `${chooseKeyList[i]}:${parsedChooseList[i]}`;
|
|
64
|
+
}
|
|
65
|
+
return ret;
|
|
66
|
+
}
|