From 37176b5a1a68ad06d3093e758af7f5db78b013fa Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 13 May 2020 12:15:24 -0700 Subject: [PATCH] Add clothing color fallback to base item name Closes #213 --- NHSE.Sprites/Item/ItemSprite.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/NHSE.Sprites/Item/ItemSprite.cs b/NHSE.Sprites/Item/ItemSprite.cs index f4f9a69..cd8b0fc 100644 --- a/NHSE.Sprites/Item/ItemSprite.cs +++ b/NHSE.Sprites/Item/ItemSprite.cs @@ -14,7 +14,8 @@ public static class ItemSprite public static void Initialize(string path, string[] itemNames) { - if (FileLookup.Count > 0) + var lookup = FileLookup; + if (lookup.Count > 0) return; ItemNames = itemNames; @@ -25,7 +26,14 @@ public static void Initialize(string path, string[] itemNames) var fn = Path.GetFileNameWithoutExtension(f); if (fn == null) continue; - FileLookup.Add(fn.ToLower(), f); + lookup[fn.ToLower()] = f; + var index = fn.IndexOf('('); + if (index < 0) + continue; + + var simplerName = fn.Substring(0, index - 1); + if (!lookup.ContainsKey(simplerName)) + lookup.Add(simplerName, f); } } @@ -78,7 +86,15 @@ private static bool GetItemImageSprite(ushort id, out string? path) } var name = str[id].ToLower(); - return FileLookup.TryGetValue(name, out path); + if (FileLookup.TryGetValue(name, out path)) + return true; + + var index = name.IndexOf('('); + if (index <= 0) + return false; + + var simple = name.Substring(0, index - 1); + return FileLookup.TryGetValue(simple, out path); } public static Bitmap? GetImage(Item item, Font font, int width, int height)