40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace NeonSprawl.Server.Game.Factions;
|
|
|
|
/// <summary>Adapter over <see cref="FactionDefinitionCatalog"/> (NEO-134).</summary>
|
|
public sealed class FactionDefinitionRegistry(FactionDefinitionCatalog catalog) : IFactionDefinitionRegistry
|
|
{
|
|
/// <inheritdoc />
|
|
public bool TryGetDefinition(string? factionId, [NotNullWhen(true)] out FactionDefRow? definition)
|
|
{
|
|
if (factionId is null)
|
|
{
|
|
definition = null;
|
|
return false;
|
|
}
|
|
|
|
if (catalog.ById.TryGetValue(factionId, out var row))
|
|
{
|
|
definition = row;
|
|
return true;
|
|
}
|
|
|
|
definition = null;
|
|
return false;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IReadOnlyList<FactionDefRow> GetDefinitionsInIdOrder()
|
|
{
|
|
var ids = catalog.ById.Keys.OrderBy(k => k, StringComparer.Ordinal).ToArray();
|
|
var list = new List<FactionDefRow>(ids.Length);
|
|
foreach (var id in ids)
|
|
{
|
|
list.Add(catalog.ById[id]);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|