webgal-parser 4.4.9-fix1 → 4.4.14-1

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.
Files changed (48) hide show
  1. package/.prettierrc +19 -0
  2. package/build/cjs/config/scriptConfig.d.ts +6 -1
  3. package/build/cjs/index.cjs +232 -182
  4. package/build/cjs/index.d.ts +15 -6
  5. package/build/cjs/interface/sceneInterface.d.ts +4 -3
  6. package/build/cjs/sceneParser.d.ts +5 -4
  7. package/build/cjs/scriptParser/argsParser.d.ts +2 -2
  8. package/build/cjs/scriptParser/commandParser.d.ts +4 -3
  9. package/build/cjs/scriptParser/contentParser.d.ts +1 -1
  10. package/build/cjs/scriptParser/scriptParser.d.ts +4 -3
  11. package/build/cjs/scriptParser/subSceneScanner.d.ts +1 -1
  12. package/build/cjs/styleParser/index.d.ts +5 -0
  13. package/build/es/config/scriptConfig.d.ts +6 -1
  14. package/build/es/index.d.ts +15 -6
  15. package/build/es/index.js +232 -182
  16. package/build/es/interface/sceneInterface.d.ts +4 -3
  17. package/build/es/sceneParser.d.ts +5 -4
  18. package/build/es/scriptParser/argsParser.d.ts +2 -2
  19. package/build/es/scriptParser/commandParser.d.ts +4 -3
  20. package/build/es/scriptParser/contentParser.d.ts +1 -1
  21. package/build/es/scriptParser/scriptParser.d.ts +4 -3
  22. package/build/es/scriptParser/subSceneScanner.d.ts +1 -1
  23. package/build/es/styleParser/index.d.ts +5 -0
  24. package/build/types/config/scriptConfig.d.ts +6 -1
  25. package/build/types/index.d.ts +15 -6
  26. package/build/types/interface/sceneInterface.d.ts +4 -3
  27. package/build/types/sceneParser.d.ts +5 -4
  28. package/build/types/scriptParser/argsParser.d.ts +2 -2
  29. package/build/types/scriptParser/commandParser.d.ts +4 -3
  30. package/build/types/scriptParser/contentParser.d.ts +1 -1
  31. package/build/types/scriptParser/scriptParser.d.ts +4 -3
  32. package/build/types/scriptParser/subSceneScanner.d.ts +1 -1
  33. package/build/types/styleParser/index.d.ts +5 -0
  34. package/build/umd/index.global.js +232 -182
  35. package/package.json +1 -1
  36. package/src/config/scriptConfig.ts +9 -5
  37. package/src/configParser/configParser.ts +37 -25
  38. package/src/index.ts +66 -30
  39. package/src/interface/sceneInterface.ts +4 -3
  40. package/src/parser4/index.ts +1 -1
  41. package/src/sceneParser.ts +36 -17
  42. package/src/scriptParser/argsParser.ts +17 -14
  43. package/src/scriptParser/assetsScanner.ts +5 -1
  44. package/src/scriptParser/commandParser.ts +31 -23
  45. package/src/scriptParser/contentParser.ts +14 -10
  46. package/src/scriptParser/scriptParser.ts +38 -20
  47. package/src/scriptParser/subSceneScanner.ts +11 -5
  48. package/src/styleParser/index.ts +39 -0
@@ -1,29 +1,28 @@
1
- import {argsParser} from "../scriptParser/argsParser";
1
+ import { argsParser } from '../scriptParser/argsParser';
2
2
 
3
- interface IOptionItem{
4
- key:string;
5
- value:string | number | boolean;
3
+ interface IOptionItem {
4
+ key: string;
5
+ value: string | number | boolean;
6
6
  }
7
- interface IConfigItem{
8
- command:string;
9
- args:string[]
10
- options:IOptionItem[];
7
+ interface IConfigItem {
8
+ command: string;
9
+ args: string[];
10
+ options: IOptionItem[];
11
11
  }
12
12
 
13
- export type WebgalConfig = IConfigItem[]
13
+ export type WebgalConfig = IConfigItem[];
14
14
 
15
-
16
- function configLineParser(inputLine:string):IConfigItem{
17
- const options:Array<IOptionItem> = [];
15
+ function configLineParser(inputLine: string): IConfigItem {
16
+ const options: Array<IOptionItem> = [];
18
17
  let command: string;
19
18
 
20
- let newSentenceRaw = inputLine.split(";")[0];
21
- if (newSentenceRaw === "") {
19
+ let newSentenceRaw = inputLine.split(';')[0];
20
+ if (newSentenceRaw === '') {
22
21
  // 注释提前返回
23
22
  return {
24
- command:'',
25
- args:[],
26
- options:[]
23
+ command: '',
24
+ args: [],
25
+ options: [],
27
26
  };
28
27
  }
29
28
  // 截取命令
@@ -35,26 +34,39 @@ function configLineParser(inputLine:string):IConfigItem{
35
34
  } else {
36
35
  command = newSentenceRaw.substring(0, getCommandResult.index);
37
36
  // 划分命令区域和content区域
38
- newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
37
+ newSentenceRaw = newSentenceRaw.substring(
38
+ getCommandResult.index + 1,
39
+ newSentenceRaw.length,
40
+ );
39
41
  }
40
42
  // 截取 Options 区域
41
43
  const getOptionsResult = / -/.exec(newSentenceRaw);
42
44
  // 获取到参数
43
45
  if (getOptionsResult) {
44
- const optionsRaw = newSentenceRaw.substring(getOptionsResult.index, newSentenceRaw.length);
46
+ const optionsRaw = newSentenceRaw.substring(
47
+ getOptionsResult.index,
48
+ newSentenceRaw.length,
49
+ );
45
50
  newSentenceRaw = newSentenceRaw.substring(0, getOptionsResult.index);
46
- for (const e of argsParser(optionsRaw, (name,_)=>{return name})) {
51
+ for (const e of argsParser(optionsRaw, (name, _) => {
52
+ return name;
53
+ })) {
47
54
  options.push(e);
48
55
  }
49
56
  }
50
57
  return {
51
58
  command,
52
- args:newSentenceRaw.split('|').map(e=>e.trim()).filter(e=>e!==''),
53
- options
59
+ args: newSentenceRaw
60
+ .split('|')
61
+ .map((e) => e.trim())
62
+ .filter((e) => e !== ''),
63
+ options,
54
64
  };
55
65
  }
56
66
 
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!=='');
67
+ export function configParser(configText: string): WebgalConfig {
68
+ const configLines = configText.replaceAll(`\r`, '').split('\n');
69
+ return configLines
70
+ .map((e) => configLineParser(e))
71
+ .filter((e) => e.command !== '');
60
72
  }
package/src/index.ts CHANGED
@@ -1,42 +1,78 @@
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";
1
+ import {
2
+ ADD_NEXT_ARG_LIST,
3
+ SCRIPT_CONFIG,
4
+ ConfigMap,
5
+ ConfigItem,
6
+ } from './config/scriptConfig';
7
+ import { configParser, WebgalConfig } from './configParser/configParser';
8
+ import { fileType } from './interface/assets';
9
+ import { IAsset } from './interface/sceneInterface';
10
+ import { sceneParser } from './sceneParser';
11
+ import {IWebGALStyleObj, scss2cssinjsParser} from "@/styleParser";
6
12
 
7
13
  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
14
+ private readonly SCRIPT_CONFIG_MAP: ConfigMap;
15
+ constructor(
16
+ private readonly assetsPrefetcher: (assetList: IAsset[]) => void,
17
+ private readonly assetSetter: (
18
+ fileName: string,
19
+ assetType: fileType,
20
+ ) => string,
21
+ private readonly ADD_NEXT_ARG_LIST: number[],
22
+ SCRIPT_CONFIG_INPUT: ConfigItem[] | ConfigMap,
24
23
  ) {
25
- return sceneParser(rawScene, sceneName, sceneUrl, this.assetsPrefetcher, this.assetSetter, this.ADD_NEXT_ARG_LIST, this.SCRIPT_CONFIG);
24
+ if (Array.isArray(SCRIPT_CONFIG_INPUT)) {
25
+ this.SCRIPT_CONFIG_MAP = new Map();
26
+ SCRIPT_CONFIG_INPUT.forEach((config) => {
27
+ this.SCRIPT_CONFIG_MAP.set(config.scriptString, config);
28
+ });
29
+ } else {
30
+ this.SCRIPT_CONFIG_MAP = SCRIPT_CONFIG_INPUT;
31
+ }
32
+ }
33
+ /**
34
+ * 解析场景
35
+ * @param rawScene 原始场景
36
+ * @param sceneName 场景名称
37
+ * @param sceneUrl 场景url
38
+ * @return 解析后的场景
39
+ */
40
+ parse(rawScene: string, sceneName: string, sceneUrl: string) {
41
+ return sceneParser(
42
+ rawScene,
43
+ sceneName,
44
+ sceneUrl,
45
+ this.assetsPrefetcher,
46
+ this.assetSetter,
47
+ this.ADD_NEXT_ARG_LIST,
48
+ this.SCRIPT_CONFIG_MAP,
49
+ );
26
50
  }
27
51
 
28
52
  parseConfig(configText: string) {
29
- return configParser(configText)
53
+ return configParser(configText);
30
54
  }
31
55
 
32
56
  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
- )
57
+ return config.reduce(
58
+ (previousValue, curr) =>
59
+ previousValue +
60
+ `${curr.command}:${curr.args.join('|')}${
61
+ curr.options.length <= 0
62
+ ? ''
63
+ : curr.options.reduce(
64
+ (p, c) => p + ' -' + c.key + '=' + c.value,
65
+ '',
66
+ )
67
+ };\n`,
68
+ '',
69
+ );
70
+ }
71
+
72
+ parseScssToWebgalStyleObj(scssString: string): IWebGALStyleObj{
73
+ return scss2cssinjsParser(scssString);
39
74
  }
75
+
40
76
  }
41
77
 
42
- export {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG};
78
+ export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * 语句类型
3
3
  */
4
- import {sceneEntry} from "./runtimeInterface";
5
- import {fileType} from "./assets";
4
+ import { sceneEntry } from './runtimeInterface';
5
+ import { fileType } from './assets';
6
6
 
7
7
  export enum commandType {
8
8
  say, // 对话
@@ -36,7 +36,8 @@ export enum commandType {
36
36
  comment,
37
37
  setTransform,
38
38
  setTransition,
39
- getUserInput
39
+ getUserInput,
40
+ applyStyle
40
41
  }
41
42
 
42
43
  /**
@@ -155,4 +155,4 @@
155
155
  // defaultRule: "scene"
156
156
  // };
157
157
  // }());
158
- export const parser4 = 'unreleased'
158
+ export const parser4 = 'unreleased';
@@ -1,7 +1,13 @@
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";
1
+ import {
2
+ commandType,
3
+ IAsset,
4
+ IScene,
5
+ ISentence,
6
+ } from './interface/sceneInterface';
7
+ import { scriptParser } from './scriptParser/scriptParser';
8
+ import uniqWith from 'lodash/uniqWith';
9
+ import { fileType } from './interface/assets';
10
+ import { ConfigMap } from './config/scriptConfig';
5
11
 
6
12
  /**
7
13
  * 场景解析器
@@ -11,13 +17,19 @@ import { fileType } from "./interface/assets";
11
17
  * @param assetsPrefetcher
12
18
  * @param assetSetter
13
19
  * @param ADD_NEXT_ARG_LIST
14
- * @param SCRIPT_CONFIG
20
+ * @param SCRIPT_CONFIG_MAP
15
21
  * @return {IScene} 解析后的场景
16
22
  */
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"); // 原始句子列表
23
+ export const sceneParser = (
24
+ rawScene: string,
25
+ sceneName: string,
26
+ sceneUrl: string,
27
+ assetsPrefetcher: (assetList: Array<IAsset>) => void,
28
+ assetSetter: (fileName: string, assetType: fileType) => string,
29
+ ADD_NEXT_ARG_LIST: commandType[],
30
+ SCRIPT_CONFIG_MAP: ConfigMap,
31
+ ): IScene => {
32
+ const rawSentenceList = rawScene.split('\n'); // 原始句子列表
21
33
 
22
34
  // 去分号留到后面去做了,现在注释要单独处理
23
35
  const rawSentenceListWithoutEmpty = rawSentenceList;
@@ -25,13 +37,20 @@ export const sceneParser = (rawScene: string, sceneName: string, sceneUrl: strin
25
37
  // .filter((sentence) => sentence.trim() !== "");
26
38
  let assetsList: Array<IAsset> = []; // 场景资源列表
27
39
  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
- });
40
+ const sentenceList: Array<ISentence> = rawSentenceListWithoutEmpty.map(
41
+ (sentence) => {
42
+ const returnSentence: ISentence = scriptParser(
43
+ sentence,
44
+ assetSetter,
45
+ ADD_NEXT_ARG_LIST,
46
+ SCRIPT_CONFIG_MAP,
47
+ );
48
+ // 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
49
+ assetsList = [...assetsList, ...returnSentence.sentenceAssets];
50
+ subSceneList = [...subSceneList, ...returnSentence.subScene];
51
+ return returnSentence;
52
+ },
53
+ );
35
54
 
36
55
  // 开始资源的预加载
37
56
  assetsList = uniqWith(assetsList); // 去重
@@ -42,6 +61,6 @@ export const sceneParser = (rawScene: string, sceneName: string, sceneUrl: strin
42
61
  sceneUrl: sceneUrl,
43
62
  sentenceList: sentenceList, // 语句列表
44
63
  assetsList: assetsList, // 资源列表
45
- subSceneList: subSceneList // 子场景列表
64
+ subSceneList: subSceneList, // 子场景列表
46
65
  };
47
66
  };
@@ -1,5 +1,5 @@
1
- import {arg} from "../interface/sceneInterface";
2
- import {fileType} from "../interface/assets";
1
+ import { arg } from '../interface/sceneInterface';
2
+ import { fileType } from '../interface/assets';
3
3
 
4
4
  /**
5
5
  * 参数解析器
@@ -7,16 +7,19 @@ import {fileType} from "../interface/assets";
7
7
  * @param assetSetter
8
8
  * @return {Array<arg>} 解析后的参数列表
9
9
  */
10
- export function argsParser(argsRaw: string, assetSetter: (fileName: string, assetType: fileType) => string): Array<arg> {
10
+ export function argsParser(
11
+ argsRaw: string,
12
+ assetSetter: (fileName: string, assetType: fileType) => string,
13
+ ): Array<arg> {
11
14
  const returnArrayList: Array<arg> = [];
12
15
  // 处理参数
13
16
  // 不要去空格
14
- let newArgsRaw = argsRaw.replace(/ /g, " ");
17
+ let newArgsRaw = argsRaw.replace(/ /g, ' ');
15
18
  // 分割参数列表
16
- let rawArgsList: Array<string> = newArgsRaw.split(" -");
19
+ let rawArgsList: Array<string> = newArgsRaw.split(' -');
17
20
  // 去除空字符串
18
21
  rawArgsList = rawArgsList.filter((e) => {
19
- return e !== "";
22
+ return e !== '';
20
23
  });
21
24
  rawArgsList.forEach((e) => {
22
25
  const equalSignIndex = e.indexOf('=');
@@ -29,35 +32,35 @@ export function argsParser(argsRaw: string, assetSetter: (fileName: string, asse
29
32
  // 判断是不是语音参数
30
33
  if (argName.toLowerCase().match(/.ogg|.mp3|.wav/)) {
31
34
  returnArrayList.push({
32
- key: "vocal",
33
- value: assetSetter(e, fileType.vocal)
35
+ key: 'vocal',
36
+ value: assetSetter(e, fileType.vocal),
34
37
  });
35
38
  } else {
36
39
  // 判断是不是省略参数
37
40
  if (argValue === undefined) {
38
41
  returnArrayList.push({
39
42
  key: argName,
40
- value: true
43
+ value: true,
41
44
  });
42
45
  } else {
43
46
  // 是字符串描述的布尔值
44
- if (argValue === "true" || argValue === "false") {
47
+ if (argValue === 'true' || argValue === 'false') {
45
48
  returnArrayList.push({
46
49
  key: argName,
47
- value: argValue === "true"
50
+ value: argValue === 'true',
48
51
  });
49
52
  } else {
50
53
  // 是数字
51
54
  if (!isNaN(Number(argValue))) {
52
55
  returnArrayList.push({
53
56
  key: argName,
54
- value: Number(argValue)
57
+ value: Number(argValue),
55
58
  });
56
59
  } else {
57
60
  // 是普通参数
58
61
  returnArrayList.push({
59
62
  key: argName,
60
- value: argValue
63
+ value: argValue,
61
64
  });
62
65
  }
63
66
  }
@@ -65,4 +68,4 @@ export function argsParser(argsRaw: string, assetSetter: (fileName: string, asse
65
68
  }
66
69
  });
67
70
  return returnArrayList;
68
- };
71
+ }
@@ -8,7 +8,11 @@ import { fileType } from '../interface/assets';
8
8
  * @param args 参数列表
9
9
  * @return {Array<IAsset>} 语句携带的参数列表
10
10
  */
11
- export const assetsScanner = (command: commandType, content: string, args: Array<arg>): Array<IAsset> => {
11
+ export const assetsScanner = (
12
+ command: commandType,
13
+ content: string,
14
+ args: Array<arg>,
15
+ ): Array<IAsset> => {
12
16
  let hasVocalArg = false;
13
17
  const returnAssetsList: Array<IAsset> = [];
14
18
  if (command === commandType.say) {
@@ -1,25 +1,34 @@
1
- import { commandType, parsedCommand } from "../interface/sceneInterface";
1
+ import { ConfigMap } from '../config/scriptConfig';
2
+ import { commandType, parsedCommand } from '../interface/sceneInterface';
2
3
 
3
4
  /**
4
5
  * 处理命令
5
6
  * @param commandRaw
6
7
  * @param ADD_NEXT_ARG_LIST
7
- * @param SCRIPT_CONFIG
8
+ * @param SCRIPT_CONFIG_MAP
8
9
  * @return {parsedCommand} 处理后的命令
9
10
  */
10
- export const commandParser = (commandRaw: string, ADD_NEXT_ARG_LIST:any, SCRIPT_CONFIG:any): parsedCommand => {
11
+ export const commandParser = (
12
+ commandRaw: string,
13
+ ADD_NEXT_ARG_LIST: commandType[],
14
+ SCRIPT_CONFIG_MAP: ConfigMap,
15
+ ): parsedCommand => {
11
16
  let returnCommand: parsedCommand = {
12
17
  type: commandType.say, // 默认是say
13
- additionalArgs: []
18
+ additionalArgs: [],
14
19
  };
15
20
  // 开始处理命令内容
16
- const type: commandType = getCommandType(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
21
+ const type: commandType = getCommandType(
22
+ commandRaw,
23
+ ADD_NEXT_ARG_LIST,
24
+ SCRIPT_CONFIG_MAP,
25
+ );
17
26
  returnCommand.type = type;
18
27
  // 如果是对话,加上额外的参数
19
- if (type === commandType.say && commandRaw!== 'say') {
28
+ if (type === commandType.say && commandRaw !== 'say') {
20
29
  returnCommand.additionalArgs.push({
21
- key: "speaker",
22
- value: commandRaw
30
+ key: 'speaker',
31
+ value: commandRaw,
23
32
  });
24
33
  }
25
34
  returnCommand = addNextArg(returnCommand, type, ADD_NEXT_ARG_LIST);
@@ -30,27 +39,26 @@ export const commandParser = (commandRaw: string, ADD_NEXT_ARG_LIST:any, SCRIPT_
30
39
  * 根据command原始值判断是什么命令
31
40
  * @param command command原始值
32
41
  * @param ADD_NEXT_ARG_LIST
33
- * @param SCRIPT_CONFIG
42
+ * @param SCRIPT_CONFIG_MAP
34
43
  * @return {commandType} 得到的command类型
35
44
  */
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;
45
+ function getCommandType(
46
+ command: string,
47
+ ADD_NEXT_ARG_LIST: commandType[],
48
+ SCRIPT_CONFIG_MAP: ConfigMap,
49
+ ): commandType {
50
+ return SCRIPT_CONFIG_MAP.get(command)?.scriptType ?? commandType.say;
47
51
  }
48
52
 
49
- function addNextArg(commandToParse: parsedCommand, thisCommandType: commandType, ADD_NEXT_ARG_LIST:any) {
53
+ function addNextArg(
54
+ commandToParse: parsedCommand,
55
+ thisCommandType: commandType,
56
+ ADD_NEXT_ARG_LIST: commandType[],
57
+ ) {
50
58
  if (ADD_NEXT_ARG_LIST.includes(thisCommandType)) {
51
59
  commandToParse.additionalArgs.push({
52
- key: "next",
53
- value: true
60
+ key: 'next',
61
+ value: true,
54
62
  });
55
63
  }
56
64
  return commandToParse;
@@ -1,5 +1,5 @@
1
- import { commandType } from "../interface/sceneInterface";
2
- import { fileType } from "../interface/assets";
1
+ import { commandType } from '../interface/sceneInterface';
2
+ import { fileType } from '../interface/assets';
3
3
 
4
4
  /**
5
5
  * 解析语句内容的函数,主要作用是把文件名改为绝对地址或相对地址(根据使用情况而定)
@@ -8,9 +8,13 @@ import { fileType } from "../interface/assets";
8
8
  * @param assetSetter
9
9
  * @return {string} 解析后的语句内容
10
10
  */
11
- export const contentParser = (contentRaw: string, type: commandType, assetSetter: any) => {
12
- if (contentRaw === "none" || contentRaw === "") {
13
- return "";
11
+ export const contentParser = (
12
+ contentRaw: string,
13
+ type: commandType,
14
+ assetSetter: any,
15
+ ) => {
16
+ if (contentRaw === 'none' || contentRaw === '') {
17
+ return '';
14
18
  }
15
19
  switch (type) {
16
20
  case commandType.playEffect:
@@ -41,12 +45,12 @@ export const contentParser = (contentRaw: string, type: commandType, assetSetter
41
45
  };
42
46
 
43
47
  function getChooseContent(contentRaw: string, assetSetter: any): string {
44
- const chooseList = contentRaw.split("|");
48
+ const chooseList = contentRaw.split('|');
45
49
  const chooseKeyList: Array<string> = [];
46
50
  const chooseValueList: Array<string> = [];
47
51
  for (const e of chooseList) {
48
- chooseKeyList.push(e.split(":")[0] ?? "");
49
- chooseValueList.push(e.split(":")[1] ?? "");
52
+ chooseKeyList.push(e.split(':')[0] ?? '');
53
+ chooseValueList.push(e.split(':')[1] ?? '');
50
54
  }
51
55
  const parsedChooseList = chooseValueList.map((e) => {
52
56
  if (e.match(/\./)) {
@@ -55,10 +59,10 @@ function getChooseContent(contentRaw: string, assetSetter: any): string {
55
59
  return e;
56
60
  }
57
61
  });
58
- let ret = "";
62
+ let ret = '';
59
63
  for (let i = 0; i < chooseKeyList.length; i++) {
60
64
  if (i !== 0) {
61
- ret = ret + "|";
65
+ ret = ret + '|';
62
66
  }
63
67
  ret = ret + `${chooseKeyList[i]}:${parsedChooseList[i]}`;
64
68
  }
@@ -1,18 +1,30 @@
1
- import { arg, commandType, IAsset, ISentence, parsedCommand } from "../interface/sceneInterface";
2
- import { commandParser } from "./commandParser";
3
- import { argsParser } from "./argsParser";
4
- import { contentParser } from "./contentParser";
5
- import { assetsScanner } from "./assetsScanner";
6
- import { subSceneScanner } from "./subSceneScanner";
1
+ import {
2
+ arg,
3
+ commandType,
4
+ IAsset,
5
+ ISentence,
6
+ parsedCommand,
7
+ } from '../interface/sceneInterface';
8
+ import { commandParser } from './commandParser';
9
+ import { argsParser } from './argsParser';
10
+ import { contentParser } from './contentParser';
11
+ import { assetsScanner } from './assetsScanner';
12
+ import { subSceneScanner } from './subSceneScanner';
13
+ import { ConfigMap } from '../config/scriptConfig';
7
14
 
8
15
  /**
9
16
  * 语句解析器
10
17
  * @param sentenceRaw 原始语句
11
18
  * @param assetSetter
12
19
  * @param ADD_NEXT_ARG_LIST
13
- * @param SCRIPT_CONFIG
20
+ * @param SCRIPT_CONFIG_MAP
14
21
  */
15
- export const scriptParser = (sentenceRaw: string, assetSetter: any, ADD_NEXT_ARG_LIST: any, SCRIPT_CONFIG: any): ISentence => {
22
+ export const scriptParser = (
23
+ sentenceRaw: string,
24
+ assetSetter: any,
25
+ ADD_NEXT_ARG_LIST: commandType[],
26
+ SCRIPT_CONFIG_MAP: ConfigMap,
27
+ ): ISentence => {
16
28
  let command: commandType; // 默认为对话
17
29
  let content: string; // 语句内容
18
30
  let subScene: Array<string>; // 语句携带的子场景(可能没有)
@@ -24,16 +36,16 @@ export const scriptParser = (sentenceRaw: string, assetSetter: any, ADD_NEXT_ARG
24
36
  // 正式开始解析
25
37
 
26
38
  // 去分号,前面已做,这里不再需要
27
- let newSentenceRaw = sentenceRaw.split(";")[0];
28
- if (newSentenceRaw === "") {
39
+ let newSentenceRaw = sentenceRaw.split(';')[0];
40
+ if (newSentenceRaw === '') {
29
41
  // 注释提前返回
30
42
  return {
31
43
  command: commandType.comment, // 语句类型
32
- commandRaw: "comment", // 命令原始内容,方便调试
33
- content: sentenceRaw.split(";")[1] ?? "", // 语句内容
34
- args: [{ key: "next", value: true }], // 参数列表
44
+ commandRaw: 'comment', // 命令原始内容,方便调试
45
+ content: sentenceRaw.split(';')[1] ?? '', // 语句内容
46
+ args: [{ key: 'next', value: true }], // 参数列表
35
47
  sentenceAssets: [], // 语句携带的资源列表
36
- subScene: [] // 语句携带的子场景
48
+ subScene: [], // 语句携带的子场景
37
49
  };
38
50
  }
39
51
  // 截取命令
@@ -44,11 +56,11 @@ export const scriptParser = (sentenceRaw: string, assetSetter: any, ADD_NEXT_ARG
44
56
  // 没有command,说明这是一条连续对话或单条语句
45
57
  if (getCommandResult === null) {
46
58
  commandRaw = newSentenceRaw;
47
- parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
59
+ parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP);
48
60
  command = parsedCommand.type;
49
61
  for (const e of parsedCommand.additionalArgs) {
50
62
  // 由于是连续对话,所以我们去除 speaker 参数。
51
- if (command === commandType.say && e.key === "speaker") {
63
+ if (command === commandType.say && e.key === 'speaker') {
52
64
  continue;
53
65
  }
54
66
  args.push(e);
@@ -56,8 +68,11 @@ export const scriptParser = (sentenceRaw: string, assetSetter: any, ADD_NEXT_ARG
56
68
  } else {
57
69
  commandRaw = newSentenceRaw.substring(0, getCommandResult.index);
58
70
  // 划分命令区域和content区域
59
- newSentenceRaw = newSentenceRaw.substring(getCommandResult.index + 1, newSentenceRaw.length);
60
- parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
71
+ newSentenceRaw = newSentenceRaw.substring(
72
+ getCommandResult.index + 1,
73
+ newSentenceRaw.length,
74
+ );
75
+ parsedCommand = commandParser(commandRaw, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG_MAP);
61
76
  command = parsedCommand.type;
62
77
  for (const e of parsedCommand.additionalArgs) {
63
78
  args.push(e);
@@ -67,7 +82,10 @@ export const scriptParser = (sentenceRaw: string, assetSetter: any, ADD_NEXT_ARG
67
82
  const getArgsResult = / -/.exec(newSentenceRaw);
68
83
  // 获取到参数
69
84
  if (getArgsResult) {
70
- const argsRaw = newSentenceRaw.substring(getArgsResult.index, sentenceRaw.length);
85
+ const argsRaw = newSentenceRaw.substring(
86
+ getArgsResult.index,
87
+ sentenceRaw.length,
88
+ );
71
89
  newSentenceRaw = newSentenceRaw.substring(0, getArgsResult.index);
72
90
  for (const e of argsParser(argsRaw, assetSetter)) {
73
91
  args.push(e);
@@ -82,6 +100,6 @@ export const scriptParser = (sentenceRaw: string, assetSetter: any, ADD_NEXT_ARG
82
100
  content: content, // 语句内容
83
101
  args: args, // 参数列表
84
102
  sentenceAssets: sentenceAssets, // 语句携带的资源列表
85
- subScene: subScene // 语句携带的子场景
103
+ subScene: subScene, // 语句携带的子场景
86
104
  };
87
105
  };