79 lines
3.3 KiB
C#
79 lines
3.3 KiB
C#
namespace NeonSprawl.Server.Game.Encounters;
|
|
|
|
/// <summary>Resolves reward-table catalog paths for local dev, tests, and container layouts (NEO-101).</summary>
|
|
public static class RewardTableCatalogPathResolution
|
|
{
|
|
/// <summary>Walks <paramref name="startDirectory"/> and parents for an existing <c>content/reward-tables</c> directory.</summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resolves the reward-tables catalog directory.
|
|
/// Empty <paramref name="configuredRewardTablesDirectory"/> triggers discovery from <see cref="AppContext.BaseDirectory"/>.
|
|
/// </summary>
|
|
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));
|
|
}
|
|
|
|
/// <summary>Resolves JSON Schema path for a single reward-table row (Draft 2020-12).</summary>
|
|
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"));
|
|
}
|
|
|
|
/// <summary>Resolves JSON Schema path for a reward grant row referenced by reward-table schema (Draft 2020-12).</summary>
|
|
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"));
|
|
}
|
|
}
|