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:
parent
04b054810f
commit
6f850a4b2a
3 changed files with 39 additions and 3 deletions
BIN
Assets/Resources/Settings.asset
(Stored with Git LFS)
BIN
Assets/Resources/Settings.asset
(Stored with Git LFS)
Binary file not shown.
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -140,6 +140,33 @@ public sealed class ShipSchemaPinTests
|
|||
Assert.Equal(EnumNames<HullType>(), 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<HardpointType>().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<HardpointType>().Length, entries.Length);
|
||||
Assert.DoesNotContain(entries, entry => entry.Contains("fileID: 0}"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SerializedShipHasTheNestedArrayShapesPythonIndexes()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue