diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 2a005109b..558bfd2e2 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -6110,6 +6110,7 @@ static void RequireTradeItemValuesUseRuntimeQueries(string root) "public bool TryGetHardpointType(out TEnum hardpointType) where TEnum : struct", "public bool TryGetSimpleCommodityCategory(out TEnum category) where TEnum : struct", "public bool TryGetCompoundCommodityCategory(out TEnum category) where TEnum : struct", + "public AetheriaRuntimeCatalogItem? FindItem(T? item, Func itemKey) where T : class", "Enum.TryParse(HardpointType, true, out hardpointType)", "Enum.TryParse(SimpleCommodityCategory, true, out category)", "Enum.TryParse(CompoundCommodityCategory, true, out category)" @@ -7195,7 +7196,7 @@ static void RequireUnitySharedDocumentAccessorErgonomics(string root) "public abstract class ActionBarBinding : IDisposable", "CultMeshReactiveDocument _catalog", "Client.Aetheria().ReactiveCatalog()", - "_catalog?.Current?.FindItem(item.ItemKey)", + "_catalog?.Current?.FindItem(item, x => x.ItemKey)", "binding?.Dispose()", "private void OnDestroy()" }; @@ -7226,6 +7227,7 @@ static void RequireUnitySharedDocumentAccessorErgonomics(string root) "_catalog?.Dispose()", "_playerSettings?.Dispose()", "_catalog?.Current", + "ResolveCatalog()?.FindItem(item, x => x.ItemKey)", "_playerSettings?.Current", "private void OnDestroy()" }; @@ -12375,7 +12377,7 @@ static void RequireMainMenuContinueRunState(string root) "ResolveInfoGathered?.Invoke(currentEntity, target)", "ResolveHostileContact?.Invoke(currentEntity, observedTarget)", "public AetheriaRuntimeCatalogSnapshot RuntimeCatalog { get; set; }", - "RuntimeCatalog?.FindItem(target.Hull?.ItemKey ?? \"\")" + "RuntimeCatalog?.FindItem(target.Hull, x => x.ItemKey)" }; var missingTargetPresentationSymbols = requiredTargetPresentationSymbols .Where(symbol => !targetPresentation.Contains(symbol, StringComparison.Ordinal)) diff --git a/Assets/Scripts/Gameplay/ActionBarSlot.cs b/Assets/Scripts/Gameplay/ActionBarSlot.cs index 8cd8c6e1a..ec11ef4c3 100644 --- a/Assets/Scripts/Gameplay/ActionBarSlot.cs +++ b/Assets/Scripts/Gameplay/ActionBarSlot.cs @@ -90,13 +90,13 @@ public abstract class ActionBarBinding : IDisposable protected AetheriaRuntimeCatalogItem FindCatalogItem(ItemInstance item) { - if (item == null || string.IsNullOrWhiteSpace(item.ItemKey) || Client == null) + if (Client == null) return null; try { _catalog ??= Client.Aetheria().ReactiveCatalog(); - return _catalog?.Current?.FindItem(item.ItemKey); + return _catalog?.Current?.FindItem(item, x => x.ItemKey); } catch (Exception ex) { diff --git a/Assets/Scripts/Gameplay/AetheriaUnityActionBarPresentation.cs b/Assets/Scripts/Gameplay/AetheriaUnityActionBarPresentation.cs index 5e1ea2752..727e08a1a 100644 --- a/Assets/Scripts/Gameplay/AetheriaUnityActionBarPresentation.cs +++ b/Assets/Scripts/Gameplay/AetheriaUnityActionBarPresentation.cs @@ -53,7 +53,7 @@ public sealed class AetheriaUnityActionBarPresentation { ActionBarWeaponGroupBinding weaponGroup => $"G{weaponGroup.Group + 1}", ActionBarConsumableBinding consumable => consumable.Target?.Name ?? "Consumable", - ActionBarGearBinding gear => _catalog?.FindItem(gear.Item?.EquippableItem?.ItemKey ?? "")?.Name ?? "Gear", + ActionBarGearBinding gear => _catalog?.FindItem(gear.Item?.EquippableItem, x => x.ItemKey)?.Name ?? "Gear", _ => "Empty" }; } @@ -257,7 +257,7 @@ public sealed class AetheriaUnityActionBarPresentation private AetheriaRuntimeCatalogItem FindConsumable(ItemInstance item) { - var typedItem = _catalog?.FindItem(item?.ItemKey ?? ""); + var typedItem = _catalog?.FindItem(item, x => x.ItemKey); return typedItem != null && string.Equals(typedItem.Category, AetheriaRuntimeItemCategories.Consumable, StringComparison.Ordinal) ? typedItem diff --git a/Assets/Scripts/Gameplay/AetheriaUnityTargetPresentation.cs b/Assets/Scripts/Gameplay/AetheriaUnityTargetPresentation.cs index b3e01f8cb..b59d32ddb 100644 --- a/Assets/Scripts/Gameplay/AetheriaUnityTargetPresentation.cs +++ b/Assets/Scripts/Gameplay/AetheriaUnityTargetPresentation.cs @@ -184,7 +184,7 @@ public sealed class AetheriaUnityTargetPresentation var visibilityToTarget = ResolveInfoGathered?.Invoke(target, currentEntity) ?? 0f; TargetVisibilityFill.fillAmount = (float)renderSettings.NormalizeTargetVisibilityFill(targetInfoGathered); VisibilityToTargetFill.fillAmount = (float)renderSettings.NormalizeVisibilityToTargetFill(visibilityToTarget); - var targetHull = RuntimeCatalog?.FindItem(target.Hull?.ItemKey ?? ""); + var targetHull = RuntimeCatalog?.FindItem(target.Hull, x => x.ItemKey); var targetMaxDurability = targetHull?.Durability > 0 ? (float)targetHull.Durability : Math.Max(target.Hull.Durability, 1f); diff --git a/Assets/Scripts/Gameplay/AetheriaUnityWeaponPresentationPolicy.cs b/Assets/Scripts/Gameplay/AetheriaUnityWeaponPresentationPolicy.cs index 667f1532a..4c63da2dd 100644 --- a/Assets/Scripts/Gameplay/AetheriaUnityWeaponPresentationPolicy.cs +++ b/Assets/Scripts/Gameplay/AetheriaUnityWeaponPresentationPolicy.cs @@ -21,7 +21,7 @@ public static class AetheriaUnityWeaponPresentationPolicy AetheriaRuntimeCatalogSnapshot runtimeCatalog, EquippedItem item) { - var typedItem = runtimeCatalog?.FindItem(item?.EquippableItem?.ItemKey ?? ""); + var typedItem = runtimeCatalog?.FindItem(item?.EquippableItem, x => x.ItemKey); if (typedItem?.BehaviorKinds == null) return false; diff --git a/Assets/Scripts/ServerShared/ItemManager.cs b/Assets/Scripts/ServerShared/ItemManager.cs index 62570163d..9d54fe3a6 100644 --- a/Assets/Scripts/ServerShared/ItemManager.cs +++ b/Assets/Scripts/ServerShared/ItemManager.cs @@ -28,11 +28,7 @@ public class ItemManager public AetheriaRuntimeCatalogItem GetRuntimeItem(ItemInstance item) { - return item == null - ? null - : !string.IsNullOrWhiteSpace(item.ItemKey) - ? _runtimeCatalog.FindItem(item.ItemKey) - : null; + return _runtimeCatalog.FindItem(item, x => x.ItemKey); } public Behavior[] CreateRuntimeBehaviors(EquippedItem item) diff --git a/Assets/Scripts/UI/HUD/SchematicDisplay.cs b/Assets/Scripts/UI/HUD/SchematicDisplay.cs index 81a2524bf..c7f8637db 100644 --- a/Assets/Scripts/UI/HUD/SchematicDisplay.cs +++ b/Assets/Scripts/UI/HUD/SchematicDisplay.cs @@ -316,7 +316,7 @@ public class SchematicDisplay : MonoBehaviour private AetheriaRuntimeCatalogItem FindTypedItem(ItemInstance item) { - return ResolveCatalog()?.FindItem(item?.ItemKey ?? ""); + return ResolveCatalog()?.FindItem(item, x => x.ItemKey); } private AetheriaRuntimeCatalogSnapshot ResolveCatalog() diff --git a/Assets/Scripts/UI/Menu/InventoryMenu.cs b/Assets/Scripts/UI/Menu/InventoryMenu.cs index 9cf6df51e..9fd0e527a 100644 --- a/Assets/Scripts/UI/Menu/InventoryMenu.cs +++ b/Assets/Scripts/UI/Menu/InventoryMenu.cs @@ -1071,7 +1071,7 @@ public class InventoryMenu : MonoBehaviour private AetheriaRuntimeCatalogItem FindTypedInventoryItem(ItemInstance item) { - return ResolveCatalog()?.FindItem(item?.ItemKey ?? ""); + return ResolveCatalog()?.FindItem(item, x => x.ItemKey); } private AetheriaRuntimeCatalogSnapshot ResolveCatalog() diff --git a/Assets/Scripts/UI/Menu/InventoryPanel.cs b/Assets/Scripts/UI/Menu/InventoryPanel.cs index b67d39eab..5bb8e926c 100644 --- a/Assets/Scripts/UI/Menu/InventoryPanel.cs +++ b/Assets/Scripts/UI/Menu/InventoryPanel.cs @@ -1030,7 +1030,7 @@ private void Update() private AetheriaRuntimeCatalogItem FindTypedInventoryItem(ItemInstance item) { - return ResolveCatalog()?.FindItem(item?.ItemKey ?? ""); + return ResolveCatalog()?.FindItem(item, x => x.ItemKey); } private void RequestDockedCurrentShip(Ship ship) diff --git a/Assets/Scripts/Zone Display/ZoneRenderer.cs b/Assets/Scripts/Zone Display/ZoneRenderer.cs index 573a871f0..0ef823a95 100644 --- a/Assets/Scripts/Zone Display/ZoneRenderer.cs +++ b/Assets/Scripts/Zone Display/ZoneRenderer.cs @@ -232,10 +232,7 @@ public class ZoneRenderer : MonoBehaviour public AetheriaRuntimeCatalogItem FindCatalogItem(ItemInstance item) { - if (item == null || string.IsNullOrWhiteSpace(item.ItemKey)) - return null; - - return ResolveCatalog()?.FindItem(item.ItemKey); + return ResolveCatalog()?.FindItem(item, x => x.ItemKey); } void Start() @@ -1201,7 +1198,7 @@ public class ZoneRenderer : MonoBehaviour private AetheriaRuntimeCatalogItem FindTypedZoneItem(ItemInstance item) { - return FindCatalogItem(item); + return ResolveCatalog()?.FindItem(item, x => x.ItemKey); } private AetheriaRuntimeCatalogSnapshot ResolveCatalog() diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs index 5f2ebe905..513746afa 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs @@ -57,6 +57,14 @@ namespace GameCult.Aetheria.State.Verse return TryGet(_itemsByKey, itemKey); } + public AetheriaRuntimeCatalogItem? FindItem(T? item, Func itemKey) where T : class + { + if (item == null || itemKey == null) + return null; + + return FindItem(itemKey(item) ?? ""); + } + public AetheriaRuntimeCorporation? FindCorporation(string corporationKey) { return TryGet(_corporationsByKey, corporationKey);