Remove redundant runtime item catalog adapter

This commit is contained in:
Meta Vens 2026-06-16 19:14:35 +01:00
commit 5d7f0ef9b2
7 changed files with 35 additions and 64 deletions

View file

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GameCult.Aetheria.State.Unity;
public interface IRuntimeItemCatalogReader
{
AetheriaRuntimeCatalogItem GetRuntimeItem(string itemKey);
}
public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
{
private readonly Dictionary<string, AetheriaRuntimeCatalogItem> _typedItemsByKey;
public AetheriaRuntimeItemCatalog(AetheriaRuntimeCatalogSnapshot catalog)
{
if (catalog == null) throw new ArgumentNullException(nameof(catalog));
_typedItemsByKey = catalog.Items
.Where(item => !string.IsNullOrWhiteSpace(item.ItemKey))
.ToDictionary(item => item.ItemKey, item => item, StringComparer.OrdinalIgnoreCase);
}
public AetheriaRuntimeCatalogItem GetRuntimeItem(string itemKey)
{
if (string.IsNullOrWhiteSpace(itemKey))
return null;
return _typedItemsByKey.TryGetValue(itemKey, out var item)
? item
: null;
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 897dd3ee37f64ef987d554516646c5cf
timeCreated: 1781359840

View file

@ -17,14 +17,13 @@ public class ItemManager
public Random Random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue));
private Action<string> _logger;
private readonly IRuntimeItemCatalogReader _runtimeItems;
private readonly AetheriaRuntimeCatalogSnapshot _runtimeCatalog;
public GameplaySettings GameplaySettings { get; }
public ItemManager(IRuntimeItemCatalogReader runtimeItems, GameplaySettings settings, Action<string> logger)
public ItemManager(AetheriaRuntimeCatalogSnapshot runtimeCatalog, GameplaySettings settings, Action<string> logger)
{
_runtimeItems = runtimeItems;
_runtimeCatalog = runtimeCatalog ?? throw new ArgumentNullException(nameof(runtimeCatalog));
GameplaySettings = settings;
_logger = logger;
}
@ -34,7 +33,7 @@ public class ItemManager
return item == null
? null
: !string.IsNullOrWhiteSpace(item.ItemKey)
? _runtimeItems.GetRuntimeItem(item.ItemKey)
? _runtimeCatalog.FindItem(item.ItemKey)
: null;
}