using Microsoft.Extensions.Options;
using NeonSprawl.Server.Game.Skills;
namespace NeonSprawl.Server.Game.Mastery;
/// DI registration for the fail-fast mastery catalog (NEO-46).
public static class MasteryCatalogServiceCollectionExtensions
{
/// Binds and registers and as singletons.
public static IServiceCollection AddMasteryCatalog(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 skillCatalog = sp.GetRequiredService();
var logger = sp.GetRequiredService()
.CreateLogger("NeonSprawl.Server.Game.Mastery.MasteryCatalog");
var masteryDir = MasteryCatalogPathResolution.ResolveMasteryDirectory(
opts.MasteryDirectory,
hostEnv.ContentRootPath);
var schemaPath = MasteryCatalogPathResolution.ResolveMasteryCatalogSchemaPath(
masteryDir,
opts.MasteryCatalogSchemaPath,
hostEnv.ContentRootPath);
var knownSkillIds = skillCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal);
return MasteryCatalogLoader.Load(masteryDir, schemaPath, knownSkillIds, logger);
});
services.AddSingleton(sp =>
new MasteryCatalogRegistry(sp.GetRequiredService()));
return services;
}
}