38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace NeonSprawl.Server.Game.Contracts;
|
|
|
|
/// <summary>Adapter over <see cref="ContractTemplateCatalog"/> (NEO-145).</summary>
|
|
public sealed class ContractTemplateRegistry(ContractTemplateCatalog catalog) : IContractTemplateRegistry
|
|
{
|
|
/// <inheritdoc />
|
|
public bool TryGetDefinition(string? templateId, [NotNullWhen(true)] out ContractTemplateRow? definition)
|
|
{
|
|
if (templateId is null)
|
|
{
|
|
definition = null;
|
|
return false;
|
|
}
|
|
|
|
if (catalog.ById.TryGetValue(templateId, out var row))
|
|
{
|
|
definition = row;
|
|
return true;
|
|
}
|
|
|
|
definition = null;
|
|
return false;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IReadOnlyList<ContractTemplateRow> GetDefinitionsInIdOrder()
|
|
{
|
|
string[] ids = [.. catalog.ById.Keys.OrderBy(k => k, StringComparer.Ordinal)];
|
|
var list = new List<ContractTemplateRow>(ids.Length);
|
|
foreach (var id in ids)
|
|
list.Add(catalog.ById[id]);
|
|
|
|
return list;
|
|
}
|
|
}
|