using NeonSprawl.Server.Game.PositionState;
using Microsoft.Extensions.Options;
namespace NeonSprawl.Server.Game.Skills;
/// Registers skill XP persistence: PostgreSQL when configured, otherwise in-memory fallback (NEO-38).
public static class SkillProgressionServiceCollectionExtensions
{
public static IServiceCollection AddSkillProgressionStore(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions()
.Bind(configuration.GetSection(ContentPathsOptions.SectionName));
var cs = configuration.GetConnectionString(PositionStateServiceCollectionExtensions.NeonSprawlConnectionStringName);
if (!string.IsNullOrWhiteSpace(cs))
{
services.AddSingleton();
}
else
{
services.AddSingleton();
}
services.AddSingleton(sp =>
{
var hostEnv = sp.GetRequiredService();
var opts = sp.GetRequiredService>().Value;
var logger = sp.GetRequiredService()
.CreateLogger("NeonSprawl.Server.Game.Skills.LevelCurve");
var skillsDir = SkillCatalogPathResolution.ResolveSkillsDirectory(opts.SkillsDirectory, hostEnv.ContentRootPath);
var curvePath = Path.Combine(skillsDir, "prototype_level_curve.json");
var schemaPath = Path.GetFullPath(Path.Combine(skillsDir, "..", "schemas", "level-curve.schema.json"));
return ContentBackedSkillLevelCurve.Load(skillsDir, curvePath, schemaPath, logger);
});
return services;
}
}