refactor io/engine_paths
This commit is contained in:
parent
611c6fa444
commit
dbe9ca5efe
@ -346,15 +346,20 @@ void Engine::loadContent() {
|
|||||||
names.push_back(pack.id);
|
names.push_back(pack.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentBuilder contentBuilder;
|
|
||||||
corecontent::setup(*input, contentBuilder);
|
|
||||||
|
|
||||||
paths.setContentPacks(&contentPacks);
|
|
||||||
PacksManager manager = createPacksManager(paths.getCurrentWorldFolder());
|
PacksManager manager = createPacksManager(paths.getCurrentWorldFolder());
|
||||||
manager.scan();
|
manager.scan();
|
||||||
names = manager.assemble(names);
|
names = manager.assemble(names);
|
||||||
contentPacks = manager.getAll(names);
|
contentPacks = manager.getAll(names);
|
||||||
|
|
||||||
|
std::vector<PathsRoot> 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);
|
auto corePack = ContentPack::createCore(paths);
|
||||||
|
|
||||||
// Setup filesystem entry points
|
// Setup filesystem entry points
|
||||||
@ -443,7 +448,12 @@ void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Engine::setLanguage(std::string locale) {
|
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<io::path> {{"core", "res:"}}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onWorldOpen(std::unique_ptr<Level> level, int64_t localPlayer) {
|
void Engine::onWorldOpen(std::unique_ptr<Level> level, int64_t localPlayer) {
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <filesystem>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
@ -192,15 +191,15 @@ void EnginePaths::unmount(const std::string& name) {
|
|||||||
mounted.erase(found);
|
mounted.erase(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string EnginePaths::createWriteablePackDevice(const std::string& name) {
|
std::string EnginePaths::createWriteableDevice(const std::string& name) {
|
||||||
const auto& found = writeablePacks.find(name);
|
const auto& found = writeables.find(name);
|
||||||
if (found != writeablePacks.end()) {
|
if (found != writeables.end()) {
|
||||||
return found->second;
|
return found->second;
|
||||||
}
|
}
|
||||||
io::path folder;
|
io::path folder;
|
||||||
for (const auto& pack : *contentPacks) {
|
for (const auto& point : entryPoints) {
|
||||||
if (pack.id == name) {
|
if (point.name == name) {
|
||||||
folder = pack.folder;
|
folder = point.path;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,29 +208,33 @@ std::string EnginePaths::createWriteablePackDevice(const std::string& name) {
|
|||||||
}
|
}
|
||||||
auto entryPoint = std::string("W.") + generate_random_base64<6>();
|
auto entryPoint = std::string("W.") + generate_random_base64<6>();
|
||||||
io::create_subdevice(entryPoint, folder.entryPoint(), folder.pathPart());
|
io::create_subdevice(entryPoint, folder.entryPoint(), folder.pathPart());
|
||||||
writeablePacks[name] = entryPoint;
|
writeables[name] = entryPoint;
|
||||||
return entryPoint;
|
return entryPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnginePaths::setContentPacks(std::vector<ContentPack>* contentPacks) {
|
void EnginePaths::cleanup() {
|
||||||
// Remove previous content entry-points
|
// Remove previous content entry-points
|
||||||
for (const auto& id : contentEntryPoints) {
|
for (const auto& [id, _] : entryPoints) {
|
||||||
io::remove_device(id);
|
io::remove_device(id);
|
||||||
}
|
}
|
||||||
for (const auto& [_, entryPoint] : writeablePacks) {
|
for (const auto& [_, entryPoint] : writeables) {
|
||||||
io::remove_device(entryPoint);
|
io::remove_device(entryPoint);
|
||||||
}
|
}
|
||||||
for (const auto& entryPoint : mounted) {
|
for (const auto& entryPoint : mounted) {
|
||||||
io::remove_device(entryPoint);
|
io::remove_device(entryPoint);
|
||||||
}
|
}
|
||||||
contentEntryPoints.clear();
|
entryPoints.clear();
|
||||||
this->contentPacks = contentPacks;
|
}
|
||||||
// Create content devices
|
|
||||||
for (const auto& pack : *contentPacks) {
|
void EnginePaths::setEntryPoints(std::vector<PathsRoot> entryPoints) {
|
||||||
auto parent = pack.folder.entryPoint();
|
cleanup();
|
||||||
io::create_subdevice(pack.id, parent, pack.folder);
|
|
||||||
contentEntryPoints.push_back(pack.id);
|
// 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<std::string, std::string> EnginePaths::parsePath(std::string_view path) {
|
std::tuple<std::string, std::string> EnginePaths::parsePath(std::string_view path) {
|
||||||
|
|||||||
@ -9,7 +9,15 @@
|
|||||||
|
|
||||||
#include "io.hpp"
|
#include "io.hpp"
|
||||||
#include "data/dv.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 {
|
class EnginePaths {
|
||||||
public:
|
public:
|
||||||
@ -37,9 +45,9 @@ public:
|
|||||||
std::string mount(const io::path& file);
|
std::string mount(const io::path& file);
|
||||||
void unmount(const std::string& name);
|
void unmount(const std::string& name);
|
||||||
|
|
||||||
std::string createWriteablePackDevice(const std::string& name);
|
std::string createWriteableDevice(const std::string& name);
|
||||||
|
|
||||||
void setContentPacks(std::vector<ContentPack>* contentPacks);
|
void setEntryPoints(std::vector<PathsRoot> entryPoints);
|
||||||
|
|
||||||
std::vector<io::path> scanForWorlds() const;
|
std::vector<io::path> scanForWorlds() const;
|
||||||
|
|
||||||
@ -51,15 +59,11 @@ private:
|
|||||||
std::filesystem::path resourcesFolder {"res"};
|
std::filesystem::path resourcesFolder {"res"};
|
||||||
io::path currentWorldFolder;
|
io::path currentWorldFolder;
|
||||||
std::optional<std::filesystem::path> scriptFolder;
|
std::optional<std::filesystem::path> scriptFolder;
|
||||||
std::vector<ContentPack>* contentPacks = nullptr;
|
std::vector<PathsRoot> entryPoints;
|
||||||
std::vector<std::string> contentEntryPoints;
|
std::unordered_map<std::string, std::string> writeables;
|
||||||
std::unordered_map<std::string, std::string> writeablePacks;
|
|
||||||
std::vector<std::string> mounted;
|
std::vector<std::string> mounted;
|
||||||
};
|
|
||||||
|
|
||||||
struct PathsRoot {
|
void cleanup();
|
||||||
std::string name;
|
|
||||||
io::path path;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResPaths {
|
class ResPaths {
|
||||||
|
|||||||
@ -258,7 +258,7 @@ static int l_pack_request_writeable(lua::State* L) {
|
|||||||
auto str = langs::get(L"Grant %{0} pack modification permission?");
|
auto str = langs::get(L"Grant %{0} pack modification permission?");
|
||||||
util::replaceAll(str, L"%{0}", util::str2wstr_utf8(packid));
|
util::replaceAll(str, L"%{0}", util::str2wstr_utf8(packid));
|
||||||
guiutil::confirm(*engine, str, [packid, handler]() {
|
guiutil::confirm(*engine, str, [packid, handler]() {
|
||||||
handler({engine->getPaths().createWriteablePackDevice(packid)});
|
handler({engine->getPaths().createWriteableDevice(packid)});
|
||||||
engine->getGUI().getMenu()->reset();
|
engine->getGUI().getMenu()->reset();
|
||||||
});
|
});
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user