59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace NeonSprawl.Server.Game.Gathering;
|
|
|
|
/// <summary>Adapter over <see cref="ResourceNodeCatalog"/> (NEO-59).</summary>
|
|
public sealed class ResourceNodeDefinitionRegistry(ResourceNodeCatalog catalog) : IResourceNodeDefinitionRegistry
|
|
{
|
|
/// <inheritdoc />
|
|
public bool TryGetDefinition(string? nodeDefId, [NotNullWhen(true)] out ResourceNodeDefRow? definition)
|
|
{
|
|
if (nodeDefId is null)
|
|
{
|
|
definition = null;
|
|
return false;
|
|
}
|
|
|
|
if (catalog.NodesById.TryGetValue(nodeDefId, out var row))
|
|
{
|
|
definition = row;
|
|
return true;
|
|
}
|
|
|
|
definition = null;
|
|
return false;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public bool TryGetYield(string? nodeDefId, [NotNullWhen(true)] out ResourceYieldRow? yield)
|
|
{
|
|
if (nodeDefId is null)
|
|
{
|
|
yield = null;
|
|
return false;
|
|
}
|
|
|
|
if (catalog.YieldsByNodeDefId.TryGetValue(nodeDefId, out var row))
|
|
{
|
|
yield = row;
|
|
return true;
|
|
}
|
|
|
|
yield = null;
|
|
return false;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IReadOnlyList<ResourceNodeDefRow> GetDefinitionsInIdOrder()
|
|
{
|
|
var ids = catalog.NodesById.Keys.OrderBy(k => k, StringComparer.Ordinal).ToArray();
|
|
var list = new List<ResourceNodeDefRow>(ids.Length);
|
|
foreach (var id in ids)
|
|
{
|
|
list.Add(catalog.NodesById[id]);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|