Make runtime item catalog key-only

This commit is contained in:
Meta Vens 2026-06-15 03:19:40 +01:00
commit c2f5d04e91
5 changed files with 9 additions and 45 deletions

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GameCult.Aetheria.State.Unity;
@ -10,9 +9,6 @@ public interface IRuntimeItemCatalogReader
public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
{
private const string ItemDefinitionPrefix = "aetheria.item_definition:";
private const string LegacyItemDefinitionPrefix = "aetheria.item_definition:legacy:";
private readonly Dictionary<string, AetheriaRuntimeCatalogItem> _typedItemsByKey;
public AetheriaRuntimeItemCatalog(AetheriaRuntimeCatalogSnapshot catalog)
@ -29,21 +25,8 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
if (string.IsNullOrWhiteSpace(itemKey))
return null;
if (_typedItemsByKey.TryGetValue(itemKey, out var item))
return item;
return Guid.TryParse(RemoveItemPrefix(itemKey), out var legacyId)
? GetRuntimeItem(AetheriaRuntimeItemReference.FromLegacyId(legacyId))
return _typedItemsByKey.TryGetValue(itemKey, out var item)
? item
: null;
}
private static string RemoveItemPrefix(string itemKey)
{
if (itemKey.StartsWith(LegacyItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase))
return itemKey.Substring(LegacyItemDefinitionPrefix.Length);
return itemKey.StartsWith(ItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase)
? itemKey.Substring(ItemDefinitionPrefix.Length)
: itemKey;
}
}

View file

@ -12,7 +12,6 @@ public interface INamedEntry
public class AetheriaRuntimeItemReference
{
private const string ItemDefinitionPrefix = "aetheria.item_definition:";
private const string LegacyItemDefinitionPrefix = "aetheria.item_definition:legacy:";
public string ItemKey;
@ -26,32 +25,10 @@ public class AetheriaRuntimeItemReference
ItemKey = itemKey;
}
public Guid LegacyItemId => TryParseLegacyId(ItemKey, out var itemId) ? itemId : Guid.Empty;
public static string FromLegacyId(Guid legacyItemId)
{
return legacyItemId == Guid.Empty ? "" : $"{LegacyItemDefinitionPrefix}{legacyItemId:D}";
}
public static Guid ToLegacyId(string itemKey)
{
return TryParseLegacyId(itemKey, out var itemId) ? itemId : Guid.Empty;
}
private static bool TryParseLegacyId(string itemKey, out Guid itemId)
{
itemId = Guid.Empty;
if (string.IsNullOrWhiteSpace(itemKey))
return false;
var legacyId = itemKey.StartsWith(LegacyItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase)
? itemKey.Substring(LegacyItemDefinitionPrefix.Length)
: itemKey.StartsWith(ItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase)
? itemKey.Substring(ItemDefinitionPrefix.Length)
: itemKey;
return Guid.TryParse(legacyId, out itemId);
}
}
public interface ITintInspector