namespace NeonSprawl.Server.Game.Encounters; /// Resolves reward-table catalog paths for local dev, tests, and container layouts (NEO-101). public static class RewardTableCatalogPathResolution { /// Walks and parents for an existing content/reward-tables directory. public static string? TryDiscoverRewardTablesDirectory(string startDirectory) { for (var dir = new DirectoryInfo(startDirectory); dir is not null; dir = dir.Parent) { var candidate = Path.Combine(dir.FullName, "content", "reward-tables"); if (Directory.Exists(candidate)) return Path.GetFullPath(candidate); } return null; } /// /// Resolves the reward-tables catalog directory. /// Empty triggers discovery from . /// public static string ResolveRewardTablesDirectory(string? configuredRewardTablesDirectory, string contentRootPath) { if (string.IsNullOrWhiteSpace(configuredRewardTablesDirectory)) { var discovered = TryDiscoverRewardTablesDirectory(AppContext.BaseDirectory); if (discovered is not null) return discovered; throw new InvalidOperationException( "Content:RewardTablesDirectory is not set and auto-discovery failed (no ancestor of AppContext.BaseDirectory contains 'content/reward-tables'). " + "Set Content:RewardTablesDirectory in configuration or environment (e.g. Content__RewardTablesDirectory)."); } var trimmed = configuredRewardTablesDirectory.Trim(); if (Path.IsPathRooted(trimmed)) return Path.GetFullPath(trimmed); return Path.GetFullPath(Path.Combine(contentRootPath, trimmed)); } /// Resolves JSON Schema path for a single reward-table row (Draft 2020-12). public static string ResolveRewardTableDefSchemaPath( string rewardTablesDirectory, 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(rewardTablesDirectory, "..", "schemas", "reward-table.schema.json")); } /// Resolves JSON Schema path for a reward grant row referenced by reward-table schema (Draft 2020-12). public static string ResolveRewardGrantRowSchemaPath( string rewardTablesDirectory, 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(rewardTablesDirectory, "..", "schemas", "reward-grant-row.schema.json")); } }