Facility icon in the Settings asset, GetIcon fails by name; HardpointType values pinned

ItemIcons gets an entry for Facility (the Tool sprite, no new art) in place of the empty one, and
GameSettings.GetIcon names the type when an entry is missing instead of throwing IndexOutOfRange.
Tests pin each HardpointType to its stored number and one non-null icon per type in the asset.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-28 04:36:24 +01:00
commit 6f850a4b2a
3 changed files with 39 additions and 3 deletions

View file

@ -69,7 +69,16 @@ public class GameSettings : ScriptableObject
[HideInInspector] public Sprite[] WeaponFireTypeIcons;
[HideInInspector] public Sprite[] WeaponModifierIcons;
public Sprite GetIcon(HardpointType type) => ItemIcons[(int) type];
// Every HardpointType has an entry in the asset's ItemIcons; a missing one is named, never an IndexOutOfRange.
public Sprite GetIcon(HardpointType type) => IconOf(ItemIcons, type);
public static Sprite IconOf(Sprite[] icons, HardpointType type)
{
var index = (int) type;
if (icons == null || index < 0 || index >= icons.Length || icons[index] == null)
throw new InvalidOperationException($"GameSettings.ItemIcons has no sprite for HardpointType.{type} (index {index}, {icons?.Length ?? 0} entries); set it in the Settings asset.");
return icons[index];
}
public Sprite GetIcon(WeaponType type) => WeaponTypeIcons[(int) type];
public Sprite GetIcon(WeaponRange range) => WeaponRangeIcons[(int) range];
public Sprite GetIcon(WeaponCaliber caliber) => WeaponCaliberIcons[(int) caliber];