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