Centralize catalog item object lookup
This commit is contained in:
parent
b32a412df2
commit
0cf4591b8f
11 changed files with 24 additions and 21 deletions
|
|
@ -6110,6 +6110,7 @@ static void RequireTradeItemValuesUseRuntimeQueries(string root)
|
|||
"public bool TryGetHardpointType<TEnum>(out TEnum hardpointType) where TEnum : struct",
|
||||
"public bool TryGetSimpleCommodityCategory<TEnum>(out TEnum category) where TEnum : struct",
|
||||
"public bool TryGetCompoundCommodityCategory<TEnum>(out TEnum category) where TEnum : struct",
|
||||
"public AetheriaRuntimeCatalogItem? FindItem<T>(T? item, Func<T, string?> 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<AetheriaRuntimeCatalogSnapshot> _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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -57,6 +57,14 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return TryGet(_itemsByKey, itemKey);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCatalogItem? FindItem<T>(T? item, Func<T, string?> itemKey) where T : class
|
||||
{
|
||||
if (item == null || itemKey == null)
|
||||
return null;
|
||||
|
||||
return FindItem(itemKey(item) ?? "");
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCorporation? FindCorporation(string corporationKey)
|
||||
{
|
||||
return TryGet(_corporationsByKey, corporationKey);
|
||||
|
|
|
|||
Loading…
Reference in a new issue