using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using NeonSprawl.Server.Game.Items; using NeonSprawl.Server.Game.Skills; namespace NeonSprawl.Server.Game.Gathering; /// DI registration for the fail-fast resource-node catalog and registry (NEO-58, NEO-59). public static class ResourceNodeCatalogServiceCollectionExtensions { /// /// Binds and registers and /// as singletons. /// public static IServiceCollection AddResourceNodeCatalog(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 logger = sp.GetRequiredService() .CreateLogger("NeonSprawl.Server.Game.Gathering.ResourceNodeCatalog"); var resourceNodesDir = ResourceNodeCatalogPathResolution.ResolveResourceNodesDirectory( opts.ResourceNodesDirectory, hostEnv.ContentRootPath); var nodeSchemaPath = ResourceNodeCatalogPathResolution.ResolveResourceNodeDefSchemaPath( resourceNodesDir, opts.ResourceNodeDefSchemaPath, hostEnv.ContentRootPath); var yieldSchemaPath = ResourceNodeCatalogPathResolution.ResolveResourceYieldRowSchemaPath( resourceNodesDir, opts.ResourceYieldRowSchemaPath, hostEnv.ContentRootPath); var knownItemIds = itemCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal); return ResourceNodeCatalogLoader.Load( resourceNodesDir, nodeSchemaPath, yieldSchemaPath, knownItemIds, logger); }); services.AddSingleton(sp => new ResourceNodeDefinitionRegistry(sp.GetRequiredService())); return services; } }