Add clothing color fallback to base item name

Closes #213
This commit is contained in:
Kurt 2020-05-13 12:15:24 -07:00
parent ab3afc23a8
commit 37176b5a1a

View File

@ -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)