64 lines
2.8 KiB
C#
64 lines
2.8 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Options;
|
|
using NeonSprawl.Server.Game.Crafting;
|
|
using NeonSprawl.Server.Game.Encounters;
|
|
using NeonSprawl.Server.Game.Items;
|
|
using NeonSprawl.Server.Game.Skills;
|
|
|
|
namespace NeonSprawl.Server.Game.Quests;
|
|
|
|
/// <summary>DI registration for the fail-fast quest catalog (NEO-113).</summary>
|
|
public static class QuestCatalogServiceCollectionExtensions
|
|
{
|
|
/// <summary>Binds <see cref="ContentPathsOptions"/> and registers <see cref="QuestDefinitionCatalog"/> as a singleton.</summary>
|
|
public static IServiceCollection AddQuestDefinitionCatalog(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddOptions<ContentPathsOptions>()
|
|
.Bind(configuration.GetSection(ContentPathsOptions.SectionName));
|
|
|
|
services.AddSingleton<QuestDefinitionCatalog>(sp =>
|
|
{
|
|
var hostEnv = sp.GetRequiredService<IHostEnvironment>();
|
|
var opts = sp.GetRequiredService<IOptions<ContentPathsOptions>>().Value;
|
|
var itemCatalog = sp.GetRequiredService<ItemDefinitionCatalog>();
|
|
var recipeCatalog = sp.GetRequiredService<RecipeDefinitionCatalog>();
|
|
var encounterCatalog = sp.GetRequiredService<EncounterDefinitionCatalog>();
|
|
var logger = sp.GetRequiredService<ILoggerFactory>()
|
|
.CreateLogger("NeonSprawl.Server.Game.Quests.QuestCatalog");
|
|
|
|
var questsDir = QuestCatalogPathResolution.ResolveQuestsDirectory(
|
|
opts.QuestsDirectory,
|
|
hostEnv.ContentRootPath);
|
|
var questDefSchemaPath = QuestCatalogPathResolution.ResolveQuestDefSchemaPath(
|
|
questsDir,
|
|
opts.QuestDefSchemaPath,
|
|
hostEnv.ContentRootPath);
|
|
var questStepDefSchemaPath = QuestCatalogPathResolution.ResolveQuestStepDefSchemaPath(
|
|
questsDir,
|
|
opts.QuestStepDefSchemaPath,
|
|
hostEnv.ContentRootPath);
|
|
var questObjectiveDefSchemaPath = QuestCatalogPathResolution.ResolveQuestObjectiveDefSchemaPath(
|
|
questsDir,
|
|
opts.QuestObjectiveDefSchemaPath,
|
|
hostEnv.ContentRootPath);
|
|
|
|
var knownItemIds = itemCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal);
|
|
var knownRecipeIds = recipeCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal);
|
|
var knownEncounterIds = encounterCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal);
|
|
|
|
return QuestDefinitionCatalogLoader.Load(
|
|
questsDir,
|
|
questDefSchemaPath,
|
|
questStepDefSchemaPath,
|
|
questObjectiveDefSchemaPath,
|
|
knownItemIds,
|
|
knownRecipeIds,
|
|
knownEncounterIds,
|
|
logger);
|
|
});
|
|
|
|
return services;
|
|
}
|
|
}
|