webgal-parser 4.6.2 → 4.6.3-beta.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.
@@ -31,15 +31,11 @@ function sceneTextPreProcessPassOne(lines: string[]): string[] {
31
31
  let thisLineIsMultiline = false;
32
32
 
33
33
  for (const line of lines) {
34
- thisLineIsMultiline = false;
35
-
36
- if (canBeMultiline(line)) {
37
- thisLineIsMultiline = true;
38
- }
39
-
40
- if (shouldNotBeMultiline(line, lastLineIsMultiline)) {
41
- thisLineIsMultiline = false;
42
- }
34
+ // 续行需要接到上一行,所以场景的第一行永远不会是续行。
35
+ thisLineIsMultiline =
36
+ processedLines.length > 0 &&
37
+ canBeMultiline(line) &&
38
+ !shouldNotBeMultiline(line, lastLineIsMultiline);
43
39
 
44
40
  if (thisLineIsMultiline) {
45
41
  processedLines[processedLines.length - 1] += '\\';
@@ -98,7 +94,10 @@ function isEmptyLine(line: string): boolean {
98
94
  */
99
95
  function sceneTextPreProcessPassTwo(lines: string[]): string[] {
100
96
  const processedLines: string[] = [];
101
- let currentMultilineContent = "";
97
+ // null 表示当前不在多行序列里。这里不能用空串来判断:
98
+ // 序列的首行本身可能就是空行(比如空行后面紧跟着一条续行),
99
+ // 那样整条序列会被静默丢弃,破坏「预处理前后行数一致」这个前提。
100
+ let currentMultilineContent: string | null = null;
102
101
  let placeHolderLines: string[] = [];
103
102
 
104
103
  function concat(line: string) {
@@ -110,12 +109,18 @@ function sceneTextPreProcessPassTwo(lines: string[]): string[] {
110
109
  placeHolderLines.push(placeholderLine(line));
111
110
  }
112
111
 
112
+ /** 把折叠好的整条语句连同补齐行数的占位行一起输出 */
113
+ function flushMultiline() {
114
+ processedLines.push(currentMultilineContent as string, ...placeHolderLines);
115
+ placeHolderLines = [];
116
+ currentMultilineContent = null;
117
+ }
118
+
113
119
  for (const line of lines) {
114
- console.log(line);
115
120
  if (line.endsWith('\\')) {
116
121
  const trueLine = line.slice(0, -1);
117
122
 
118
- if (currentMultilineContent === "") {
123
+ if (currentMultilineContent === null) {
119
124
  // first line
120
125
  currentMultilineContent = trueLine;
121
126
  } else {
@@ -125,23 +130,38 @@ function sceneTextPreProcessPassTwo(lines: string[]): string[] {
125
130
  continue;
126
131
  }
127
132
 
128
- if (currentMultilineContent !== "") {
133
+ if (currentMultilineContent !== null) {
129
134
  // end line
130
135
  concat(line);
131
- processedLines.push(currentMultilineContent);
132
- processedLines.push(...placeHolderLines);
133
-
134
- placeHolderLines = [];
135
- currentMultilineContent = "";
136
+ flushMultiline();
136
137
  continue;
137
138
  }
138
139
 
139
140
  processedLines.push(line);
140
141
  }
141
142
 
143
+ // 场景末行仍以 \ 结尾时循环里没有机会收尾,在这里把累积的内容补出去。
144
+ if (currentMultilineContent !== null) {
145
+ flushMultiline();
146
+ }
147
+
142
148
  return processedLines;
143
149
  }
144
150
 
151
+ /**
152
+ * 占位行的前缀。占位行本身是一条注释,引擎会空跑掉;
153
+ * 它的作用是让预处理后的行数与原始场景一致,从而保持
154
+ * 「解析后语句 index == 文件行号」这一不变量。
155
+ */
156
+ export const WEBGAL_LINE_BREAK_MARK = ';_WEBGAL_LINE_BREAK_';
157
+
158
+ /**
159
+ * 判断预处理后的某一行是否是占位行,即它是上一条多行语句折叠掉的续行。
160
+ */
161
+ export function isLineBreakPlaceholder(processedLine: string): boolean {
162
+ return processedLine.startsWith(WEBGAL_LINE_BREAK_MARK);
163
+ }
164
+
145
165
  /**
146
166
  * Placeholder Line. Adding this line preserves the original number of lines
147
167
  * in the scene text, so that it can be compatible with the graphical editor.
@@ -150,74 +170,5 @@ function sceneTextPreProcessPassTwo(lines: string[]): string[] {
150
170
  * @returns The placeholder line
151
171
  */
152
172
  function placeholderLine(content = "") {
153
- return ";_WEBGAL_LINE_BREAK_" + content;
173
+ return WEBGAL_LINE_BREAK_MARK + content;
154
174
  }
155
-
156
- // export function sceneTextPreProcess(sceneText: string): string {
157
- // const lines = sceneText.replaceAll('\r', '').split('\n');
158
- // const processedLines: string[] = [];
159
- // let lastNonMultilineIndex = -1;
160
- // let isInMultilineSequence = false;
161
-
162
- // function isMultiline(line: string): boolean {
163
- // if (!line.startsWith(' ')) return false;
164
- // const trimmedLine = line.trimStart();
165
- // return trimmedLine.startsWith('|') || trimmedLine.startsWith('-');
166
- // }
167
-
168
- // for (let i = 0; i < lines.length; i++) {
169
- // const line = lines[i];
170
-
171
- // if (line.trim() === '') {
172
- // // Empty line handling
173
- // if (isInMultilineSequence) {
174
- // // Check if the next line is a multiline line
175
-
176
- // let isStillInMulti = false;
177
- // for (let j = i + 1; j < lines.length; j++) {
178
- // const lookForwardLine = lines[j] || '';
179
- // // 遇到正常语句了,直接中断
180
- // if (lookForwardLine.trim() !== '' && !isMultiline(lookForwardLine)) {
181
- // isStillInMulti = false;
182
- // break;
183
- // }
184
- // // 必须找到后面接的是参数,并且中间没有遇到任何正常语句才行
185
- // if (lookForwardLine.trim() !== '' && isMultiline(lookForwardLine)) {
186
- // isStillInMulti = true;
187
- // break;
188
- // }
189
- // }
190
- // if (isStillInMulti) {
191
- // // Still within a multiline sequence
192
- // processedLines.push(';_WEBGAL_LINE_BREAK_');
193
- // } else {
194
- // // End of multiline sequence
195
- // isInMultilineSequence = false;
196
- // processedLines.push(line);
197
- // }
198
- // } else {
199
- // // Preserve empty lines outside of multiline sequences
200
- // processedLines.push(line);
201
- // }
202
- // } else if (isMultiline(line)) {
203
- // // Multiline statement handling
204
- // if (lastNonMultilineIndex >= 0) {
205
- // // Concatenate to the previous non-multiline statement
206
- // const trimedLine = line.trimStart();
207
- // const addBlank = trimedLine.startsWith('-') ? ' ' : '';
208
- // processedLines[lastNonMultilineIndex] += addBlank + trimedLine;
209
- // }
210
-
211
- // // Add the special comment line
212
- // processedLines.push(';_WEBGAL_LINE_BREAK_' + line);
213
- // isInMultilineSequence = true;
214
- // } else {
215
- // // Non-multiline statement handling
216
- // processedLines.push(line);
217
- // lastNonMultilineIndex = processedLines.length - 1;
218
- // isInMultilineSequence = false;
219
- // }
220
- // }
221
-
222
- // return processedLines.join('\n');
223
- // }
@@ -30,7 +30,7 @@ export function argsParser(
30
30
  argValue = undefined;
31
31
  }
32
32
  // 判断是不是语音参数
33
- if (argName.toLowerCase().match(/.ogg|.mp3|.wav/)) {
33
+ if (argName.toLowerCase().match(/.ogg|.mp3|.wav|.opus/)) {
34
34
  returnArrayList.push({
35
35
  key: 'vocal',
36
36
  value: assetSetter(e, fileType.vocal),
@@ -51,6 +51,9 @@ export const scriptParser = (
51
51
  sentenceAssets: [], // 语句携带的资源列表
52
52
  subScene: [], // 语句携带的子场景
53
53
  inlineComment: '', // 行内注释
54
+ startLine: lineNumber,
55
+ endLine: lineNumber,
56
+ isLineBreakHolder: false,
54
57
  };
55
58
  }
56
59
  // 截取命令
@@ -116,5 +119,9 @@ export const scriptParser = (
116
119
  sentenceAssets: sentenceAssets, // 语句携带的资源列表
117
120
  subScene: subScene, // 语句携带的子场景
118
121
  inlineComment: sentenceComment.trim(), // 行内注释
122
+ // 单行语句的行范围就是自己,多行语句的 endLine 由 sceneParser 回填
123
+ startLine: lineNumber,
124
+ endLine: lineNumber,
125
+ isLineBreakHolder: false,
119
126
  };
120
127
  };