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; /// DI registration for the fail-fast quest catalog (NEO-113). public static class QuestCatalogServiceCollectionExtensions { /// Binds and registers as a singleton. public static IServiceCollection AddQuestDefinitionCatalog(this IServiceCollection services, IConfiguration configuration) { services.AddOptions() .Bind(configuration.GetSection(ContentPathsOptions.SectionName)); services.AddSingleton(sp => { var hostEnv = sp.GetRequiredService(); var opts = sp.GetRequiredService>().Value; var itemCatalog = sp.GetRequiredService(); var recipeCatalog = sp.GetRequiredService(); var encounterCatalog = sp.GetRequiredService(); var logger = sp.GetRequiredService() .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; } }