61 lines
2.5 KiB
C#
61 lines
2.5 KiB
C#
namespace NeonSprawl.Server.Game.Factions;
|
|
|
|
/// <summary>Resolves faction catalog paths for local dev, tests, and container layouts (NEO-134).</summary>
|
|
public static class FactionCatalogPathResolution
|
|
{
|
|
/// <summary>Walks <paramref name="startDirectory"/> and parents for an existing <c>content/factions</c> directory.</summary>
|
|
public static string? TryDiscoverFactionsDirectory(string startDirectory)
|
|
{
|
|
for (var dir = new DirectoryInfo(startDirectory); dir is not null; dir = dir.Parent)
|
|
{
|
|
var candidate = Path.Combine(dir.FullName, "content", "factions");
|
|
if (Directory.Exists(candidate))
|
|
return Path.GetFullPath(candidate);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resolves the factions catalog directory.
|
|
/// Empty <paramref name="configuredFactionsDirectory"/> triggers discovery from <see cref="AppContext.BaseDirectory"/>.
|
|
/// </summary>
|
|
public static string ResolveFactionsDirectory(string? configuredFactionsDirectory, string contentRootPath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(configuredFactionsDirectory))
|
|
{
|
|
var discovered = TryDiscoverFactionsDirectory(AppContext.BaseDirectory);
|
|
if (discovered is not null)
|
|
return discovered;
|
|
|
|
throw new InvalidOperationException(
|
|
"Content:FactionsDirectory is not set and auto-discovery failed (no ancestor of AppContext.BaseDirectory contains 'content/factions'). " +
|
|
"Set Content:FactionsDirectory in configuration or environment (e.g. Content__FactionsDirectory).");
|
|
}
|
|
|
|
var trimmed = configuredFactionsDirectory.Trim();
|
|
if (Path.IsPathRooted(trimmed))
|
|
return Path.GetFullPath(trimmed);
|
|
|
|
return Path.GetFullPath(Path.Combine(contentRootPath, trimmed));
|
|
}
|
|
|
|
/// <summary>Resolves JSON Schema path for a single faction row (Draft 2020-12).</summary>
|
|
public static string ResolveFactionDefSchemaPath(
|
|
string factionsDirectory,
|
|
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(factionsDirectory, "..", "schemas", "faction-def.schema.json"));
|
|
}
|
|
}
|