neon-sprawl/server/NeonSprawl.Server/Game/Items/ItemDefinitionCatalog.cs

26 lines
1.1 KiB
C#

using System.Collections.ObjectModel;
namespace NeonSprawl.Server.Game.Items;
/// <summary>In-memory item catalog loaded at startup (NEO-51). Game code should prefer injectable item registry for lookups (NEO-52).</summary>
public sealed class ItemDefinitionCatalog(
string itemsDirectory,
IReadOnlyDictionary<string, ItemDefRow> byId,
int catalogJsonFileCount)
{
/// <summary>Absolute path to the directory that was enumerated for <c>*_items.json</c> catalogs.</summary>
public string ItemsDirectory { get; } = itemsDirectory;
public IReadOnlyDictionary<string, ItemDefRow> ById { get; } = new ReadOnlyDictionary<string, ItemDefRow>(new Dictionary<string, ItemDefRow>(byId, StringComparer.Ordinal));
public int DistinctItemCount => ById.Count;
/// <summary>Number of <c>*_items.json</c> files under <see cref="ItemsDirectory"/>.</summary>
public int CatalogJsonFileCount { get; } = catalogJsonFileCount;
/// <summary>Resolves a catalog row by stable <paramref name="id"/>.</summary>
public bool TryGetItem(string id, out ItemDefRow? row) =>
ById.TryGetValue(id, out row);
}