From b6f8a6dee88800672c4af433685b03ed029c8c12 Mon Sep 17 00:00:00 2001 From: Richard Ward Date: Fri, 19 Dec 2025 11:14:59 +0000 Subject: [PATCH] tidy --- src/main.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ac2960c..316be23 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,3 @@ -#define SDL_MAIN_HANDLED - #include #include #include @@ -80,11 +78,26 @@ RuntimeConfig LoadRuntimeConfigFromJson(const std::filesystem::path& configPath, throw std::runtime_error("JSON config requires a string member '" + std::string(scriptField) + "'"); } + std::optional projectRoot; + const char* projectRootField = "project_root"; + if (document.HasMember(projectRootField) && document[projectRootField].IsString()) { + std::filesystem::path candidate(document[projectRootField].GetString()); + if (candidate.is_absolute()) { + projectRoot = std::filesystem::weakly_canonical(candidate); + } else { + projectRoot = std::filesystem::weakly_canonical(configPath.parent_path() / candidate); + } + } + RuntimeConfig config; const auto& scriptValue = document[scriptField]; std::filesystem::path scriptPath(scriptValue.GetString()); if (!scriptPath.is_absolute()) { - scriptPath = configPath.parent_path() / scriptPath; + if (projectRoot) { + scriptPath = *projectRoot / scriptPath; + } else { + scriptPath = configPath.parent_path() / scriptPath; + } } scriptPath = std::filesystem::weakly_canonical(scriptPath); if (!std::filesystem::exists(scriptPath)) {