webgal-parser 4.5.18 → 4.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webgal-parser",
3
- "version": "4.5.18",
3
+ "version": "4.6.2",
4
4
  "description": "WebGAL script parser",
5
5
  "scripts": {
6
6
  "test": "vitest",
@@ -17,26 +17,16 @@
17
17
  "main": "./build/cjs/index.cjs",
18
18
  "author": "Mahiru <Mahiru_@outlook.com>",
19
19
  "license": "MPL-2.0",
20
- "dependencies": {
21
- "chevrotain": "^10.5.0",
22
- "cloudlogjs": "^1.0.11",
23
- "lodash": "^4.17.21",
24
- "tsx": "^3.12.7"
25
- },
26
20
  "devDependencies": {
27
21
  "@rollup/plugin-commonjs": "^23.0.2",
28
- "@rollup/plugin-json": "^5.0.1",
29
22
  "@rollup/plugin-node-resolve": "^15.0.1",
30
- "@rollup/plugin-typescript": "^9.0.2",
31
- "@types/lodash": "^4.14.189",
32
23
  "@types/node": "^18.14.0",
33
24
  "@vitest/coverage-c8": "^0.28.5",
25
+ "rimraf": "^3.0.2",
34
26
  "rollup": "^3.29.5",
35
- "rollup-plugin-babel": "^4.4.0",
36
- "rollup-plugin-terser": "^7.0.2",
37
27
  "rollup-plugin-typescript2": "^0.34.1",
38
- "ts-node": "^10.9.1",
39
28
  "tslib": "^2.4.1",
29
+ "tsx": "^3.12.7",
40
30
  "typescript": "^4.9.3",
41
31
  "vitest": "^0.28.5"
42
32
  },
@@ -5,7 +5,6 @@ import {
5
5
  ISentence,
6
6
  } from './interface/sceneInterface';
7
7
  import { scriptParser } from './scriptParser/scriptParser';
8
- import uniqWith from 'lodash/uniqWith';
9
8
  import { fileType } from './interface/assets';
10
9
  import { ConfigMap } from './config/scriptConfig';
11
10
 
@@ -38,12 +37,13 @@ export const sceneParser = (
38
37
  let assetsList: Array<IAsset> = []; // 场景资源列表
39
38
  let subSceneList: Array<string> = []; // 子场景列表
40
39
  const sentenceList: Array<ISentence> = rawSentenceListWithoutEmpty.map(
41
- (sentence) => {
40
+ (sentence, index) => {
42
41
  const returnSentence: ISentence = scriptParser(
43
42
  sentence,
44
43
  assetSetter,
45
44
  ADD_NEXT_ARG_LIST,
46
45
  SCRIPT_CONFIG_MAP,
46
+ index,
47
47
  );
48
48
  // 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
49
49
  assetsList = [...assetsList, ...returnSentence.sentenceAssets];
@@ -53,7 +53,7 @@ export const sceneParser = (
53
53
  );
54
54
 
55
55
  // 开始资源的预加载
56
- assetsList = uniqWith(assetsList); // 去重
56
+ assetsList = deduplicateAssets(assetsList);
57
57
  assetsPrefetcher(assetsList);
58
58
 
59
59
  return {
@@ -64,3 +64,18 @@ export const sceneParser = (
64
64
  subSceneList: subSceneList, // 子场景列表
65
65
  };
66
66
  };
67
+
68
+ const deduplicateAssets = (assetsList: IAsset[]): IAsset[] => {
69
+ const seenAssets = new Set<string>();
70
+ return assetsList.filter((asset) => {
71
+ if (!asset || typeof asset.url !== 'string' || asset.url === '') {
72
+ return false;
73
+ }
74
+ const assetKey = `${asset.type}:${asset.url}`;
75
+ if (seenAssets.has(assetKey)) {
76
+ return false;
77
+ }
78
+ seenAssets.add(assetKey);
79
+ return true;
80
+ });
81
+ };
@@ -35,36 +35,39 @@ export function argsParser(
35
35
  key: 'vocal',
36
36
  value: assetSetter(e, fileType.vocal),
37
37
  });
38
- } else {
39
- // 判断是不是省略参数
40
- if (argValue === undefined) {
41
- returnArrayList.push({
42
- key: argName,
43
- value: true,
44
- });
45
- } else {
46
- // 是字符串描述的布尔值
47
- if (argValue === 'true' || argValue === 'false') {
48
- returnArrayList.push({
49
- key: argName,
50
- value: argValue === 'true',
51
- });
52
- } else {
53
- // 是数字
54
- if (!isNaN(Number(argValue))) {
55
- returnArrayList.push({
56
- key: argName,
57
- value: Number(argValue),
58
- });
59
- } else {
60
- // 是普通参数
61
- returnArrayList.push({
62
- key: argName,
63
- value: argValue,
64
- });
65
- }
66
- }
67
- }
38
+ } else if (argName === 'vocal' && argValue !== undefined) {
39
+ returnArrayList.push({
40
+ key: argName,
41
+ value: assetSetter(argValue, fileType.vocal),
42
+ });
43
+ }
44
+ // 判断是不是省略参数
45
+ else if (argValue === undefined) {
46
+ returnArrayList.push({
47
+ key: argName,
48
+ value: true,
49
+ });
50
+ }
51
+ // 是字符串描述的布尔值
52
+ else if (argValue === 'true' || argValue === 'false') {
53
+ returnArrayList.push({
54
+ key: argName,
55
+ value: argValue === 'true',
56
+ });
57
+ }
58
+ // 是数字
59
+ else if (!isNaN(Number(argValue))) {
60
+ returnArrayList.push({
61
+ key: argName,
62
+ value: Number(argValue),
63
+ });
64
+ }
65
+ // 是普通参数
66
+ else {
67
+ returnArrayList.push({
68
+ key: argName,
69
+ value: argValue,
70
+ });
68
71
  }
69
72
  });
70
73
  return returnArrayList;
@@ -12,6 +12,7 @@ export const assetsScanner = (
12
12
  command: commandType,
13
13
  content: string,
14
14
  args: Array<arg>,
15
+ lineNumber: number,
15
16
  ): Array<IAsset> => {
16
17
  let hasVocalArg = false;
17
18
  const returnAssetsList: Array<IAsset> = [];
@@ -22,7 +23,7 @@ export const assetsScanner = (
22
23
  returnAssetsList.push({
23
24
  name: e.value as string,
24
25
  url: e.value as string,
25
- lineNumber: 0,
26
+ lineNumber,
26
27
  type: fileType.vocal,
27
28
  });
28
29
  }
@@ -36,7 +37,7 @@ export const assetsScanner = (
36
37
  returnAssetsList.push({
37
38
  name: content,
38
39
  url: content,
39
- lineNumber: 0,
40
+ lineNumber,
40
41
  type: fileType.background,
41
42
  });
42
43
  }
@@ -44,7 +45,7 @@ export const assetsScanner = (
44
45
  returnAssetsList.push({
45
46
  name: content,
46
47
  url: content,
47
- lineNumber: 0,
48
+ lineNumber,
48
49
  type: fileType.figure,
49
50
  });
50
51
  }
@@ -52,7 +53,7 @@ export const assetsScanner = (
52
53
  returnAssetsList.push({
53
54
  name: content,
54
55
  url: content,
55
- lineNumber: 0,
56
+ lineNumber,
56
57
  type: fileType.figure,
57
58
  });
58
59
  }
@@ -60,7 +61,7 @@ export const assetsScanner = (
60
61
  returnAssetsList.push({
61
62
  name: content,
62
63
  url: content,
63
- lineNumber: 0,
64
+ lineNumber,
64
65
  type: fileType.video,
65
66
  });
66
67
  }
@@ -68,7 +69,7 @@ export const assetsScanner = (
68
69
  returnAssetsList.push({
69
70
  name: content,
70
71
  url: content,
71
- lineNumber: 0,
72
+ lineNumber,
72
73
  type: fileType.bgm,
73
74
  });
74
75
  }
@@ -24,6 +24,7 @@ export const scriptParser = (
24
24
  assetSetter: any,
25
25
  ADD_NEXT_ARG_LIST: commandType[],
26
26
  SCRIPT_CONFIG_MAP: ConfigMap,
27
+ lineNumber = 0,
27
28
  ): ISentence => {
28
29
  let command: commandType; // 默认为对话
29
30
  let content: string; // 语句内容
@@ -39,7 +40,7 @@ export const scriptParser = (
39
40
  const commentSplit = sentenceRaw.split(/(?<!\\);/);
40
41
  let newSentenceRaw = commentSplit[0];
41
42
  newSentenceRaw = newSentenceRaw.replaceAll('\\;',';');
42
- const sentenceComment = commentSplit[1] ?? '';
43
+ const sentenceComment = commentSplit.slice(1).join(';');
43
44
  if (newSentenceRaw.trim() === '') {
44
45
  // 注释提前返回
45
46
  return {
@@ -105,7 +106,7 @@ export const scriptParser = (
105
106
  }
106
107
 
107
108
  content = contentParser(newSentenceRaw.trim(), command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
108
- sentenceAssets = assetsScanner(command, content, args); // 扫描语句携带资源
109
+ sentenceAssets = assetsScanner(command, content, args, lineNumber); // 扫描语句携带资源
109
110
  subScene = subSceneScanner(command, content); // 扫描语句携带子场景
110
111
  return {
111
112
  command: command, // 语句类型