public object EnsureIcon(Saint.Item sItem) { var iconId = (UInt16)sItem.GetRaw("Icon"); if (_iconPathsByIconId.TryGetValue(iconId, out var iconPath)) { return(iconPath); } // This item has no high-res icon, generate a low-res temporary instead. var temporaryId = "t/" + iconId; _iconPathsByIconId[iconId] = temporaryId; // Write the temporary. var path = Path.Combine(_itemIconPath, temporaryId) + ".png"; if (File.Exists(path) && !_overwriteIcon) { return(temporaryId); } var image = sItem.Icon.GetImage(); image.Save(path, System.Drawing.Imaging.ImageFormat.Png); return(temporaryId); }
public static object GetIconId(Saint.Item item) { if (IconDataByItemId.TryGetValue(item.Key, out var storedIconData)) { storedIconData.RawIconKey = (UInt16)item.GetRaw("Icon"); _iconIdByImageFile[item.Icon] = storedIconData.IconId; return(storedIconData.IconId); } if (_iconIdByImageFile.TryGetValue(item.Icon, out var otherIconId)) { return(otherIconId); } throw new InvalidOperationException("Item has no icon id."); }
private static void CheckIconData(Saint.Item item) { if (!IconDataByItemId.TryGetValue(item.Key, out var storedIconData)) { return; } var rawIconKey = (UInt16)item.GetRaw("Icon"); // Ensure the stored data is still what we expect. if (rawIconKey != storedIconData.RawIconKey) { // Icon changed! Remove data. DatabaseBuilder.PrintLine($"{item.Key} {item.Name} icon changed. {rawIconKey} != {storedIconData.RawIconKey}. Removing."); IconDataByItemId.Remove(item.Key); } else { // Have valid stored data. Cross-reference the image file. _iconIdByImageFile[item.Icon] = storedIconData.IconId; } }