NEO-51: Primary constructor on ItemDefinitionCatalog; test tidy.

Restore explicit Content:ItemsDirectory in test factory; use const
for schema-violation fixture JSON.
pull/86/head
VinPropane 2026-05-17 21:58:53 -04:00
parent d23f6dd8ab
commit 0a3c28ae5c
3 changed files with 9 additions and 15 deletions

View File

@ -129,7 +129,7 @@ public class ItemDefinitionCatalogLoaderTests
{
// Arrange
var (_, itemsDir, schemaPath) = CreateTempContentLayout();
var bad = """
const string bad = """
{
"schemaVersion": 1,
"items": [

View File

@ -5,8 +5,8 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Time.Testing;
using NeonSprawl.Server.Game.AbilityInput;
using NeonSprawl.Server.Game.PositionState;
using NeonSprawl.Server.Game.Items;
using NeonSprawl.Server.Game.PositionState;
using NeonSprawl.Server.Game.Mastery;
using NeonSprawl.Server.Game.Skills;
using Npgsql;

View File

@ -3,27 +3,21 @@ 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
public sealed class ItemDefinitionCatalog(
string itemsDirectory,
IReadOnlyDictionary<string, ItemDefRow> byId,
int catalogJsonFileCount)
{
public ItemDefinitionCatalog(
string itemsDirectory,
IReadOnlyDictionary<string, ItemDefRow> byId,
int catalogJsonFileCount)
{
ItemsDirectory = itemsDirectory;
ById = new ReadOnlyDictionary<string, ItemDefRow>(new Dictionary<string, ItemDefRow>(byId, StringComparer.Ordinal));
CatalogJsonFileCount = catalogJsonFileCount;
}
/// <summary>Absolute path to the directory that was enumerated for <c>*_items.json</c> catalogs.</summary>
public string ItemsDirectory { get; }
public string ItemsDirectory { get; } = itemsDirectory;
public IReadOnlyDictionary<string, ItemDefRow> ById { get; }
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; }
public int CatalogJsonFileCount { get; } = catalogJsonFileCount;
/// <summary>Resolves a catalog row by stable <paramref name="id"/>.</summary>
public bool TryGetItem(string id, out ItemDefRow? row) =>