diff --git a/src/engine.cpp b/src/engine.cpp index 2f8466d6e..a3c630356 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -83,6 +83,9 @@ Engine::Engine(CoreParameters coreParameters) paths.setResourcesFolder(params.resFolder); paths.setUserFilesFolder(params.userFolder); paths.prepare(); + if (!params.scriptFile.empty()) { + paths.setScriptFolder(params.scriptFile.parent_path()); + } loadSettings(); auto resdir = paths.getResourcesFolder(); diff --git a/src/files/engine_paths.cpp b/src/files/engine_paths.cpp index 0ecea7b85..2c8cd02cc 100644 --- a/src/files/engine_paths.cpp +++ b/src/files/engine_paths.cpp @@ -169,6 +169,10 @@ void EnginePaths::setResourcesFolder(std::filesystem::path folder) { this->resourcesFolder = std::move(folder); } +void EnginePaths::setScriptFolder(std::filesystem::path folder) { + this->scriptFolder = std::move(folder); +} + void EnginePaths::setCurrentWorldFolder(std::filesystem::path folder) { this->currentWorldFolder = std::move(folder); } @@ -211,7 +215,9 @@ std::filesystem::path EnginePaths::resolve( if (prefix == "export") { return userFilesFolder / EXPORT_FOLDER / fs::u8path(filename); } - + if (prefix == "script" && scriptFolder) { + return scriptFolder.value() / fs::u8path(filename); + } if (contentPacks) { for (auto& pack : *contentPacks) { if (pack.id == prefix) { diff --git a/src/files/engine_paths.hpp b/src/files/engine_paths.hpp index 61be1757b..5ec347046 100644 --- a/src/files/engine_paths.hpp +++ b/src/files/engine_paths.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,8 @@ class EnginePaths { void setResourcesFolder(std::filesystem::path folder); std::filesystem::path getResourcesFolder() const; + void setScriptFolder(std::filesystem::path folder); + std::filesystem::path getWorldFolderByName(const std::string& name); std::filesystem::path getWorldsFolder() const; std::filesystem::path getConfigFolder() const; @@ -51,6 +54,7 @@ class EnginePaths { std::filesystem::path userFilesFolder {"."}; std::filesystem::path resourcesFolder {"res"}; std::filesystem::path currentWorldFolder; + std::optional scriptFolder; std::vector* contentPacks = nullptr; };