namespace NeonSprawl.Server.Game.Crafting; /// Resolves recipe catalog paths for local dev, tests, and container layouts (NEO-66). public static class RecipeCatalogPathResolution { /// Walks and parents for an existing content/recipes directory. public static string? TryDiscoverRecipesDirectory(string startDirectory) { for (var dir = new DirectoryInfo(startDirectory); dir is not null; dir = dir.Parent) { var candidate = Path.Combine(dir.FullName, "content", "recipes"); if (Directory.Exists(candidate)) return Path.GetFullPath(candidate); } return null; } /// /// Resolves the recipes catalog directory. /// Empty triggers discovery from . /// public static string ResolveRecipesDirectory(string? configuredRecipesDirectory, string contentRootPath) { if (string.IsNullOrWhiteSpace(configuredRecipesDirectory)) { var discovered = TryDiscoverRecipesDirectory(AppContext.BaseDirectory); if (discovered is not null) return discovered; throw new InvalidOperationException( "Content:RecipesDirectory is not set and auto-discovery failed (no ancestor of AppContext.BaseDirectory contains 'content/recipes'). " + "Set Content:RecipesDirectory in configuration or environment (e.g. Content__RecipesDirectory)."); } var trimmed = configuredRecipesDirectory.Trim(); if (Path.IsPathRooted(trimmed)) return Path.GetFullPath(trimmed); return Path.GetFullPath(Path.Combine(contentRootPath, trimmed)); } /// Resolves JSON Schema path for a single recipe row (Draft 2020-12). public static string ResolveRecipeDefSchemaPath( string recipesDirectory, string? configuredSchemaPath, string contentRootPath) { if (!string.IsNullOrWhiteSpace(configuredSchemaPath)) { var trimmed = configuredSchemaPath.Trim(); if (Path.IsPathRooted(trimmed)) return Path.GetFullPath(trimmed); return Path.GetFullPath(Path.Combine(contentRootPath, trimmed)); } return Path.GetFullPath(Path.Combine(recipesDirectory, "..", "schemas", "recipe-def.schema.json")); } /// Resolves JSON Schema path for a recipe I/O row (Draft 2020-12). public static string ResolveRecipeIoRowSchemaPath( string recipesDirectory, string? configuredSchemaPath, string contentRootPath) { if (!string.IsNullOrWhiteSpace(configuredSchemaPath)) { var trimmed = configuredSchemaPath.Trim(); if (Path.IsPathRooted(trimmed)) return Path.GetFullPath(trimmed); return Path.GetFullPath(Path.Combine(contentRootPath, trimmed)); } return Path.GetFullPath(Path.Combine(recipesDirectory, "..", "schemas", "recipe-io-row.schema.json")); } }