-
Notifications
You must be signed in to change notification settings - Fork 13
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
add Custombutton #31
add Custombutton #31
Conversation
Here's the translation of the review guide to Chinese: 审阅者指南 by Sourcery此拉取请求引入了一个实现自定义按钮纹理加载器的新模块。更改包括创建一个新的 CustomButton 类,该类从指定目录加载纹理,将它们初始化到字典中,并应用 Harmony 补丁以覆盖 ButtonControllerBase 和 ButtonManager 中默认的按钮纹理加载过程。 ButtonControllerBase 上 CustomButton 补丁的序列图sequenceDiagram
participant GS as GameSystem
participant BC as ButtonControllerBase
participant CB as CustomButton
GS->>BC: Call LoadDefaultResources()
alt Harmony patch active
BC->>CB: Invoke LoadDefaultResourcesPrefix()
CB->>CB: Reflect to obtain FlatButtonParam field
CB->>CB: Iterate over button info and replace textures
CB->>BC: Set _isFlatButtonLoaded to true
end
Note over CB,BC: Custom textures are applied if available, otherwise default textures loaded
ButtonManager 上 CustomButton 补丁的序列图sequenceDiagram
participant GS as GameSystem
participant BM as ButtonManager
participant CB as CustomButton
GS->>BM: Call Initialize()
alt Harmony patch active
BM->>CB: Invoke ButtonManagerInitializePostfix(__instance)
CB->>CB: Use reflection to access _containers and Container's SpritePath
CB->>CB: Iterate container values, replacing sprites with custom ones if available
end
Note over CB,BM: Custom textures override default container sprites when available
CustomButton 模块的更新类图classDiagram
class CustomButton {
<<static>>
- string buttonDir = "LocalAssets/Buttons"
- Dictionary~string, Sprite~ spriteDict
- bool isInitialized
+ void OnBeforePatch()
- void Initialize()
+ void LoadDefaultResourcesPrefix() <<HarmonyPrefix, HarmonyPatch>>
+ void ButtonManagerInitializePostfix(ButtonManager __instance) <<HarmonyPostfix, HarmonyPatch>>
}
文件级更改
提示和命令与 Sourcery 交互
自定义您的体验访问您的仪表板以:
获取帮助Original review guide in EnglishReviewer's Guide by SourceryThis pull request introduces a new module that implements a custom button texture loader. The changes include creating a new CustomButton class that loads textures from a specified directory, initializing them into a dictionary, and applying Harmony patches to override the default button texture loading process in ButtonControllerBase and ButtonManager. Sequence diagram for CustomButton patch on ButtonControllerBase.LoadDefaultResourcessequenceDiagram
participant GS as GameSystem
participant BC as ButtonControllerBase
participant CB as CustomButton
GS->>BC: Call LoadDefaultResources()
alt Harmony patch active
BC->>CB: Invoke LoadDefaultResourcesPrefix()
CB->>CB: Reflect to obtain FlatButtonParam field
CB->>CB: Iterate over button info and replace textures
CB->>BC: Set _isFlatButtonLoaded to true
end
Note over CB,BC: Custom textures are applied if available, otherwise default textures loaded
Sequence diagram for CustomButton patch on ButtonManager.InitializesequenceDiagram
participant GS as GameSystem
participant BM as ButtonManager
participant CB as CustomButton
GS->>BM: Call Initialize()
alt Harmony patch active
BM->>CB: Invoke ButtonManagerInitializePostfix(__instance)
CB->>CB: Use reflection to access _containers and Container's SpritePath
CB->>CB: Iterate container values, replacing sprites with custom ones if available
end
Note over CB,BM: Custom textures override default container sprites when available
Updated class diagram for the CustomButton moduleclassDiagram
class CustomButton {
<<static>>
- string buttonDir = "LocalAssets/Buttons"
- Dictionary~string, Sprite~ spriteDict
- bool isInitialized
+ void OnBeforePatch()
- void Initialize()
+ void LoadDefaultResourcesPrefix() <<HarmonyPrefix, HarmonyPatch>>
+ void ButtonManagerInitializePostfix(ButtonManager __instance) <<HarmonyPostfix, HarmonyPatch>>
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
嘿 @ck2739046 - 我已经审查了你的更改 - 以下是一些反馈:
总体评论:
- 在使用反射调用之前,请验证它们返回非空值(例如,对于字段和属性),以防止可能出现的空引用异常。
以下是我在审查期间查看的内容
- 🟡 一般性问题:发现1个问题
- 🟢 安全性:一切看起来都很好
- 🟢 测试:一切看起来都很好
- 🟢 复杂性:一切看起来都很好
- 🟢 文档:一切看起来都很好
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English
Hey @ck2739046 - I've reviewed your changes - here's some feedback:
Overall Comments:
- Verify that reflection calls return non-null values (e.g., for fields and properties) before using them to prevent potential null reference exceptions.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
||
public static void OnBeforePatch() { Initialize(); } | ||
|
||
private static void Initialize() |
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.
建议: 纹理加载中的异常处理
虽然 catch 块记录了异常,但请考虑是否可以添加更多上下文,例如文件特定的详细信息,这可以帮助在批量文件处理期间更精确地定位纹理加载问题。
建议的实现:
foreach (var file in Directory.EnumerateFiles(buttonDir_r, "*.png")) {
try {
var fileName = Path.GetFileNameWithoutExtension(file);
var bytes = File.ReadAllBytes(file);
// (纹理处理逻辑的其余部分)
}
catch (Exception ex)
{
MelonLogger.Error($"加载纹理文件 '{file}' 时出错:{ex}");
}
验证你的纹理处理逻辑的其余部分是否仍在内部 try 块中。
另外,确保任何潜在的外部依赖项都了解处理逻辑,以便后续文件的处理不受影响。
Original comment in English
suggestion: Exception handling in texture loading
While the catch block logs exceptions, consider if additional context, such as file-specific details, could help pinpoint issues during texture loading, especially during bulk file processing.
Suggested implementation:
foreach (var file in Directory.EnumerateFiles(buttonDir_r, "*.png")) {
try {
var fileName = Path.GetFileNameWithoutExtension(file);
var bytes = File.ReadAllBytes(file);
// (rest of texture processing logic)
}
catch (Exception ex)
{
MelonLogger.Error($"Error loading texture file '{file}': {ex}");
}
Verify that the rest of your texture processing logic inside the foreach loop remains inside the inner try block.
Also, ensure that any potential dependencies outside are aware of the handling logic so that the processing of subsequent files continues unaffected.
Summary by Sourcery
新功能:
Original summary in English
Summary by Sourcery
New Features: