109 lines
4.6 KiB
C#
109 lines
4.6 KiB
C#
namespace NeonSprawl.Server.Game.Quests;
|
|
|
|
/// <summary>Resolves quest catalog paths for local dev, tests, and container layouts (NEO-113).</summary>
|
|
public static class QuestCatalogPathResolution
|
|
{
|
|
/// <summary>Walks <paramref name="startDirectory"/> and parents for an existing <c>content/quests</c> directory.</summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resolves the quests catalog directory.
|
|
/// Empty <paramref name="configuredQuestsDirectory"/> triggers discovery from <see cref="AppContext.BaseDirectory"/>.
|
|
/// </summary>
|
|
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));
|
|
}
|
|
|
|
/// <summary>Resolves JSON Schema path for a single quest row (Draft 2020-12).</summary>
|
|
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"));
|
|
}
|
|
|
|
/// <summary>Resolves JSON Schema path for a quest step row.</summary>
|
|
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"));
|
|
}
|
|
|
|
/// <summary>Resolves JSON Schema path for a quest objective row.</summary>
|
|
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"));
|
|
}
|
|
|
|
/// <summary>Resolves JSON Schema path for a reward grant row (shared by reward tables and quest bundles).</summary>
|
|
public static string ResolveRewardGrantRowSchemaPath(string questsDirectory) =>
|
|
Path.GetFullPath(Path.Combine(questsDirectory, "..", "schemas", "reward-grant-row.schema.json"));
|
|
|
|
/// <summary>Resolves JSON Schema path for a quest skill XP grant row.</summary>
|
|
public static string ResolveQuestSkillXpGrantSchemaPath(string questsDirectory) =>
|
|
Path.GetFullPath(Path.Combine(questsDirectory, "..", "schemas", "quest-skill-xp-grant.schema.json"));
|
|
|
|
/// <summary>Resolves JSON Schema path for a quest completion reward bundle.</summary>
|
|
public static string ResolveQuestRewardBundleSchemaPath(string questsDirectory) =>
|
|
Path.GetFullPath(Path.Combine(questsDirectory, "..", "schemas", "quest-reward-bundle.schema.json"));
|
|
}
|