From 6f850a4b2aca1e025a7788f46e4a965d2815f49b Mon Sep 17 00:00:00 2001 From: soul Date: Sat, 28 Nov 2026 04:36:24 +0100 Subject: [PATCH] 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 --- Assets/Resources/Settings.asset | 4 +-- Assets/Scripts/Gameplay/GameSettings.cs | 11 +++++++- .../ShipSchemaPinTests.cs | 27 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Assets/Resources/Settings.asset b/Assets/Resources/Settings.asset index 7d89eea8e..2da386267 100644 --- a/Assets/Resources/Settings.asset +++ b/Assets/Resources/Settings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d9d381e3b25ea04d92768f0633cb89668108229dcc17336b560d0cbbfbaed04f -size 12397 +oid sha256:7981565178e096ee594ebce89bad849f017750051aaa72c7fd8f043e549bebcd +size 12453 diff --git a/Assets/Scripts/Gameplay/GameSettings.cs b/Assets/Scripts/Gameplay/GameSettings.cs index e5e4c2b92..b63a8154e 100644 --- a/Assets/Scripts/Gameplay/GameSettings.cs +++ b/Assets/Scripts/Gameplay/GameSettings.cs @@ -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]; diff --git a/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs b/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs index 760595dcc..d2cd22611 100644 --- a/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs +++ b/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs @@ -140,6 +140,33 @@ public sealed class ShipSchemaPinTests Assert.Equal(EnumNames(), Strings("HULL_TYPE_NAMES")); } + // The stored number of each HardpointType: a row is stored by value, so an arm inserted mid-enum silently turns every later + // stored row into another type. New arms are appended with the next number. + [Fact] + public void HardpointTypeValuesAreTheStoredNumbers() + { + var stored = new[] + { + ("Hull", 0), ("Tool", 1), ("Thermal", 2), ("Thruster", 3), ("WarpDrive", 4), ("Reactor", 5), ("Radiator", 6), ("Shield", 7), + ("Sensors", 8), ("Energy", 9), ("Ballistic", 10), ("Launcher", 11), ("ControlModule", 12), ("Facility", 13) + }; + Assert.Equal(stored, Enum.GetValues().Select(type => (type.ToString(), (int) type)).OrderBy(pair => pair.Item2)); + } + + // GameSettings.GetIcon(HardpointType) indexes the Settings asset's ItemIcons by value: one sprite per type, none null. (GameSettings is + // Unity code, so the asset is read as text; the loud failure of a missing entry is for the Unity editor to confirm.) + [Fact] + public void EveryHardpointTypeHasAnIconInTheSettingsAsset() + { + var text = File.ReadAllText(Path.Combine(AetherDb.FindRoot(), "Assets", "Resources", "Settings.asset")); + var lines = text.Split('\n').Select(line => line.TrimEnd('\r')).ToList(); + var start = lines.IndexOf(" ItemIcons:") + 1; + Assert.True(start > 0, "Settings.asset has no ItemIcons"); + var entries = lines.Skip(start).TakeWhile(line => line.StartsWith(" - ")).ToArray(); + Assert.Equal(Enum.GetValues().Length, entries.Length); + Assert.DoesNotContain(entries, entry => entry.Contains("fileID: 0}")); + } + [Fact] public void SerializedShipHasTheNestedArrayShapesPythonIndexes() {