2026-06-15 18:51:59 +01:00
|
|
|
using System;
|
2026-06-13 14:36:54 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using GameCult.Aetheria.State.Unity;
|
|
|
|
|
|
2026-06-14 09:19:53 +01:00
|
|
|
public interface IRuntimeItemCatalogReader
|
2026-06-13 14:36:54 +01:00
|
|
|
{
|
2026-06-14 22:58:02 +01:00
|
|
|
AetheriaRuntimeCatalogItem GetRuntimeItem(string itemKey);
|
2026-06-13 14:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-14 09:19:53 +01:00
|
|
|
public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
|
2026-06-13 14:36:54 +01:00
|
|
|
{
|
2026-06-14 22:58:02 +01:00
|
|
|
private readonly Dictionary<string, AetheriaRuntimeCatalogItem> _typedItemsByKey;
|
2026-06-13 14:36:54 +01:00
|
|
|
|
|
|
|
|
public AetheriaRuntimeItemCatalog(AetheriaRuntimeCatalogSnapshot catalog)
|
|
|
|
|
{
|
|
|
|
|
if (catalog == null) throw new ArgumentNullException(nameof(catalog));
|
|
|
|
|
|
2026-06-14 22:58:02 +01:00
|
|
|
_typedItemsByKey = catalog.Items
|
2026-06-15 01:31:16 +01:00
|
|
|
.Where(item => !string.IsNullOrWhiteSpace(item.ItemKey))
|
|
|
|
|
.ToDictionary(item => item.ItemKey, item => item, StringComparer.OrdinalIgnoreCase);
|
2026-06-13 14:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-14 22:58:02 +01:00
|
|
|
public AetheriaRuntimeCatalogItem GetRuntimeItem(string itemKey)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(itemKey))
|
|
|
|
|
return null;
|
|
|
|
|
|
2026-06-15 03:19:40 +01:00
|
|
|
return _typedItemsByKey.TryGetValue(itemKey, out var item)
|
|
|
|
|
? item
|
2026-06-14 22:58:02 +01:00
|
|
|
: null;
|
|
|
|
|
}
|
2026-06-13 14:36:54 +01:00
|
|
|
}
|