using NeonSprawl.Server.Game.Skills;
namespace NeonSprawl.Server.Game.Items;
/// DI registration for the fail-fast item catalog (NEO-51).
public static class ItemCatalogServiceCollectionExtensions
{
/// Binds and registers and as singletons.
public static IServiceCollection AddItemDefinitionCatalog(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.Items.ItemCatalog");
var itemsDir = ItemCatalogPathResolution.ResolveItemsDirectory(opts.ItemsDirectory, hostEnv.ContentRootPath);
var schemaPath = ItemCatalogPathResolution.ResolveItemDefSchemaPath(
itemsDir,
opts.ItemDefSchemaPath,
hostEnv.ContentRootPath);
return ItemDefinitionCatalogLoader.Load(itemsDir, schemaPath, logger);
});
services.AddSingleton(sp =>
new ItemDefinitionRegistry(sp.GetRequiredService()));
return services.AddPlayerInventoryStore(configuration);
}
}