Make runtime item catalog key-only
This commit is contained in:
parent
c245538793
commit
ffe9d6d7bf
7 changed files with 20 additions and 63 deletions
|
|
@ -6,7 +6,6 @@ using GameCult.Aetheria.State.Unity;
|
|||
public interface IRuntimeItemCatalogReader
|
||||
{
|
||||
AetheriaRuntimeCatalogItem GetRuntimeItem(string itemKey);
|
||||
AetheriaRuntimeCatalogItem GetRuntimeItem(Guid guid);
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
|
||||
|
|
@ -15,19 +14,14 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
|
|||
private const string LegacyItemDefinitionPrefix = "aetheria.item_definition:legacy:";
|
||||
|
||||
private readonly Dictionary<string, AetheriaRuntimeCatalogItem> _typedItemsByKey;
|
||||
private readonly Dictionary<Guid, AetheriaRuntimeCatalogItem> _typedItemsByLegacyId;
|
||||
|
||||
public AetheriaRuntimeItemCatalog(AetheriaRuntimeCatalogSnapshot catalog)
|
||||
{
|
||||
if (catalog == null) throw new ArgumentNullException(nameof(catalog));
|
||||
|
||||
_typedItemsByKey = catalog.Items
|
||||
.Where(item => !string.IsNullOrWhiteSpace(item.LegacyId))
|
||||
.ToDictionary(item => ToItemKey(item.LegacyId), item => item, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
_typedItemsByLegacyId = catalog.Items
|
||||
.Where(item => Guid.TryParse(item.LegacyId, out _))
|
||||
.ToDictionary(item => Guid.Parse(item.LegacyId), item => item);
|
||||
.Where(item => !string.IsNullOrWhiteSpace(item.ItemKey))
|
||||
.ToDictionary(item => item.ItemKey, item => item, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCatalogItem GetRuntimeItem(string itemKey)
|
||||
|
|
@ -39,21 +33,10 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
|
|||
return item;
|
||||
|
||||
return Guid.TryParse(RemoveItemPrefix(itemKey), out var legacyId)
|
||||
? GetRuntimeItem(legacyId)
|
||||
? GetRuntimeItem(AetheriaRuntimeItemReference.FromLegacyId(legacyId))
|
||||
: null;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCatalogItem GetRuntimeItem(Guid guid)
|
||||
{
|
||||
_typedItemsByLegacyId.TryGetValue(guid, out var item);
|
||||
return item;
|
||||
}
|
||||
|
||||
private static string ToItemKey(string legacyId)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(legacyId) ? "" : $"{LegacyItemDefinitionPrefix}{legacyId}";
|
||||
}
|
||||
|
||||
private static string RemoveItemPrefix(string itemKey)
|
||||
{
|
||||
if (itemKey.StartsWith(LegacyItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
|
|
|
|||
Loading…
Reference in a new issue