Skip to content

Commit dd6ffac

Browse files
Merge pull request #730 from OpenWebGAL/update-webgal-parser-sync
feat: sync webgal-parser interfaces with main WebGAL project
2 parents bff1cdc + 2f6a97c commit dd6ffac

File tree

5 files changed

+97
-4
lines changed

5 files changed

+97
-4
lines changed

packages/parser/CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# WebGAL Parser Changelog
2+
3+
## [4.5.13] - 2025-07-05
4+
5+
### Fixed
6+
- Fixed interface consistency between `webgal-parser` and main WebGAL project
7+
- Added missing trailing comma in `commandType` enum to match WebGAL main project
8+
- Updated `ISceneData` interface to use `ISceneEntry` instead of `sceneEntry` for better type consistency
9+
10+
### Added
11+
- Added `ISceneEntry` interface as compatibility alias for `sceneEntry`
12+
- Added comprehensive test cases for new animation parameters:
13+
- `wait` command testing
14+
- `changeFigure` with `duration`, `enter`, `exit` parameters
15+
- `changeBg` with animation and transform parameters
16+
17+
### Improved
18+
- Enhanced type safety and consistency with main WebGAL project
19+
- Better test coverage for animation-related features
20+
- Improved interface documentation
21+
22+
### Technical Notes
23+
- The parser already supports all animation parameters (`duration`, `enter`, `exit`, `transform`) through its generic argument parsing system
24+
- No changes to core parsing logic were needed - the parser was already compatible with the latest WebGAL features
25+
- This update focuses on interface consistency and test coverage improvements
26+
27+
## [4.5.12] - Previous Version
28+
- Previous stable release with `wait` command support

packages/parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webgal-parser",
3-
"version": "4.5.12",
3+
"version": "4.5.13",
44
"description": "WebGAL script parser",
55
"scripts": {
66
"test": "vitest",

packages/parser/src/interface/runtimeInterface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ export interface sceneEntry {
77
sceneUrl: string; // 场景url
88
continueLine: number; // 继续原场景的行号
99
}
10+
11+
/**
12+
* 场景栈条目接口 (兼容性别名)
13+
* @interface ISceneEntry
14+
*/
15+
export interface ISceneEntry extends sceneEntry {}

packages/parser/src/interface/sceneInterface.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* 语句类型
33
*/
4-
import { sceneEntry } from './runtimeInterface';
4+
import { sceneEntry, ISceneEntry } from './runtimeInterface';
55
import { fileType } from './assets';
66

77
export enum commandType {
@@ -38,7 +38,7 @@ export enum commandType {
3838
setTransition,
3939
getUserInput,
4040
applyStyle,
41-
wait
41+
wait,
4242
}
4343

4444
/**
@@ -92,7 +92,7 @@ export interface IScene {
9292
*/
9393
export interface ISceneData {
9494
currentSentenceId: number; // 当前语句ID
95-
sceneStack: Array<sceneEntry>; // 场景栈
95+
sceneStack: Array<ISceneEntry>; // 场景栈
9696
currentScene: IScene; // 当前场景数据
9797
}
9898

packages/parser/test/parser.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,62 @@ test("say statement", async () => {
194194
subScene: []
195195
});
196196
});
197+
198+
test("wait command", async () => {
199+
const parser = new SceneParser((assetList) => {
200+
}, (fileName, assetType) => {
201+
return fileName;
202+
}, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
203+
204+
const result = parser.parse(`wait:1000;`, 'test', 'test');
205+
expect(result.sentenceList).toContainEqual({
206+
command: commandType.wait,
207+
commandRaw: "wait",
208+
content: "1000",
209+
args: [],
210+
sentenceAssets: [],
211+
subScene: []
212+
});
213+
});
214+
215+
test("changeFigure with duration and animation args", async () => {
216+
const parser = new SceneParser((assetList) => {
217+
}, (fileName, assetType) => {
218+
return fileName;
219+
}, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
220+
221+
const result = parser.parse(`changeFigure:stand.png -duration=1000 -enter=fadeIn -exit=fadeOut;`, 'test', 'test');
222+
expect(result.sentenceList).toContainEqual({
223+
command: commandType.changeFigure,
224+
commandRaw: "changeFigure",
225+
content: "stand.png",
226+
args: [
227+
{ key: 'duration', value: 1000 },
228+
{ key: 'enter', value: 'fadeIn' },
229+
{ key: 'exit', value: 'fadeOut' }
230+
],
231+
sentenceAssets: [{ name: "stand.png", url: 'stand.png', type: fileType.figure, lineNumber: 0 }],
232+
subScene: []
233+
});
234+
});
235+
236+
test("changeBg with animation parameters", async () => {
237+
const parser = new SceneParser((assetList) => {
238+
}, (fileName, assetType) => {
239+
return fileName;
240+
}, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);
241+
242+
const result = parser.parse(`changeBg:background.jpg -duration=2000 -enter=slideIn -transform={"alpha":0.8};`, 'test', 'test');
243+
expect(result.sentenceList).toContainEqual({
244+
command: commandType.changeBg,
245+
commandRaw: "changeBg",
246+
content: "background.jpg",
247+
args: [
248+
{ key: 'duration', value: 2000 },
249+
{ key: 'enter', value: 'slideIn' },
250+
{ key: 'transform', value: '{"alpha":0.8}' }
251+
],
252+
sentenceAssets: [{ name: "background.jpg", url: 'background.jpg', type: fileType.background, lineNumber: 0 }],
253+
subScene: []
254+
});
255+
});

0 commit comments

Comments
 (0)