Skip to content

fix: filter timeline segment#924

Open
HardyNLee wants to merge 1 commit intoOpenWebGAL:devfrom
HardyNLee:fix/filter-timeline-segment
Open

fix: filter timeline segment#924
HardyNLee wants to merge 1 commit intoOpenWebGAL:devfrom
HardyNLee:fix/filter-timeline-segment

Conversation

@HardyNLee
Copy link
Copy Markdown
Contributor

介绍

修复 transform 含有非 number 类型字段时,popmotion 连带游戏卡死的情况

popmotion 似乎只支持 number 和一小部分特定格式的 string,并且只提取第一层属性,其他类型都会报错。position 和 scale 因为已经自行提取出来了,没什么问题

更改

在生成 timeline 的 values 前先对每个 segment 过滤掉所有值不是 number 类型的字段。

测试

changeBg:bg.webp;
changeFigure:stand.png -transform={"postion":{"x":500}}; 这里 position 拼错了,所以会当成普通对象
changeFigure:stand2.png -transform={"aaa":true};

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the timeline generation logic in packages/webgal to filter out non-numeric properties from animation segments before they are processed by the animation engine. A review comment suggests explicitly excluding the duration property from the filtered values, as it is a numeric property that should not be passed to the animation interpolation logic to avoid unnecessary calculations.

currentDelay += segmentDuration;
const { position, scale, ...segmentValues } = segment;
// 移除所有值类型不是 number 的属性
const filteredSegmentValues = omitBy(segmentValues, (value) => typeof value !== 'number');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这里的过滤逻辑虽然排除了非数字类型的属性(如 ease),但 duration 也是数字类型,因此会被保留在 filteredSegmentValues 中。这会导致 duration 被传递给 popmotion 进行插值动画,并在 onUpdate 中不断赋值给 PIXI 容器。由于 duration 并不是 PIXI 容器的变换属性,建议在过滤时显式排除它,以避免不必要的计算和属性赋值。

Suggested change
const filteredSegmentValues = omitBy(segmentValues, (value) => typeof value !== 'number');
const filteredSegmentValues = omitBy(segmentValues, (value, key) => typeof value !== 'number' || key === 'duration');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant