diff --git a/res/scripts/world.lua b/res/scripts/world.lua index d2726162..18ecea91 100644 --- a/res/scripts/world.lua +++ b/res/scripts/world.lua @@ -1,4 +1,4 @@ -- use for engine development tests -- must be empty in release -- must not be modified by content-packs -print(generation.load_structure("core:generators/default.files/tree0.vox")) +print(generation.load_structure("core:default.files/tree0")) diff --git a/src/files/engine_paths.cpp b/src/files/engine_paths.cpp index 1be3ca20..d665603e 100644 --- a/src/files/engine_paths.cpp +++ b/src/files/engine_paths.cpp @@ -162,15 +162,23 @@ void EnginePaths::setContentPacks(std::vector* contentPacks) { this->contentPacks = contentPacks; } +std::tuple EnginePaths::parsePath(std::string_view path) { + size_t separator = path.find(':'); + if (separator == std::string::npos) { + return {"", std::string(path)}; + } + auto prefix = std::string(path.substr(0, separator)); + auto filename = std::string(path.substr(separator + 1)); + return {prefix, filename}; +} + std::filesystem::path EnginePaths::resolve( const std::string& path, bool throwErr ) { - size_t separator = path.find(':'); - if (separator == std::string::npos) { + auto [prefix, filename] = EnginePaths::parsePath(path); + if (prefix.empty()) { throw files_access_error("no entry point specified"); } - std::string prefix = path.substr(0, separator); - std::string filename = path.substr(separator + 1); filename = toCanonic(fs::u8path(filename)).u8string(); if (prefix == "res" || prefix == "core") { diff --git a/src/files/engine_paths.hpp b/src/files/engine_paths.hpp index ab966791..ceb2f613 100644 --- a/src/files/engine_paths.hpp +++ b/src/files/engine_paths.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "content/ContentPack.hpp" @@ -40,6 +41,7 @@ public: std::filesystem::path resolve(const std::string& path, bool throwErr = true); + static std::tuple parsePath(std::string_view view); private: std::filesystem::path userFilesFolder {"."}; std::filesystem::path resourcesFolder {"res"}; diff --git a/src/logic/scripting/lua/libgeneration.cpp b/src/logic/scripting/lua/libgeneration.cpp index c38716e9..b5e90515 100644 --- a/src/logic/scripting/lua/libgeneration.cpp +++ b/src/logic/scripting/lua/libgeneration.cpp @@ -29,8 +29,9 @@ static int l_save_structure(lua::State* L) { static int l_load_structure(lua::State* L) { auto paths = engine->getPaths(); - auto filename = lua::require_string(L, 1); - auto path = paths->resolve(filename); + auto [prefix, filename] = EnginePaths::parsePath(lua::require_string(L, 1)); + + auto path = paths->resolve(prefix+":generators/"+filename+".vox"); if (!std::filesystem::exists(path)) { throw std::runtime_error("file "+path.u8string()+" does not exist"); }