-
-
Notifications
You must be signed in to change notification settings - Fork 315
fix: 修复 changeBg 与 changeFigure 的 exit 设置不能正常生效的问题 #827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @ChangeSuger, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在修复 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
你好,感谢你的贡献。这个 PR 很好地解决了 changeBg 和 changeFigure 的 exit 动画无法正常生效的问题。通过在 removeAnimationSettingsByTarget 中保留旧的动画设置(使用 -off 后缀),并在 getEnterExitAnimation 中正确查找这些设置,确保了退场动画能够使用正确的参数。
代码修改的思路清晰,解决了根本问题。我只在 animationFunctions.ts 中发现了一个可以优化的地方,即避免重复的数组查找操作,这有助于提升代码性能和可读性。具体建议请看我的评论。
总体来说,这是一个高质量的修复,做得很好!
| duration = | ||
| webgalStore.getState().stage.animationSettings.find((setting) => setting.target + '-off' === target) | ||
| ?.exitDuration ?? duration; | ||
| webgalStore.getState().stage.animationSettings.find((setting) => setting.target === target)?.exitDuration ?? | ||
| duration; | ||
| // 走默认动画 | ||
| let animation: IAnimationObject | null = generateUniversalSoftOffAnimationObj(realTarget ?? target, duration); | ||
| const animationName = webgalStore | ||
| .getState() | ||
| .stage.animationSettings.find((setting) => setting.target + '-off' === target)?.exitAnimationName; | ||
| .stage.animationSettings.find((setting) => setting.target === target)?.exitAnimationName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为了提高代码的可读性和性能,建议将 webgalStore.getState().stage.animationSettings.find(...) 的查找操作提取到一个变量中。这样可以避免重复访问 Redux store 和遍历数组,使代码更高效简洁。
| duration = | |
| webgalStore.getState().stage.animationSettings.find((setting) => setting.target + '-off' === target) | |
| ?.exitDuration ?? duration; | |
| webgalStore.getState().stage.animationSettings.find((setting) => setting.target === target)?.exitDuration ?? | |
| duration; | |
| // 走默认动画 | |
| let animation: IAnimationObject | null = generateUniversalSoftOffAnimationObj(realTarget ?? target, duration); | |
| const animationName = webgalStore | |
| .getState() | |
| .stage.animationSettings.find((setting) => setting.target + '-off' === target)?.exitAnimationName; | |
| .stage.animationSettings.find((setting) => setting.target === target)?.exitAnimationName; | |
| const animationSetting = webgalStore.getState().stage.animationSettings.find((setting) => setting.target === target); | |
| duration = animationSetting?.exitDuration ?? duration; | |
| // 走默认动画 | |
| let animation: IAnimationObject | null = generateUniversalSoftOffAnimationObj(realTarget ?? target, duration); | |
| const animationName = animationSetting?.exitAnimationName; |
背景
目前的 bg 和 figure 的 exit 动画设置都不能正常生效,如果想正常生效,需要在下一个 changeBg 或 changeFigure 设置相同的 exit 动画(用 setTransition 也一样),最小复现示例(替换
start.txt即可):问题排查 & 修复思路
核心问题是目前的 bg 和 figure 的切换依赖于相关的状态:“旧bg”的设定在相关指令中就被清除了,取而代之的是“新bg”的设定,在这些状态变更后,才依次执行“旧bg”的 exit 与“新bg” 的 enter,故两者在
getEnterExitAnimation时拿到的都是“新bg”的设定。WebGAL/packages/webgal/src/Core/gameScripts/changeBg/index.ts
Line 49 in 23e98d9
修复思路是将原先的仅移除操作改为在移除的同时,使用
${target}-off存储“旧bg”的设定(重复设定时移除之前的设定),保证在 exit 中能拿到“旧bg”的设定。测试
使用最小复现示例的 txt 文件就可以进行测试。
这个修改方案的缺点是会往状态里增加一倍的 animationSetting,但是想不到别的更好的方案了。