Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion AquaMai.Mods/GameSystem/Assets/LoadLocalImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static void LoadMusicPostfix(List<string> ____targetDirs)
if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue;
var idStr = Path.GetFileName(file).Substring("ui_jacket_".Length, 6);
jacketPaths[idStr] = file;
Comment on lines 53 to 55

Choose a reason for hiding this comment

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

medium

这部分加载图片(jacket)的逻辑在 LoadMusicPostfix 方法中重复了多次,例如后续的 frame (L58-64), nameplate (L66-72) 等。这些代码块的结构基本相同,只是子目录、文件名前缀和目标字典不同。

为了提高代码的可读性和可维护性,建议将这个重复的逻辑提取到一个辅助方法中。例如:

private static void LoadImagesFromSubdirectory(string baseDir, string subDir, string prefix, Dictionary<string, string> targetDict)
{
    var fullPath = Path.Combine(baseDir, "AssetBundleImages", subDir);
    if (!Directory.Exists(fullPath)) return;

    foreach (var file in Directory.GetFiles(fullPath))
    {
        if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue;
        var idStr = Path.GetFileName(file).Substring(prefix.Length, 6);
        targetDict[idStr] = file;
    }
}

然后可以这样调用:

LoadImagesFromSubdirectory(aDir, "jacket", "ui_jacket_", jacketPaths);
LoadImagesFromSubdirectory(aDir, "frame", "ui_frame_", framePaths);
// ...etc

这会让 LoadMusicPostfix 方法更清晰、更易于维护。

MelonLogger.Msg($"[LoadLocalImages] Loaded {file}");
}

if (Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\frame")))
Expand Down