namespace NeonSprawl.Server.Game.Quests; /// Resolves quest catalog paths for local dev, tests, and container layouts (NEO-113). public static class QuestCatalogPathResolution { /// Walks and parents for an existing content/quests directory. public static string? TryDiscoverQuestsDirectory(string startDirectory) { for (var dir = new DirectoryInfo(startDirectory); dir is not null; dir = dir.Parent) { var candidate = Path.Combine(dir.FullName, "content", "quests"); if (Directory.Exists(candidate)) return Path.GetFullPath(candidate); } return null; } /// /// Resolves the quests catalog directory. /// Empty triggers discovery from . /// public static string ResolveQuestsDirectory(string? configuredQuestsDirectory, string contentRootPath) { if (string.IsNullOrWhiteSpace(configuredQuestsDirectory)) { var discovered = TryDiscoverQuestsDirectory(AppContext.BaseDirectory); if (discovered is not null) return discovered; throw new InvalidOperationException( "Content:QuestsDirectory is not set and auto-discovery failed (no ancestor of AppContext.BaseDirectory contains 'content/quests'). " + "Set Content:QuestsDirectory in configuration or environment (e.g. Content__QuestsDirectory)."); } var trimmed = configuredQuestsDirectory.Trim(); if (Path.IsPathRooted(trimmed)) return Path.GetFullPath(trimmed); return Path.GetFullPath(Path.Combine(contentRootPath, trimmed)); } /// Resolves JSON Schema path for a single quest row (Draft 2020-12). public static string ResolveQuestDefSchemaPath( string questsDirectory, 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(questsDirectory, "..", "schemas", "quest-def.schema.json")); } /// Resolves JSON Schema path for a quest step row. public static string ResolveQuestStepDefSchemaPath( string questsDirectory, 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(questsDirectory, "..", "schemas", "quest-step-def.schema.json")); } /// Resolves JSON Schema path for a quest objective row. public static string ResolveQuestObjectiveDefSchemaPath( string questsDirectory, 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(questsDirectory, "..", "schemas", "quest-objective-def.schema.json")); } /// Resolves JSON Schema path for a reward grant row (shared by reward tables and quest bundles). public static string ResolveRewardGrantRowSchemaPath(string questsDirectory) => Path.GetFullPath(Path.Combine(questsDirectory, "..", "schemas", "reward-grant-row.schema.json")); /// Resolves JSON Schema path for a quest skill XP grant row. public static string ResolveQuestSkillXpGrantSchemaPath(string questsDirectory) => Path.GetFullPath(Path.Combine(questsDirectory, "..", "schemas", "quest-skill-xp-grant.schema.json")); /// Resolves JSON Schema path for a quest completion reward bundle. public static string ResolveQuestRewardBundleSchemaPath(string questsDirectory) => Path.GetFullPath(Path.Combine(questsDirectory, "..", "schemas", "quest-reward-bundle.schema.json")); }