-
-
Notifications
You must be signed in to change notification settings - Fork 311
feat: add set effect debug command #788
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
Conversation
Summary of ChangesHello @HardyNLee, 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
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 新增了 DebugCommand.SET_EFFECT 命令,用于从编辑器接收效果数据并实时更新舞台,这是一个很棒的功能。代码实现整体不错,但在处理从 WebSocket 收到的消息时,有可以改进的地方。我对 webSocketFunc.ts 中的效果处理逻辑提出了一些建议,主要是关于增加数据校验以提高代码的健壮性,以及重构变换合并的逻辑使其更清晰、更易于维护。请查看具体的代码注释。
| const effect = JSON.parse(message.message) as IEffect; | ||
| const targetEffect = webgalStore.getState().stage.effects.find((e) => e.target === effect.target); | ||
| const targetTransform = targetEffect?.transform ? targetEffect.transform : baseTransform; | ||
| const newTransform = { | ||
| ...targetTransform, | ||
| ...(effect.transform ?? {}), | ||
| position: { | ||
| ...targetTransform.position, | ||
| ...(effect.transform?.position ?? {}), | ||
| }, | ||
| scale: { | ||
| ...targetTransform.scale, | ||
| ...(effect.transform?.scale ?? {}), | ||
| }, | ||
| }; | ||
| webgalStore.dispatch(stageActions.updateEffect({ target: effect.target, transform: newTransform })); |
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.
这部分代码有两点可以改进,以提高代码的健壮性和可读性:
-
增加数据校验:
JSON.parse(message.message) as IEffect是一个类型断言,它假设了message.message的内容总是符合IEffect接口。如果收到的 JSON 字符串虽然合法但缺少target属性,后续代码(如effect.target)可能会因为undefined而出错。建议在解析后增加一个简单的校验,确保effect对象和它的target属性存在且类型正确。 -
优化变换合并逻辑:当前合并
transform的方式有些冗余。...(effect.transform ?? {})会展开position和scale属性,但它们随后又被显式地重写了。我们可以使用对象解构来分离出嵌套的position和scale对象,使代码更简洁,意图也更清晰。
我已经将这两点改进合并到了下面的代码建议中。
const parsedEffect = JSON.parse(message.message);
if (!parsedEffect || typeof parsedEffect.target !== 'string') {
logger.error(`Invalid effect object received: ${message.message}`);
return;
}
const effect = parsedEffect as IEffect;
const targetEffect = webgalStore.getState().stage.effects.find((e) => e.target === effect.target);
const targetTransform = targetEffect?.transform ?? baseTransform;
const { position: newPosition, scale: newScale, ...restOfTransform } = effect.transform ?? {};
const newTransform = {
...targetTransform,
...restOfTransform,
position: {
...targetTransform.position,
...newPosition,
},
scale: {
...targetTransform.scale,
...newScale,
},
};
webgalStore.dispatch(stageActions.updateEffect({ target: effect.target, transform: newTransform }));
介绍
新增
DebugCommand.SET_EFFECT用于处理来自编辑器的 IEffect 字符串, 实现实时效果预览Tip
此 PR 是 OpenWebGAL/WebGAL_Terre#495 的前置条件, 详情见那边