using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using NeonSprawl.Server.Game.Skills;
namespace NeonSprawl.Server.Game.Npc;
/// DI registration for the fail-fast NPC behavior catalog (NEO-88).
public static class NpcBehaviorCatalogServiceCollectionExtensions
{
/// Binds and registers as a singleton.
public static IServiceCollection AddNpcBehaviorDefinitionCatalog(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 logger = sp.GetRequiredService()
.CreateLogger("NeonSprawl.Server.Game.Npc.NpcBehaviorCatalog");
var npcBehaviorsDir = NpcBehaviorCatalogPathResolution.ResolveNpcBehaviorsDirectory(
opts.NpcBehaviorsDirectory,
hostEnv.ContentRootPath);
var schemaPath = NpcBehaviorCatalogPathResolution.ResolveNpcBehaviorDefSchemaPath(
npcBehaviorsDir,
opts.NpcBehaviorDefSchemaPath,
hostEnv.ContentRootPath);
return NpcBehaviorDefinitionCatalogLoader.Load(npcBehaviorsDir, schemaPath, logger);
});
return services;
}
}