Skip to content

Conversation

@HardyNLee
Copy link
Contributor

介绍

changeBg changeFigure url 未更改时, -transform 参数会像 setTransform 命令一样工作

相当于以前的

changFigure: stand.webp -id=aaa -transform={"position":{"x":-500}};
setTransform: {"position":{"x":500}} -target=aaa -duration=1500;

现在可以写成

changFigure: stand.webp -id=aaa -transform={"position":{"x":-500}};
changFigure: stand.webp -id=aaa -transform={"position":{"x":500}} -duration=1500;

这对于一边更改立绘/背景参数 (如 zIndex, live2d 的 motion expression), 一边做变换效果的情况, 可以简写为一行, 同时也减少了很多新手问 为什么我设置(changeFigure)的变换效果没有动画 的情况

因为有 isUrlChanged 做隔离, 所以按理说应该不会影响入场退场的逻辑

changeBg changeFigure 添加了 writeDefault 参数, 但是 keep 暂时不加, 我总感觉有点隐式的问题, 等我以后相通了再加

这个 PR 实际上与 #863 有一点点重叠, 不过问题不大

编辑器那边等这个 PR 合并后, 再移除掉那个"请用设置效果命令" 的提示

@gemini-code-assist
Copy link

Summary of Changes

Hello @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!

此拉取请求旨在增强 WebGAL 引擎的动画控制能力,特别是针对 changeBgchangeFigure 命令。通过使这些命令的 -transform 参数在资源URL不变时能够执行连续的动画变换,它极大地提高了脚本的灵活性和简洁性。这一改进不仅简化了复杂的动画序列,还解决了用户在使用这些命令时常见的动画行为误解,使得动画效果的实现更加直观和强大。

Highlights

  • 统一变换参数行为: 当背景或立绘的URL未改变时,changeBgchangeFigure 命令的 -transform 参数现在将像 setTransform 命令一样工作,允许在不切换资源的情况下应用动画变换。
  • 简化动画脚本: 此更改允许开发者将资源参数(如 zIndex、Live2D 动作/表情)的修改与变换效果结合到一行命令中,从而简化脚本编写并减少新用户关于动画不生效的困惑。
  • 新增 writeDefault 参数: 为 changeBgchangeFigure 命令添加了 writeDefault 参数,用于控制动画行为。
  • 动画注册与移除重构: 引入了 registerTimelineAnimationremoveTimelineAnimation 两个新函数,用于统一管理时间线动画的注册和移除逻辑,并在 setAnimation, setTempAnimation, setTransform, changeBg, changeFigure 中进行了应用。

🧠 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.

Changelog
  • packages/webgal/src/Core/Modules/animationFunctions.ts
    • 新增 registerTimelineAnimation 函数,用于统一注册时间线动画。
    • 新增 removeTimelineAnimation 函数,用于统一移除时间线动画。
  • packages/webgal/src/Core/gameScripts/changeBg/index.ts
    • 引入 writeDefault 参数,控制背景变换动画的默认写入行为。
    • 当背景URL未改变时,transform 参数现在会通过 registerTimelineAnimation 注册为时间线动画。
    • 移除了在变换动画中强制设置初始 alpha 为0的逻辑,以支持更灵活的动画效果。
    • 更新了 stopFunction 逻辑,根据URL是否改变选择调用 stopPresetAnimationOnTargetremoveTimelineAnimation
  • packages/webgal/src/Core/gameScripts/changeFigure.ts
    • 引入 writeDefault 参数,控制立绘变换动画的默认写入行为。
    • 当立绘URL未改变时,transform 参数现在会通过 registerTimelineAnimation 注册为时间线动画。
    • 移除了在变换动画中强制设置初始 alpha 为0的逻辑,以支持更灵活的动画效果。
    • 更新了 stopFunction 逻辑,根据URL是否改变选择调用 stopPresetAnimationOnTargetremoveTimelineAnimation
  • packages/webgal/src/Core/gameScripts/setAnimation.ts
    • 重构动画注册和移除逻辑,现在使用 registerTimelineAnimationremoveTimelineAnimation
    • 移除了未使用的 startDialogKey 变量。
  • packages/webgal/src/Core/gameScripts/setTempAnimation.ts
    • 重构动画注册和移除逻辑,现在使用 registerTimelineAnimationremoveTimelineAnimation
    • 移除了未使用的 startDialogKey 变量。
  • packages/webgal/src/Core/gameScripts/setTransform.ts
    • 重构动画注册和移除逻辑,现在使用 registerTimelineAnimationremoveTimelineAnimation
    • 移除了未使用的 startDialogKey 变量。
Activity
  • 作者 HardyNLee 创建了此拉取请求,旨在扩展 changeBgchangeFigure 命令的 transform 参数功能,使其在不更改资源URL时也能像 setTransform 一样工作。
  • 此拉取请求还引入了 writeDefault 参数,并对多个动画相关的脚本文件进行了重构,以统一动画注册和移除的逻辑。
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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

这个 PR 扩展了 transform 参数的用法,允许在不改变图像 URL 的情况下应用变换,这是一个很好的功能增强。同时,代码中通过提取 registerTimelineAnimationremoveTimelineAnimation 函数来重构动画逻辑,减少了重复代码,值得称赞。
不过,在重构过程中,setAnimationsetTempAnimationsetTransform 中处理 keep 参数的逻辑似乎引入了一个 bug,导致 keep 功能可能无法按预期工作。此外,在 changeBgchangeFigure 中仍然存在一些代码重复,可以进一步优化。
我已经在具体的代码行上提出了一些修改建议,希望能帮助你完善这个功能。

Comment on lines 114 to 140
// eslint-disable-next-line max-params
export function registerTimelineAnimation(
animationName: string,
animationKey: string,
target: string,
animationDuration: number,
writeDefault: boolean,
keep: boolean,
keepAnimationStopped: boolean,
) {
setTimeout(() => {
if (keep && keepAnimationStopped) {
return;
}
WebGAL.gameplay.pixiStage?.stopPresetAnimationOnTarget(target);
const animationObj: IAnimationObject | null = getAnimationObject(
animationName,
target,
animationDuration,
writeDefault,
);
if (animationObj) {
logger.debug(`动画${animationName}作用在${target}`, animationDuration);
WebGAL.gameplay.pixiStage?.registerAnimation(animationObj, animationKey, target);
}
}, 0);
}

Choose a reason for hiding this comment

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

critical

registerTimelineAnimation 函数在处理 keepAnimationStopped 时存在逻辑问题。keepAnimationStopped 是通过值传递的,因此在 setTimeout 的闭包中,它将始终使用初始值(即 false),这会破坏防止重新注册“保留”的动画的预期逻辑。我建议重构此函数,移除 setTimeout 和与 keep 相关的逻辑,将该职责移回调用方。这将修复闭包问题,同时保持核心动画注册逻辑的封装。

export function registerTimelineAnimation(
  animationName: string,
  animationKey: string,
  target: string,
  animationDuration: number,
  writeDefault: boolean,
) {
  WebGAL.gameplay.pixiStage?.stopPresetAnimationOnTarget(target);
  const animationObj: IAnimationObject | null = getAnimationObject(
    animationName,
    target,
    animationDuration,
    writeDefault,
  );
  if (animationObj) {
    logger.debug(`动画${animationName}作用在${target}`, animationDuration);
    WebGAL.gameplay.pixiStage?.registerAnimation(animationObj, animationKey, target);
  }
}

Comment on lines 32 to 40
registerTimelineAnimation(
animationName,
animationKey,
target,
animationDuration,
writeDefault,
keep,
keepAnimationStopped,
);

Choose a reason for hiding this comment

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

critical

根据我对 animationFunctions.ts 中提出的建议,您应该在此处将对 registerTimelineAnimation 的调用包装在 setTimeout 中,以恢复 keepAnimationStopped 的正确行为。

  setTimeout(() => {
    if (keep && keepAnimationStopped) {
      return;
    }
    registerTimelineAnimation(
      animationName,
      animationKey,
      target,
      animationDuration,
      writeDefault,
    );
  }, 0);

Comment on lines 43 to 51
registerTimelineAnimation(
animationName,
animationKey,
target,
animationDuration,
writeDefault,
keep,
keepAnimationStopped,
);

Choose a reason for hiding this comment

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

critical

根据我对 animationFunctions.ts 中提出的建议,您应该在此处将对 registerTimelineAnimation 的调用包装在 setTimeout 中,以恢复 keepAnimationStopped 的正确行为。

  setTimeout(() => {
    if (keep && keepAnimationStopped) {
      return;
    }
    registerTimelineAnimation(
      animationName,
      animationKey,
      target,
      animationDuration,
      writeDefault,
    );
  }, 0);

Comment on lines 49 to 57
registerTimelineAnimation(
animationName,
animationKey,
target,
animationDuration,
writeDefault,
keep,
keepAnimationStopped,
);

Choose a reason for hiding this comment

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

critical

根据我对 animationFunctions.ts 中提出的建议,您应该在此处将对 registerTimelineAnimation 的调用包装在 setTimeout 中,以恢复 keepAnimationStopped 的正确行为。

  setTimeout(() => {
    if (keep && keepAnimationStopped) {
      return;
    }
    registerTimelineAnimation(
      animationName,
      animationKey,
      target,
      animationDuration,
      writeDefault,
    );
  }, 0);

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