Skip to content

[+]为LoadLocalImages增添了区域图片的直读#93

Merged
clansty merged 2 commits intoMuNET-OSS:mainfrom
HawkingLaughing:LoadMoreLocalImages
Nov 27, 2025
Merged

[+]为LoadLocalImages增添了区域图片的直读#93
clansty merged 2 commits intoMuNET-OSS:mainfrom
HawkingLaughing:LoadMoreLocalImages

Conversation

@HawkingLaughing
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

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

此 PR 旨在增强 LoadLocalImages 模块的功能,使其能够直接加载和管理本地的区域地图背景图片。通过引入新的字典扩展方法、专门的地图背景路径存储以及相应的图片处理和转换方法,该改动使得游戏能够更灵活地使用自定义地图背景资源。此外,通过对 AssetManager 的打补丁,确保了这些本地资源能够无缝地集成到游戏资产加载流程中。

Highlights

  • 新的扩展方法: 为嵌套字典 Dictionary<TKey1, Dictionary<TKey2, TValue>> 添加了 GetExValueOrDefault 扩展方法,以简化对多层字典值的安全访问。
  • 地图背景图片加载: 新增了对本地地图背景图片(mapBgPaths)的直接读取支持,允许从指定目录加载自定义地图背景资源。
  • 地图背景处理方法: 实现了 GetMapBgPathGetMapBgTexture2DGetMapBgSprite 方法,用于检索地图背景图片的路径,并将其转换为 Texture2DSprite 对象。
  • AssetManager 补丁: 引入了一个 Harmony 补丁 MapLoader,拦截 AssetManager.GetMapBgSprite 方法,使其能够优先加载本地提供的地图背景精灵,从而实现自定义地图背景功能。
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为LoadLocalImages添加了直接读取区域图片的功能,并通过Harmony Patch拦截了游戏原有的图片加载方法。代码改动清晰地实现了目标功能。我发现了一些可以改进的地方:

  • 文件路径的拼接方式存在风险,建议使用更安全的方法。
  • 部分代码中存在冗余的逻辑,可以简化以提高代码清晰度。
  • 循环中的日志记录可能会产生性能问题。

具体的修改建议请见下方评论。

var id = mapId.ToString("000000");
Sprite sprite = GetMapBgSprite(id, filename);
if(sprite == null) return true;
__result = sprite ?? __instance.LoadAsset<Sprite>($"Map/Sprite/BG/" + id + "/" + filename + ".png");

Choose a reason for hiding this comment

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

high

这里的空值合并运算符 ?? 是多余的。因为在上一行 if(sprite == null) return true; 已经处理了 spritenull 的情况。执行到这一行时,sprite 必然不为 null,因此 ?? 后面的部分永远不会被执行。这会使代码逻辑变得混乱。

            __result = sprite;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

不确定,我跟着之前有的内容写的

Copy link
Contributor Author

Choose a reason for hiding this comment

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

该处内容已更新

Copy link
Contributor Author

Choose a reason for hiding this comment

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

请无视此文件的修改

@clansty clansty merged commit 6c5a13c into MuNET-OSS:main Nov 27, 2025
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