Skip to content

Conversation

@HardyNLee
Copy link
Contributor

介绍

为立绘添加 混合模式 参数, 可用的值有:

  • normal 正常(默认值)
  • add 线性减淡
  • multiply 正片叠底
  • screen 滤色
image

测试

简单测试

changeBg:bg.webp -transform={"brightness":0.5};
changeFigure:stand.webp -id=aaa;
changeFigure:stand.webp -id=aaa -blendMode=add;
changeFigure:stand.webp -id=aaa -blendMode=multiply;
changeFigure:stand.webp -id=aaa -blendMode=screen;
changeFigure:stand.webp -id=aaa -blendMode=normal;

稍好看一点的测试

请将下面两张图片放到 /game/figure/shapes

linear_transparent.webp radial_transparent.webp
changeBg:bg.webp -transform={"brightness":0.829,"gamma":0.634};
changeFigure:stand.png -id=aaa -transform={"position":{"y":160},"scale":{"x":1.5,"y":1.5},"brightness":0.89,"contrast":1.037,"gamma":0.646,"bevelRed":255,"bevelGreen":255,"bevelBlue":255} -zIndex=3;
; 背景暖光
changeFigure:shapes/radial_transparent.webp -id=bg_warm_light -transform={"position":{"x":-390,"y":-549},"scale":{"x":2,"y":2},"alpha":0.762,"brightness":0.683,"colorRed":255,"colorGreen":214,"colorBlue":148} -zIndex=0 -blendMode=add;
; 背景冷光
changeFigure:shapes/linear_transparent.webp -id=bg_cold_light -transform={"position":{"x":793,"y":598},"scale":{"x":2.5,"y":1.756},"rotation":2.528,"alpha":1,"brightness":2,"colorRed":120,"colorGreen":69,"colorBlue":255} -zIndex=1 -blendMode=multiply;
; 脸部亮光
changeFigure:shapes/radial_transparent.webp -id=face_light -transform={"position":{"x":-110,"y":-183},"scale":{"x":0.963,"y":1.098},"alpha":0.128,"brightness":1.841,"colorRed":255,"colorGreen":111,"colorBlue":51} -zIndex=4 -blendMode=screen;

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

此拉取请求引入了一项新功能,允许用户为游戏中的立绘指定混合模式。通过在 changeFigure 命令中添加 blendMode 参数,开发者现在可以利用 PixiJS 提供的多种混合效果,如“正常”、“线性减淡”、“正片叠底”和“滤色”,从而极大地增强视觉表现力和艺术效果。这项改动涉及从游戏脚本参数解析到核心渲染逻辑以及状态管理接口的全面更新,确保了混合模式功能的完整集成。

Highlights

  • 新增混合模式参数: 为立绘(figure)引入了新的 blendMode 参数,支持 'normal'(正常)、'add'(线性减淡)、'multiply'(正片叠底)和 'screen'(滤色)四种混合模式。
  • PixiJS 容器混合模式实现: 在 WebGALPixiContainer 中实现了 blendMode 的 getter 和 setter,负责将字符串形式的混合模式名称转换为 PixiJS 内部的 PIXI.BLEND_MODES 枚举值,并处理未知模式的警告。
  • 游戏脚本集成: 更新了 changeFigure 游戏脚本,使其能够解析传入的 blendMode 参数,并将其作为立绘元数据进行存储和应用,同时为未指定的混合模式设置默认值 'normal'。
  • 舞台渲染逻辑更新: 修改了 PixiControlleruseSetFigure 钩子,确保在创建或更新立绘时,能够正确地从元数据中读取并应用 blendMode 到相应的 PixiJS 容器上。
  • 接口定义扩展: 在 IFigureMetadata 接口中添加了可选的 blendMode?: string; 属性,以支持在状态管理中存储立绘的混合模式信息。

🧠 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 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 为立绘添加了 blendMode(混合模式)功能,允许实现更多样的视觉效果。整体实现逻辑清晰,涉及了参数解析、状态管理和最终的 PIXI.js 渲染。代码改动分布在多个文件中,都与新功能的实现紧密相关。

我发现了一些可以改进的地方,主要关于代码的可维护性和减少重复。我已经提出了具体的建议,希望能帮助提升代码质量。

Comment on lines +670 to +672
if (metadata.blendMode) {
thisFigureContainer.blendMode = metadata.blendMode;
}

Choose a reason for hiding this comment

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

medium

这部分应用元数据的逻辑在 addLive2dFigureaddFigure 方法中是重复的。为了减少代码重复并提高可维护性,建议将这部分逻辑提取到一个私有辅助方法中。

例如,可以创建一个 applyFigureMetadata 方法:

private applyFigureMetadata(container: WebGALPixiContainer, key: string) {
  const metadata = this.getFigureMetadataByKey(key);
  if (metadata) {
    if (metadata.zIndex !== undefined) {
      container.zIndex = metadata.zIndex;
    }
    if (metadata.blendMode) {
      container.blendMode = metadata.blendMode;
    }
  }
}

然后在 addFigureaddLive2dFigure 中调用 this.applyFigureMetadata(thisFigureContainer, key); 来替代重复的代码块。

Comment on lines +351 to +384
public get blendMode(): string {
switch (this.alphaFilter.blendMode) {
case PIXI.BLEND_MODES.NORMAL:
return 'normal';
case PIXI.BLEND_MODES.ADD:
return 'add';
case PIXI.BLEND_MODES.MULTIPLY:
return 'multiply';
case PIXI.BLEND_MODES.SCREEN:
return 'screen';
default:
logger.warn(`Unknown blend mode: ${this.alphaFilter.blendMode}, returning normal.`);
return 'normal';
}
}
public set blendMode(v: string) {
switch (v) {
case 'normal':
this.alphaFilter.blendMode = PIXI.BLEND_MODES.NORMAL;
break;
case 'add':
this.alphaFilter.blendMode = PIXI.BLEND_MODES.ADD;
break;
case 'multiply':
this.alphaFilter.blendMode = PIXI.BLEND_MODES.MULTIPLY;
break;
case 'screen':
this.alphaFilter.blendMode = PIXI.BLEND_MODES.SCREEN;
break;
default:
logger.warn(`Unknown blend mode: ${v}, setting to normal.`);
this.alphaFilter.blendMode = PIXI.BLEND_MODES.NORMAL;
}
}

Choose a reason for hiding this comment

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

medium

为了提高代码的可维护性和可扩展性,建议使用映射(Map/Object)来处理字符串和 PIXI.BLEND_MODES 之间的转换,而不是使用 switch 语句。这样,当未来需要添加更多混合模式时,只需更新映射对象即可,代码会更简洁。

为了获得最佳性能,建议将这些映射对象提取为类的静态属性。

  public get blendMode(): string {
    const reverseBlendModeMap: Record<number, string> = {
      [PIXI.BLEND_MODES.NORMAL]: 'normal',
      [PIXI.BLEND_MODES.ADD]: 'add',
      [PIXI.BLEND_MODES.MULTIPLY]: 'multiply',
      [PIXI.BLEND_MODES.SCREEN]: 'screen',
    };
    const blendModeName = reverseBlendModeMap[this.alphaFilter.blendMode];
    if (blendModeName) {
      return blendModeName;
    }
    logger.warn(`Unknown blend mode: ${this.alphaFilter.blendMode}, returning normal.`);
    return 'normal';
  }
  public set blendMode(v: string) {
    const blendModeMap: Record<string, PIXI.BLEND_MODES> = {
      normal: PIXI.BLEND_MODES.NORMAL,
      add: PIXI.BLEND_MODES.ADD,
      multiply: PIXI.BLEND_MODES.MULTIPLY,
      screen: PIXI.BLEND_MODES.SCREEN,
    };
    const blendMode = blendModeMap[v];
    if (blendMode !== undefined) {
      this.alphaFilter.blendMode = blendMode;
    } else {
      logger.warn(`Unknown blend mode: ${v}, setting to normal.`);
      this.alphaFilter.blendMode = PIXI.BLEND_MODES.NORMAL;
    }
  }

@MakinoharaShoko MakinoharaShoko merged commit ee8c6fe into OpenWebGAL:dev Jan 27, 2026
1 check passed
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.

2 participants