-
-
Notifications
You must be signed in to change notification settings - Fork 315
feat: add blend mode argument #844
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
feat: add blend mode argument #844
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
🧠 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 为立绘添加了 blendMode(混合模式)功能,允许实现更多样的视觉效果。整体实现逻辑清晰,涉及了参数解析、状态管理和最终的 PIXI.js 渲染。代码改动分布在多个文件中,都与新功能的实现紧密相关。
我发现了一些可以改进的地方,主要关于代码的可维护性和减少重复。我已经提出了具体的建议,希望能帮助提升代码质量。
| if (metadata.blendMode) { | ||
| thisFigureContainer.blendMode = metadata.blendMode; | ||
| } |
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.
这部分应用元数据的逻辑在 addLive2dFigure 和 addFigure 方法中是重复的。为了减少代码重复并提高可维护性,建议将这部分逻辑提取到一个私有辅助方法中。
例如,可以创建一个 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;
}
}
}然后在 addFigure 和 addLive2dFigure 中调用 this.applyFigureMetadata(thisFigureContainer, key); 来替代重复的代码块。
| 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; | ||
| } | ||
| } |
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.
为了提高代码的可维护性和可扩展性,建议使用映射(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;
}
}
介绍
为立绘添加 混合模式 参数, 可用的值有:
测试
简单测试
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下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;