namespace NeonSprawl.Server.Game.Skills; /// Resolves catalog paths for local dev, tests, and container layouts (NEO-34). public static class SkillCatalogPathResolution { /// Walks and parents for an existing content/skills directory. public static string? TryDiscoverSkillsDirectory(string startDirectory) { for (var dir = new DirectoryInfo(startDirectory); dir is not null; dir = dir.Parent) { var candidate = Path.Combine(dir.FullName, "content", "skills"); if (Directory.Exists(candidate)) return Path.GetFullPath(candidate); } return null; } /// /// Resolves the skills catalog directory. /// Empty triggers discovery from . /// public static string ResolveSkillsDirectory(string? configuredSkillsDirectory, string contentRootPath) { if (string.IsNullOrWhiteSpace(configuredSkillsDirectory)) { var discovered = TryDiscoverSkillsDirectory(AppContext.BaseDirectory); if (discovered is not null) return discovered; throw new InvalidOperationException( "Content:SkillsDirectory is not set and auto-discovery failed (no ancestor of AppContext.BaseDirectory contains 'content/skills'). " + "Set Content:SkillsDirectory in configuration or environment (e.g. Content__SkillsDirectory)."); } var trimmed = configuredSkillsDirectory.Trim(); if (Path.IsPathRooted(trimmed)) return Path.GetFullPath(trimmed); return Path.GetFullPath(Path.Combine(contentRootPath, trimmed)); } /// Resolves JSON Schema path for a single skill row (Draft 2020-12). public static string ResolveSkillDefSchemaPath( string skillsDirectory, 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(skillsDirectory, "..", "schemas", "skill-def.schema.json")); } }