migrate from std::filesystem::path to io::path (WIP)

This commit is contained in:
MihailRis
2025-01-30 22:23:13 +03:00
parent 1e22882284
commit e0314803c0
72 changed files with 1189 additions and 791 deletions
+7 -7
View File
@@ -56,22 +56,22 @@ scriptenv UiDocument::getEnvironment() const {
std::unique_ptr<UiDocument> UiDocument::read(
const scriptenv& penv,
const std::string& name,
const fs::path& file,
const io::path& file,
const std::string& fileName
) {
const std::string text = io::read_string(file);
auto xmldoc = xml::parse(file.u8string(), text);
auto xmldoc = xml::parse(file.string(), text);
auto env = penv == nullptr
? scripting::create_doc_environment(scripting::get_root_environment(), name)
: scripting::create_doc_environment(penv, name);
gui::UiXmlReader reader(env);
auto view = reader.readXML(file.u8string(), *xmldoc->getRoot());
auto view = reader.readXML(file.string(), *xmldoc->getRoot());
view->setId("root");
uidocscript script {};
auto scriptFile = fs::path(file.u8string()+".lua");
if (fs::is_regular_file(scriptFile)) {
auto scriptFile = io::path(file.string()+".lua");
if (io::is_regular_file(scriptFile)) {
scripting::load_layout_script(
env, name, scriptFile, fileName + ".lua", script
);
@@ -80,8 +80,8 @@ std::unique_ptr<UiDocument> UiDocument::read(
}
std::shared_ptr<gui::UINode> UiDocument::readElement(
const fs::path& file, const std::string& fileName
const io::path& file, const std::string& fileName
) {
auto document = read(nullptr, file.filename().u8string(), file, fileName);
auto document = read(nullptr, file.name(), file, fileName);
return document->getRoot();
}
+3 -4
View File
@@ -4,10 +4,9 @@
#include <string>
#include <memory>
#include <filesystem>
#include <unordered_map>
namespace fs = std::filesystem;
#include "io/fwd.hpp"
namespace gui {
class UINode;
@@ -48,10 +47,10 @@ public:
static std::unique_ptr<UiDocument> read(
const scriptenv& parent_env,
const std::string& name,
const fs::path& file,
const io::path& file,
const std::string& fileName
);
static std::shared_ptr<gui::UINode> readElement(
const fs::path& file, const std::string& fileName
const io::path& file, const std::string& fileName
);
};
+11 -11
View File
@@ -69,8 +69,8 @@ namespace {
};
}
void langs::loadLocalesInfo(const fs::path& resdir, std::string& fallback) {
auto file = resdir/fs::u8path(langs::TEXTS_FOLDER)/fs::u8path("langs.json");
void langs::loadLocalesInfo(const io::path& resdir, std::string& fallback) {
auto file = resdir / langs::TEXTS_FOLDER / "langs.json";
auto root = io::read_json(file);
langs::locales_info.clear();
@@ -94,7 +94,7 @@ void langs::loadLocalesInfo(const fs::path& resdir, std::string& fallback) {
}
}
std::string langs::locale_by_envlocale(const std::string& envlocale, const fs::path& resdir){
std::string langs::locale_by_envlocale(const std::string& envlocale, const io::path& resdir){
std::string fallback = FALLBACK_DEFAULT;
if (locales_info.size() == 0) {
loadLocalesInfo(resdir, fallback);
@@ -115,21 +115,21 @@ std::string langs::locale_by_envlocale(const std::string& envlocale, const fs::p
}
}
void langs::load(const fs::path& resdir,
void langs::load(const io::path& resdir,
const std::string& locale,
const std::vector<ContentPack>& packs,
Lang& lang) {
fs::path filename = fs::path(TEXTS_FOLDER)/fs::path(locale + LANG_FILE_EXT);
fs::path core_file = resdir/filename;
io::path filename = io::path(TEXTS_FOLDER) / (locale + LANG_FILE_EXT);
io::path core_file = resdir / filename;
if (fs::is_regular_file(core_file)) {
if (io::is_regular_file(core_file)) {
std::string text = io::read_string(core_file);
Reader reader(core_file.string(), text);
reader.read(lang, "");
}
for (auto pack : packs) {
fs::path file = pack.folder/filename;
if (fs::is_regular_file(file)) {
io::path file = pack.folder / filename;
if (io::is_regular_file(file)) {
std::string text = io::read_string(file);
Reader reader(file.string(), text);
reader.read(lang, "");
@@ -137,7 +137,7 @@ void langs::load(const fs::path& resdir,
}
}
void langs::load(const fs::path& resdir,
void langs::load(const io::path& resdir,
const std::string& locale,
const std::string& fallback,
const std::vector<ContentPack>& packs) {
@@ -149,7 +149,7 @@ void langs::load(const fs::path& resdir,
current = std::move(lang);
}
void langs::setup(const fs::path& resdir,
void langs::setup(const io::path& resdir,
std::string locale,
const std::vector<ContentPack>& packs) {
std::string fallback = langs::FALLBACK_DEFAULT;
+7 -6
View File
@@ -3,9 +3,10 @@
#include <string>
#include <vector>
#include <memory>
#include <filesystem>
#include <unordered_map>
#include "io/fwd.hpp"
struct ContentPack;
namespace langs {
@@ -44,17 +45,17 @@ namespace langs {
extern std::unordered_map<std::string, LocaleInfo> locales_info;
extern void loadLocalesInfo(
const std::filesystem::path& resdir,
const io::path& resdir,
std::string& fallback);
extern std::string locale_by_envlocale(const std::string& envlocale,
const std::filesystem::path& resdir);
const io::path& resdir);
extern void load(const std::filesystem::path& resdir,
extern void load(const io::path& resdir,
const std::string& locale,
const std::vector<ContentPack>& packs,
Lang& lang);
extern void load(const std::filesystem::path& resdir,
extern void load(const io::path& resdir,
const std::string& locale,
const std::string& fallback,
const std::vector<ContentPack>& packs);
@@ -63,7 +64,7 @@ namespace langs {
extern const std::wstring& get(const std::wstring& key,
const std::wstring& context);
extern void setup(const std::filesystem::path& resdir,
extern void setup(const io::path& resdir,
std::string locale,
const std::vector<ContentPack>& packs);
}
+4 -4
View File
@@ -105,8 +105,8 @@ void LevelScreen::initializeContent() {
void LevelScreen::initializePack(ContentPackRuntime* pack) {
const ContentPack& info = pack->getInfo();
fs::path scriptFile = info.folder/fs::path("scripts/hud.lua");
if (fs::is_regular_file(scriptFile)) {
io::path scriptFile = info.folder / "scripts/hud.lua";
if (io::is_regular_file(scriptFile)) {
scripting::load_hud_script(
pack->getEnvironment(),
info.id,
@@ -124,7 +124,7 @@ LevelScreen::~LevelScreen() {
// unblock all bindings
Events::enableBindings();
controller->onWorldQuit();
engine.getPaths().setCurrentWorldFolder(fs::path());
engine.getPaths().setCurrentWorldFolder("");
}
void LevelScreen::saveWorldPreview() {
@@ -147,7 +147,7 @@ void LevelScreen::saveWorldPreview() {
worldRenderer->draw(ctx, camera, false, true, 0.0f, postProcessing.get());
auto image = postProcessing->toImage();
image->flipY();
imageio::write(paths.resolve("world:preview.png").u8string(), image.get());
imageio::write(paths.resolve("world:preview.png").string(), image.get());
} catch (const std::exception& err) {
logger.error() << err.what();
}