diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 85c45173..90169137 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -346,15 +346,20 @@ void Engine::loadContent() { names.push_back(pack.id); } - ContentBuilder contentBuilder; - corecontent::setup(*input, contentBuilder); - - paths.setContentPacks(&contentPacks); PacksManager manager = createPacksManager(paths.getCurrentWorldFolder()); manager.scan(); names = manager.assemble(names); contentPacks = manager.getAll(names); + std::vector entryPoints; + for (auto& pack : contentPacks) { + entryPoints.emplace_back(pack.id, pack.folder); + } + paths.setEntryPoints(std::move(entryPoints)); + + ContentBuilder contentBuilder; + corecontent::setup(*input, contentBuilder); + auto corePack = ContentPack::createCore(paths); // Setup filesystem entry points @@ -443,7 +448,12 @@ void Engine::setScreen(std::shared_ptr screen) { } void Engine::setLanguage(std::string locale) { - langs::setup("res:", std::move(locale), resPaths->collectRoots()); + langs::setup( + "res:", + std::move(locale), + resPaths ? resPaths->collectRoots() + : std::vector {{"core", "res:"}} + ); } void Engine::onWorldOpen(std::unique_ptr level, int64_t localPlayer) { diff --git a/src/io/engine_paths.cpp b/src/io/engine_paths.cpp index 07ab2060..cccdf934 100644 --- a/src/io/engine_paths.cpp +++ b/src/io/engine_paths.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include "typedefs.hpp" @@ -192,15 +191,15 @@ void EnginePaths::unmount(const std::string& name) { mounted.erase(found); } -std::string EnginePaths::createWriteablePackDevice(const std::string& name) { - const auto& found = writeablePacks.find(name); - if (found != writeablePacks.end()) { +std::string EnginePaths::createWriteableDevice(const std::string& name) { + const auto& found = writeables.find(name); + if (found != writeables.end()) { return found->second; } io::path folder; - for (const auto& pack : *contentPacks) { - if (pack.id == name) { - folder = pack.folder; + for (const auto& point : entryPoints) { + if (point.name == name) { + folder = point.path; break; } } @@ -209,29 +208,33 @@ std::string EnginePaths::createWriteablePackDevice(const std::string& name) { } auto entryPoint = std::string("W.") + generate_random_base64<6>(); io::create_subdevice(entryPoint, folder.entryPoint(), folder.pathPart()); - writeablePacks[name] = entryPoint; + writeables[name] = entryPoint; return entryPoint; } -void EnginePaths::setContentPacks(std::vector* contentPacks) { +void EnginePaths::cleanup() { // Remove previous content entry-points - for (const auto& id : contentEntryPoints) { + for (const auto& [id, _] : entryPoints) { io::remove_device(id); } - for (const auto& [_, entryPoint] : writeablePacks) { + for (const auto& [_, entryPoint] : writeables) { io::remove_device(entryPoint); } for (const auto& entryPoint : mounted) { io::remove_device(entryPoint); } - contentEntryPoints.clear(); - this->contentPacks = contentPacks; - // Create content devices - for (const auto& pack : *contentPacks) { - auto parent = pack.folder.entryPoint(); - io::create_subdevice(pack.id, parent, pack.folder); - contentEntryPoints.push_back(pack.id); + entryPoints.clear(); +} + +void EnginePaths::setEntryPoints(std::vector entryPoints) { + cleanup(); + + // Create sub-devices + for (const auto& point : entryPoints) { + auto parent = point.path.entryPoint(); + io::create_subdevice(point.name, parent, point.path); } + this->entryPoints = std::move(entryPoints); } std::tuple EnginePaths::parsePath(std::string_view path) { diff --git a/src/io/engine_paths.hpp b/src/io/engine_paths.hpp index 1d35185b..a883fb98 100644 --- a/src/io/engine_paths.hpp +++ b/src/io/engine_paths.hpp @@ -9,7 +9,15 @@ #include "io.hpp" #include "data/dv.hpp" -#include "content/ContentPack.hpp" + +struct PathsRoot { + std::string name; + io::path path; + + PathsRoot(std::string name, io::path path) + : name(std::move(name)), path(std::move(path)) { + } +}; class EnginePaths { public: @@ -37,9 +45,9 @@ public: std::string mount(const io::path& file); void unmount(const std::string& name); - std::string createWriteablePackDevice(const std::string& name); + std::string createWriteableDevice(const std::string& name); - void setContentPacks(std::vector* contentPacks); + void setEntryPoints(std::vector entryPoints); std::vector scanForWorlds() const; @@ -51,15 +59,11 @@ private: std::filesystem::path resourcesFolder {"res"}; io::path currentWorldFolder; std::optional scriptFolder; - std::vector* contentPacks = nullptr; - std::vector contentEntryPoints; - std::unordered_map writeablePacks; + std::vector entryPoints; + std::unordered_map writeables; std::vector mounted; -}; -struct PathsRoot { - std::string name; - io::path path; + void cleanup(); }; class ResPaths { diff --git a/src/logic/scripting/lua/libs/libpack.cpp b/src/logic/scripting/lua/libs/libpack.cpp index 4f41cdeb..1e37a8c8 100644 --- a/src/logic/scripting/lua/libs/libpack.cpp +++ b/src/logic/scripting/lua/libs/libpack.cpp @@ -258,7 +258,7 @@ static int l_pack_request_writeable(lua::State* L) { auto str = langs::get(L"Grant %{0} pack modification permission?"); util::replaceAll(str, L"%{0}", util::str2wstr_utf8(packid)); guiutil::confirm(*engine, str, [packid, handler]() { - handler({engine->getPaths().createWriteablePackDevice(packid)}); + handler({engine->getPaths().createWriteableDevice(packid)}); engine->getGUI().getMenu()->reset(); }); return 0;