56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace NeonSprawl.Server.Game.Quests;
|
|
|
|
/// <summary>Adapter over <see cref="QuestDefinitionCatalog"/> (NEO-114).</summary>
|
|
public sealed class QuestDefinitionRegistry(QuestDefinitionCatalog catalog) : IQuestDefinitionRegistry
|
|
{
|
|
private readonly IReadOnlyList<QuestDefRow> _definitionsInIdOrder = BuildDefinitionsInIdOrder(catalog);
|
|
|
|
/// <inheritdoc />
|
|
public bool TryGetDefinition(string? questId, [NotNullWhen(true)] out QuestDefRow? definition)
|
|
{
|
|
if (questId is null)
|
|
{
|
|
definition = null;
|
|
return false;
|
|
}
|
|
|
|
return catalog.TryGetQuest(questId, out definition);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public bool TryNormalizeKnown(string? rawQuestId, [NotNullWhen(true)] out string normalized)
|
|
{
|
|
if (rawQuestId is null)
|
|
{
|
|
normalized = string.Empty;
|
|
return false;
|
|
}
|
|
|
|
normalized = rawQuestId.Trim().ToLowerInvariant();
|
|
if (normalized.Length == 0)
|
|
{
|
|
normalized = string.Empty;
|
|
return false;
|
|
}
|
|
|
|
return catalog.TryGetQuest(normalized, out _);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IReadOnlyList<QuestDefRow> GetDefinitionsInIdOrder() => _definitionsInIdOrder;
|
|
|
|
private static IReadOnlyList<QuestDefRow> BuildDefinitionsInIdOrder(QuestDefinitionCatalog catalog)
|
|
{
|
|
var ids = catalog.ById.Keys.OrderBy(k => k, StringComparer.Ordinal).ToArray();
|
|
var list = new List<QuestDefRow>(ids.Length);
|
|
foreach (var id in ids)
|
|
{
|
|
list.Add(catalog.ById[id]);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|