Aetheria/Assets/Scripts/ServerShared/AetheriaRuntimeItemCatalog.cs

33 lines
1,021 B
C#
Raw Normal View History

using System;
2026-06-13 14:36:54 +01:00
using System.Collections.Generic;
using System.Linq;
using GameCult.Aetheria.State.Unity;
public interface IRuntimeItemCatalogReader
2026-06-13 14:36:54 +01:00
{
AetheriaRuntimeCatalogItem GetRuntimeItem(string itemKey);
2026-06-13 14:36:54 +01:00
}
public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
2026-06-13 14:36:54 +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));
_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
}
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
: null;
}
2026-06-13 14:36:54 +01:00
}