From 1e22882284e1f7889d8216acb48f4bd06d20dc7f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 30 Jan 2025 16:53:52 +0300 Subject: [PATCH] rename 'files' to 'io' --- src/assets/AssetsLoader.cpp | 6 +- src/assets/assetload_funcs.cpp | 14 ++--- src/coders/GLSLExtension.cpp | 6 +- src/coders/imageio.cpp | 4 +- src/coders/png.cpp | 4 +- src/coders/toml.cpp | 2 +- src/content/ContentLoader.cpp | 32 +++++------ src/content/ContentPack.cpp | 8 +-- src/content/ContentReport.cpp | 4 +- src/content/loading/GeneratorLoader.cpp | 8 +-- src/core_defs.cpp | 6 +- src/engine/Engine.cpp | 14 ++--- src/engine/Engine.hpp | 4 +- src/frontend/UiDocument.cpp | 4 +- src/frontend/locale.cpp | 8 +-- src/frontend/menu.cpp | 2 +- src/frontend/screens/LevelScreen.cpp | 2 +- src/graphics/render/Decorator.cpp | 2 +- src/{files => io}/engine_paths.cpp | 4 +- src/{files => io}/engine_paths.hpp | 0 src/{files/files.cpp => io/io.cpp} | 56 +++++++++---------- src/{files/files.hpp => io/io.hpp} | 2 +- src/{files => io}/settings_io.cpp | 0 src/{files => io}/settings_io.hpp | 0 src/{files => io}/util.hpp | 2 +- src/logic/EngineController.cpp | 3 - src/logic/scripting/lua/libs/libcore.cpp | 6 +- src/logic/scripting/lua/libs/libfile.cpp | 14 ++--- .../scripting/lua/libs/libgeneration.cpp | 8 +-- src/logic/scripting/lua/libs/libinput.cpp | 4 +- src/logic/scripting/lua/libs/libpack.cpp | 2 +- src/logic/scripting/lua/libs/libworld.cpp | 6 +- src/logic/scripting/lua/lua_engine.cpp | 6 +- .../lua/usertypes/lua_type_heightmap.cpp | 2 +- src/logic/scripting/scripting.cpp | 12 ++-- src/logic/scripting/scripting_hud.cpp | 6 +- .../scripting/scripting_world_generation.cpp | 4 +- src/util/command_line.cpp | 2 +- src/world/World.cpp | 6 +- src/world/files/WorldConverter.cpp | 10 ++-- src/world/files/WorldFiles.cpp | 18 +++--- src/world/files/WorldFiles.hpp | 2 +- src/world/files/WorldRegions.hpp | 4 +- test/coders/lua_parsing.cpp | 4 +- test/coders/vec3.cpp | 4 +- 45 files changed, 157 insertions(+), 160 deletions(-) rename src/{files => io}/engine_paths.cpp (96%) rename src/{files => io}/engine_paths.hpp (100%) rename src/{files/files.cpp => io/io.cpp} (72%) rename src/{files/files.hpp => io/io.hpp} (99%) rename src/{files => io}/settings_io.cpp (100%) rename src/{files => io}/settings_io.hpp (100%) rename src/{files => io}/util.hpp (95%) diff --git a/src/assets/AssetsLoader.cpp b/src/assets/AssetsLoader.cpp index 3f050055..8c7fc2dc 100644 --- a/src/assets/AssetsLoader.cpp +++ b/src/assets/AssetsLoader.cpp @@ -9,8 +9,8 @@ #include "content/Content.hpp" #include "content/ContentPack.hpp" #include "debug/Logger.hpp" -#include "files/engine_paths.hpp" -#include "files/files.hpp" +#include "io/engine_paths.hpp" +#include "io/io.hpp" #include "graphics/core/Texture.hpp" #include "logic/scripting/scripting.hpp" #include "objects/rigging.hpp" @@ -187,7 +187,7 @@ void AssetsLoader::processPreloadList(AssetType tag, const dv::value& list) { } void AssetsLoader::processPreloadConfig(const fs::path& file) { - auto root = files::read_json(file); + auto root = io::read_json(file); processPreloadList(AssetType::ATLAS, root["atlases"]); processPreloadList(AssetType::FONT, root["fonts"]); processPreloadList(AssetType::SHADER, root["shaders"]); diff --git a/src/assets/assetload_funcs.cpp b/src/assets/assetload_funcs.cpp index 399e7959..929d5e62 100644 --- a/src/assets/assetload_funcs.cpp +++ b/src/assets/assetload_funcs.cpp @@ -13,8 +13,8 @@ #include "coders/vec3.hpp" #include "constants.hpp" #include "debug/Logger.hpp" -#include "files/engine_paths.hpp" -#include "files/files.hpp" +#include "io/engine_paths.hpp" +#include "io/io.hpp" #include "frontend/UiDocument.hpp" #include "graphics/core/Atlas.hpp" #include "graphics/core/Font.hpp" @@ -72,8 +72,8 @@ assetload::postfunc assetload::shader( fs::path vertexFile = paths->find(filename + ".glslv"); fs::path fragmentFile = paths->find(filename + ".glslf"); - std::string vertexSource = files::read_string(vertexFile); - std::string fragmentSource = files::read_string(fragmentFile); + std::string vertexSource = io::read_string(vertexFile); + std::string fragmentSource = io::read_string(fragmentFile); vertexSource = Shader::preprocessor->process(vertexFile, vertexSource); fragmentSource = @@ -273,7 +273,7 @@ assetload::postfunc assetload::model( ) { auto path = paths->find(file + ".vec3"); if (fs::exists(path)) { - auto bytes = files::read_bytes_buffer(path); + auto bytes = io::read_bytes_buffer(path); auto modelVEC3 = std::make_shared(vec3::load(path.u8string(), bytes)); return [loader, name, modelVEC3=std::move(modelVEC3)](Assets* assets) { for (auto& [modelName, model] : modelVEC3->models) { @@ -292,7 +292,7 @@ assetload::postfunc assetload::model( }; } path = paths->find(file + ".obj"); - auto text = files::read_string(path); + auto text = io::read_string(path); try { auto model = obj::parse(path.u8string(), text).release(); return [=](Assets* assets) { @@ -309,7 +309,7 @@ static void read_anim_file( const std::string& animFile, std::vector>& frameList ) { - auto root = files::read_json(animFile); + auto root = io::read_json(animFile); float frameDuration = DEFAULT_FRAME_DURATION; std::string frameName; diff --git a/src/coders/GLSLExtension.cpp b/src/coders/GLSLExtension.cpp index 186522a5..c7f45cd7 100644 --- a/src/coders/GLSLExtension.cpp +++ b/src/coders/GLSLExtension.cpp @@ -5,8 +5,8 @@ #include #include -#include "files/engine_paths.hpp" -#include "files/files.hpp" +#include "io/engine_paths.hpp" +#include "io/io.hpp" #include "typedefs.hpp" #include "util/stringutil.hpp" @@ -22,7 +22,7 @@ void GLSLExtension::setPaths(const ResPaths* paths) { void GLSLExtension::loadHeader(const std::string& name) { fs::path file = paths->find("shaders/lib/" + name + ".glsl"); - std::string source = files::read_string(file); + std::string source = io::read_string(file); addHeader(name, ""); addHeader(name, process(file, source, true)); } diff --git a/src/coders/imageio.cpp b/src/coders/imageio.cpp index a80f422c..5f082abc 100644 --- a/src/coders/imageio.cpp +++ b/src/coders/imageio.cpp @@ -5,7 +5,7 @@ #include #include "graphics/core/ImageData.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "png.hpp" namespace fs = std::filesystem; @@ -41,7 +41,7 @@ std::unique_ptr imageio::read(const fs::path& filename) { "file format is not supported (read): " + filename.u8string() ); } - auto bytes = files::read_bytes_buffer(filename); + auto bytes = io::read_bytes_buffer(filename); try { return std::unique_ptr(found->second(bytes.data(), bytes.size())); } catch (const std::runtime_error& err) { diff --git a/src/coders/png.cpp b/src/coders/png.cpp index b29afd34..6671922c 100644 --- a/src/coders/png.cpp +++ b/src/coders/png.cpp @@ -6,7 +6,7 @@ #include #include "debug/Logger.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "graphics/core/GLTexture.hpp" #include "graphics/core/ImageData.hpp" @@ -212,7 +212,7 @@ std::unique_ptr png::load_texture(const ubyte* bytes, size_t size) { } std::unique_ptr png::load_texture(const std::string& filename) { - auto bytes = files::read_bytes_buffer(fs::u8path(filename)); + auto bytes = io::read_bytes_buffer(fs::u8path(filename)); try { return load_texture(bytes.data(), bytes.size()); } catch (const std::runtime_error& err) { diff --git a/src/coders/toml.cpp b/src/coders/toml.cpp index 080df90e..3896bcec 100644 --- a/src/coders/toml.cpp +++ b/src/coders/toml.cpp @@ -7,7 +7,7 @@ #include #include "data/setting.hpp" -#include "files/settings_io.hpp" +#include "io/settings_io.hpp" #include "util/stringutil.hpp" #include "commons.hpp" diff --git a/src/content/ContentLoader.cpp b/src/content/ContentLoader.cpp index ce3f5060..1603334d 100644 --- a/src/content/ContentLoader.cpp +++ b/src/content/ContentLoader.cpp @@ -12,7 +12,7 @@ #include "coders/json.hpp" #include "core_defs.hpp" #include "debug/Logger.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "items/ItemDef.hpp" #include "logic/scripting/scripting.hpp" #include "objects/rigging.hpp" @@ -54,8 +54,8 @@ static void detect_defs( if (name[0] == '_') { continue; } - if (fs::is_regular_file(file) && files::is_data_file(file)) { - auto map = files::read_object(file); + if (fs::is_regular_file(file) && io::is_data_file(file)) { + auto map = io::read_object(file); std::string id = prefix.empty() ? name : prefix + ":" + name; detected.emplace_back(id); } else if (fs::is_directory(file) && @@ -78,9 +78,9 @@ static void detect_defs_pairs( if (name[0] == '_') { continue; } - if (fs::is_regular_file(file) && files::is_data_file(file)) { + if (fs::is_regular_file(file) && io::is_data_file(file)) { try { - auto map = files::read_object(file); + auto map = io::read_object(file); auto id = prefix.empty() ? name : prefix + ":" + name; auto caption = util::id_to_caption(id); map.at("caption").get(caption); @@ -147,7 +147,7 @@ void ContentLoader::fixPackIndices() { dv::value root; if (fs::is_regular_file(contentFile)) { - root = files::read_json(contentFile); + root = io::read_json(contentFile); } else { root = dv::object(); } @@ -159,7 +159,7 @@ void ContentLoader::fixPackIndices() { if (modified) { // rewrite modified json - files::write_json(contentFile, root); + io::write_json(contentFile, root); } } @@ -215,7 +215,7 @@ static void process_method( void ContentLoader::loadBlock( Block& def, const std::string& name, const fs::path& file ) { - auto root = files::read_json(file); + auto root = io::read_json(file); if (def.properties == nullptr) { def.properties = dv::object(); def.properties["name"] = name; @@ -404,7 +404,7 @@ void ContentLoader::loadBlock( void ContentLoader::loadItem( ItemDef& def, const std::string& name, const fs::path& file ) { - auto root = files::read_json(file); + auto root = io::read_json(file); def.properties = root; if (root.has("parent")) { @@ -448,7 +448,7 @@ void ContentLoader::loadItem( void ContentLoader::loadEntity( EntityDef& def, const std::string& name, const fs::path& file ) { - auto root = files::read_json(file); + auto root = io::read_json(file); if (root.has("parent")) { const auto& parentName = root["parent"].asString(); @@ -568,7 +568,7 @@ static std::tuple create_unit_id( void ContentLoader::loadBlockMaterial( BlockMaterial& def, const fs::path& file ) { - auto root = files::read_json(file); + auto root = io::read_json(file); root.at("steps-sound").get(def.stepsSound); root.at("place-sound").get(def.placeSound); root.at("break-sound").get(def.breakSound); @@ -580,7 +580,7 @@ void ContentLoader::loadContent(const dv::value& root) { auto configFile = pack->folder / fs::path(prefix + "/" + name + ".json"); std::string parent; if (fs::exists(configFile)) { - auto root = files::read_json(configFile); + auto root = io::read_json(configFile); root.at("parent").get(parent); } return parent; @@ -778,7 +778,7 @@ void ContentLoader::load() { // Load pack resources.json fs::path resourcesFile = folder / fs::u8path("resources.json"); if (fs::exists(resourcesFile)) { - auto resRoot = files::read_json(resourcesFile); + auto resRoot = io::read_json(resourcesFile); for (const auto& [key, arr] : resRoot.asObject()) { if (auto resType = ResourceType_from(key)) { loadResources(*resType, arr); @@ -792,7 +792,7 @@ void ContentLoader::load() { // Load pack resources aliases fs::path aliasesFile = folder / fs::u8path("resource-aliases.json"); if (fs::exists(aliasesFile)) { - auto resRoot = files::read_json(aliasesFile); + auto resRoot = io::read_json(aliasesFile); for (const auto& [key, arr] : resRoot.asObject()) { if (auto resType = ResourceType_from(key)) { loadResourceAliases(*resType, arr); @@ -821,7 +821,7 @@ void ContentLoader::load() { fs::path skeletonsDir = folder / fs::u8path("skeletons"); foreach_file(skeletonsDir, [this](const fs::path& file) { std::string name = pack->id + ":" + file.stem().u8string(); - std::string text = files::read_string(file); + std::string text = io::read_string(file); builder.add( rigging::SkeletonConfig::parse(text, file.u8string(), name) ); @@ -830,7 +830,7 @@ void ContentLoader::load() { // Process content.json and load defined content units auto contentFile = pack->getContentFile(); if (fs::exists(contentFile)) { - loadContent(files::read_json(contentFile)); + loadContent(io::read_json(contentFile)); } } diff --git a/src/content/ContentPack.cpp b/src/content/ContentPack.cpp index 7135f231..9bcec23c 100644 --- a/src/content/ContentPack.cpp +++ b/src/content/ContentPack.cpp @@ -7,8 +7,8 @@ #include "coders/json.hpp" #include "constants.hpp" #include "data/dv.hpp" -#include "files/engine_paths.hpp" -#include "files/files.hpp" +#include "io/engine_paths.hpp" +#include "io/io.hpp" namespace fs = std::filesystem; @@ -71,7 +71,7 @@ static void checkContentPackId(const std::string& id, const fs::path& folder) { } ContentPack ContentPack::read(const std::string& path, const fs::path& folder) { - auto root = files::read_json(folder / fs::path(PACKAGE_FILENAME)); + auto root = io::read_json(folder / fs::path(PACKAGE_FILENAME)); ContentPack pack; root.at("id").get(pack.id); root.at("title").get(pack.title); @@ -151,7 +151,7 @@ std::vector ContentPack::worldPacksList(const fs::path& folder) { if (!fs::is_regular_file(listfile)) { throw std::runtime_error("missing file 'packs.list'"); } - return files::read_list(listfile); + return io::read_list(listfile); } fs::path ContentPack::findPack( diff --git a/src/content/ContentReport.cpp b/src/content/ContentReport.cpp index c25a903a..c9043507 100644 --- a/src/content/ContentReport.cpp +++ b/src/content/ContentReport.cpp @@ -4,7 +4,7 @@ #include "coders/json.hpp" #include "constants.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "items/ItemDef.hpp" #include "voxels/Block.hpp" #include "world/World.hpp" @@ -75,7 +75,7 @@ std::shared_ptr ContentReport::create( return nullptr; } - auto root = files::read_json(filename); + auto root = io::read_json(filename); uint regionsVersion = 2U; // old worlds compatibility (pre 0.23) root.at("region-version").get(regionsVersion); auto& blocklist = root["blocks"]; diff --git a/src/content/loading/GeneratorLoader.cpp b/src/content/loading/GeneratorLoader.cpp index f9f06d80..2e903426 100644 --- a/src/content/loading/GeneratorLoader.cpp +++ b/src/content/loading/GeneratorLoader.cpp @@ -4,8 +4,8 @@ #include "../ContentPack.hpp" -#include "files/files.hpp" -#include "files/engine_paths.hpp" +#include "io/io.hpp" +#include "io/engine_paths.hpp" #include "logic/scripting/scripting.hpp" #include "world/generator/GeneratorDef.hpp" #include "world/generator/VoxelFragment.hpp" @@ -146,7 +146,7 @@ static std::vector> load_structures( structFile.u8string()); } auto fragment = std::make_unique(); - fragment->deserialize(files::read_binary_json(structFile)); + fragment->deserialize(io::read_binary_json(structFile)); logger.info() << "fragment " << name << " has size [" << fragment->getSize().x << ", " << fragment->getSize().y << ", " << fragment->getSize().z << "]"; @@ -202,7 +202,7 @@ void ContentLoader::loadGenerator( if (!fs::exists(generatorFile)) { return; } - auto map = files::read_toml(generatorsDir / fs::u8path(name + ".toml")); + auto map = io::read_toml(generatorsDir / fs::u8path(name + ".toml")); map.at("caption").get(def.caption); map.at("biome-parameters").get(def.biomeParameters); map.at("biome-bpd").get(def.biomesBPD); diff --git a/src/core_defs.cpp b/src/core_defs.cpp index fb8540ba..04ef4101 100644 --- a/src/core_defs.cpp +++ b/src/core_defs.cpp @@ -3,8 +3,8 @@ #include "items/ItemDef.hpp" #include "content/Content.hpp" #include "content/ContentBuilder.hpp" -#include "files/files.hpp" -#include "files/engine_paths.hpp" +#include "io/io.hpp" +#include "io/engine_paths.hpp" #include "window/Window.hpp" #include "window/Events.hpp" #include "window/input.hpp" @@ -31,7 +31,7 @@ void corecontent::setup(const EnginePaths& paths, ContentBuilder& builder) { auto bindsFile = paths.getResourcesFolder()/fs::path("bindings.toml"); if (fs::is_regular_file(bindsFile)) { Events::loadBindings( - bindsFile.u8string(), files::read_string(bindsFile), BindType::BIND + bindsFile.u8string(), io::read_string(bindsFile), BindType::BIND ); } diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 73704468..a9aa2b98 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -16,7 +16,7 @@ #include "content/ContentBuilder.hpp" #include "content/ContentLoader.hpp" #include "core_defs.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "frontend/locale.hpp" #include "frontend/menu.hpp" #include "frontend/screens/Screen.hpp" @@ -128,14 +128,14 @@ void Engine::initialize(CoreParameters coreParameters) { keepAlive(settings.ui.language.observe([this](auto lang) { setLanguage(lang); }, true)); - basePacks = files::read_list(resdir/fs::path("config/builtins.list")); + basePacks = io::read_list(resdir/fs::path("config/builtins.list")); } void Engine::loadSettings() { fs::path settings_file = paths.getSettingsFile(); if (fs::is_regular_file(settings_file)) { logger.info() << "loading settings"; - std::string text = files::read_string(settings_file); + std::string text = io::read_string(settings_file); try { toml::parse(*settingsHandler, settings_file.string(), text); } catch (const parsing_error& err) { @@ -149,7 +149,7 @@ void Engine::loadControls() { fs::path controls_file = paths.getControlsFile(); if (fs::is_regular_file(controls_file)) { logger.info() << "loading controls"; - std::string text = files::read_string(controls_file); + std::string text = io::read_string(controls_file); Events::loadBindings(controls_file.u8string(), text, BindType::BIND); } } @@ -219,10 +219,10 @@ void Engine::renderFrame() { void Engine::saveSettings() { logger.info() << "saving settings"; - files::write_string(paths.getSettingsFile(), toml::stringify(*settingsHandler)); + io::write_string(paths.getSettingsFile(), toml::stringify(*settingsHandler)); if (!params.headless) { logger.info() << "saving bindings"; - files::write_string(paths.getControlsFile(), Events::writeBindings()); + io::write_string(paths.getControlsFile(), Events::writeBindings()); } } @@ -330,7 +330,7 @@ static void load_configs(const fs::path& root) { auto bindsFile = configFolder/fs::path("bindings.toml"); if (fs::is_regular_file(bindsFile)) { Events::loadBindings( - bindsFile.u8string(), files::read_string(bindsFile), BindType::BIND + bindsFile.u8string(), io::read_string(bindsFile), BindType::BIND ); } } diff --git a/src/engine/Engine.hpp b/src/engine/Engine.hpp index d4cbf40a..fd6cb1c3 100644 --- a/src/engine/Engine.hpp +++ b/src/engine/Engine.hpp @@ -8,8 +8,8 @@ #include "content/content_fwd.hpp" #include "content/ContentPack.hpp" #include "content/PacksManager.hpp" -#include "files/engine_paths.hpp" -#include "files/settings_io.hpp" +#include "io/engine_paths.hpp" +#include "io/settings_io.hpp" #include "util/ObjectsKeeper.hpp" #include "PostRunnables.hpp" #include "Time.hpp" diff --git a/src/frontend/UiDocument.cpp b/src/frontend/UiDocument.cpp index 2108b46e..91c1e0a0 100644 --- a/src/frontend/UiDocument.cpp +++ b/src/frontend/UiDocument.cpp @@ -2,7 +2,7 @@ #include -#include "files/files.hpp" +#include "io/io.hpp" #include "graphics/ui/elements/UINode.hpp" #include "graphics/ui/elements/InventoryView.hpp" #include "graphics/ui/gui_xml.hpp" @@ -59,7 +59,7 @@ std::unique_ptr UiDocument::read( const fs::path& file, const std::string& fileName ) { - const std::string text = files::read_string(file); + const std::string text = io::read_string(file); auto xmldoc = xml::parse(file.u8string(), text); auto env = penv == nullptr diff --git a/src/frontend/locale.cpp b/src/frontend/locale.cpp index 2af78076..bc60cc38 100644 --- a/src/frontend/locale.cpp +++ b/src/frontend/locale.cpp @@ -5,7 +5,7 @@ #include "coders/json.hpp" #include "coders/commons.hpp" #include "content/ContentPack.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "util/stringutil.hpp" #include "data/dv.hpp" #include "debug/Logger.hpp" @@ -71,7 +71,7 @@ namespace { void langs::loadLocalesInfo(const fs::path& resdir, std::string& fallback) { auto file = resdir/fs::u8path(langs::TEXTS_FOLDER)/fs::u8path("langs.json"); - auto root = files::read_json(file); + auto root = io::read_json(file); langs::locales_info.clear(); root.at("fallback").get(fallback); @@ -123,14 +123,14 @@ void langs::load(const fs::path& resdir, fs::path core_file = resdir/filename; if (fs::is_regular_file(core_file)) { - std::string text = files::read_string(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)) { - std::string text = files::read_string(file); + std::string text = io::read_string(file); Reader reader(file.string(), text); reader.read(lang, ""); } diff --git a/src/frontend/menu.cpp b/src/frontend/menu.cpp index 4a36410c..da2e6ba2 100644 --- a/src/frontend/menu.cpp +++ b/src/frontend/menu.cpp @@ -8,7 +8,7 @@ #include "engine/Engine.hpp" #include "data/dv.hpp" #include "interfaces/Task.hpp" -#include "files/engine_paths.hpp" +#include "io/engine_paths.hpp" #include "graphics/ui/elements/Menu.hpp" #include "graphics/ui/gui_util.hpp" #include "graphics/ui/GUI.hpp" diff --git a/src/frontend/screens/LevelScreen.cpp b/src/frontend/screens/LevelScreen.cpp index 0e9eb609..fe9156cc 100644 --- a/src/frontend/screens/LevelScreen.cpp +++ b/src/frontend/screens/LevelScreen.cpp @@ -6,7 +6,7 @@ #include "core_defs.hpp" #include "debug/Logger.hpp" #include "engine/Engine.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "frontend/LevelFrontend.hpp" #include "frontend/hud.hpp" #include "graphics/core/DrawContext.hpp" diff --git a/src/graphics/render/Decorator.cpp b/src/graphics/render/Decorator.cpp index e6331820..605e9ec6 100644 --- a/src/graphics/render/Decorator.cpp +++ b/src/graphics/render/Decorator.cpp @@ -16,7 +16,7 @@ #include "logic/LevelController.hpp" #include "util/stringutil.hpp" #include "engine/Engine.hpp" -#include "files/files.hpp" +#include "io/io.hpp" namespace fs = std::filesystem; diff --git a/src/files/engine_paths.cpp b/src/io/engine_paths.cpp similarity index 96% rename from src/files/engine_paths.cpp rename to src/io/engine_paths.cpp index 0cb90de8..df5b8347 100644 --- a/src/files/engine_paths.cpp +++ b/src/io/engine_paths.cpp @@ -293,7 +293,7 @@ dv::value ResPaths::readCombinedList(const std::string& filename) const { continue; } try { - auto value = files::read_object(path); + auto value = io::read_object(path); if (!value.isList()) { logger.warning() << "reading combined list " << root.name << ":" << filename << " is not a list (skipped)"; @@ -318,7 +318,7 @@ dv::value ResPaths::readCombinedObject(const std::string& filename) const { continue; } try { - auto value = files::read_object(path); + auto value = io::read_object(path); if (!value.isObject()) { logger.warning() << "reading combined object " << root.name << ": " diff --git a/src/files/engine_paths.hpp b/src/io/engine_paths.hpp similarity index 100% rename from src/files/engine_paths.hpp rename to src/io/engine_paths.hpp diff --git a/src/files/files.cpp b/src/io/io.cpp similarity index 72% rename from src/files/files.cpp rename to src/io/io.cpp index f7d3f460..9979b950 100644 --- a/src/files/files.cpp +++ b/src/io/io.cpp @@ -1,4 +1,4 @@ -#include "files.hpp" +#include "io.hpp" #include @@ -15,7 +15,7 @@ namespace fs = std::filesystem; -files::rafile::rafile(const fs::path& filename) +io::rafile::rafile(const fs::path& filename) : file(filename, std::ios::binary | std::ios::ate) { if (!file) { throw std::runtime_error("could not to open file " + filename.string()); @@ -24,19 +24,19 @@ files::rafile::rafile(const fs::path& filename) file.seekg(0); } -size_t files::rafile::length() const { +size_t io::rafile::length() const { return filelength; } -void files::rafile::seekg(std::streampos pos) { +void io::rafile::seekg(std::streampos pos) { file.seekg(pos); } -void files::rafile::read(char* buffer, std::streamsize size) { +void io::rafile::read(char* buffer, std::streamsize size) { file.read(buffer, size); } -bool files::write_bytes( +bool io::write_bytes( const fs::path& filename, const ubyte* data, size_t size ) { std::ofstream output(filename, std::ios::binary); @@ -46,7 +46,7 @@ bool files::write_bytes( return true; } -uint files::append_bytes( +uint io::append_bytes( const fs::path& filename, const ubyte* data, size_t size ) { std::ofstream output(filename, std::ios::binary | std::ios::app); @@ -57,7 +57,7 @@ uint files::append_bytes( return position; } -bool files::read(const fs::path& filename, char* data, size_t size) { +bool io::read(const fs::path& filename, char* data, size_t size) { std::ifstream output(filename, std::ios::binary); if (!output.is_open()) return false; output.read(data, size); @@ -65,13 +65,13 @@ bool files::read(const fs::path& filename, char* data, size_t size) { return true; } -util::Buffer files::read_bytes_buffer(const fs::path& path) { +util::Buffer io::read_bytes_buffer(const fs::path& path) { size_t size; - auto bytes = files::read_bytes(path, size); + auto bytes = io::read_bytes(path, size); return util::Buffer(std::move(bytes), size); } -std::unique_ptr files::read_bytes( +std::unique_ptr io::read_bytes( const fs::path& filename, size_t& length ) { std::ifstream input(filename, std::ios::binary); @@ -90,7 +90,7 @@ std::unique_ptr files::read_bytes( return data; } -std::vector files::read_bytes(const fs::path& filename) { +std::vector io::read_bytes(const fs::path& filename) { std::ifstream input(filename, std::ios::binary); if (!input.is_open()) return {}; input.seekg(0, std::ios_base::end); @@ -104,13 +104,13 @@ std::vector files::read_bytes(const fs::path& filename) { return data; } -std::string files::read_string(const fs::path& filename) { +std::string io::read_string(const fs::path& filename) { size_t size; auto bytes = read_bytes(filename, size); return std::string((const char*)bytes.get(), size); } -bool files::write_string(const fs::path& filename, std::string_view content) { +bool io::write_string(const fs::path& filename, std::string_view content) { std::ofstream file(filename); if (!file) { return false; @@ -119,35 +119,35 @@ bool files::write_string(const fs::path& filename, std::string_view content) { return true; } -bool files::write_json( +bool io::write_json( const fs::path& filename, const dv::value& obj, bool nice ) { - return files::write_string(filename, json::stringify(obj, nice, " ")); + return io::write_string(filename, json::stringify(obj, nice, " ")); } -bool files::write_binary_json( +bool io::write_binary_json( const fs::path& filename, const dv::value& obj, bool compression ) { auto bytes = json::to_binary(obj, compression); - return files::write_bytes(filename, bytes.data(), bytes.size()); + return io::write_bytes(filename, bytes.data(), bytes.size()); } -dv::value files::read_json(const fs::path& filename) { - std::string text = files::read_string(filename); +dv::value io::read_json(const fs::path& filename) { + std::string text = io::read_string(filename); return json::parse(filename.string(), text); } -dv::value files::read_binary_json(const fs::path& file) { +dv::value io::read_binary_json(const fs::path& file) { size_t size; - auto bytes = files::read_bytes(file, size); + auto bytes = io::read_bytes(file, size); return json::from_binary(bytes.get(), size); } -dv::value files::read_toml(const fs::path& file) { - return toml::parse(file.u8string(), files::read_string(file)); +dv::value io::read_toml(const fs::path& file) { + return toml::parse(file.u8string(), io::read_string(file)); } -std::vector files::read_list(const fs::path& filename) { +std::vector io::read_list(const fs::path& filename) { std::ifstream file(filename); if (!file) { throw std::runtime_error( @@ -177,15 +177,15 @@ static std::map data_decoders { {fs::u8path(".toml"), toml::parse}, }; -bool files::is_data_file(const fs::path& file) { +bool io::is_data_file(const fs::path& file) { return is_data_interchange_format(file.extension()); } -bool files::is_data_interchange_format(const fs::path& ext) { +bool io::is_data_interchange_format(const fs::path& ext) { return data_decoders.find(ext) != data_decoders.end(); } -dv::value files::read_object(const fs::path& file) { +dv::value io::read_object(const fs::path& file) { const auto& found = data_decoders.find(file.extension()); if (found == data_decoders.end()) { throw std::runtime_error("unknown file format"); diff --git a/src/files/files.hpp b/src/io/io.hpp similarity index 99% rename from src/files/files.hpp rename to src/io/io.hpp index 4cf509d4..5ea4c93e 100644 --- a/src/files/files.hpp +++ b/src/io/io.hpp @@ -12,7 +12,7 @@ namespace fs = std::filesystem; -namespace files { +namespace io { /// @brief Read-only random access file class rafile { std::ifstream file; diff --git a/src/files/settings_io.cpp b/src/io/settings_io.cpp similarity index 100% rename from src/files/settings_io.cpp rename to src/io/settings_io.cpp diff --git a/src/files/settings_io.hpp b/src/io/settings_io.hpp similarity index 100% rename from src/files/settings_io.hpp rename to src/io/settings_io.hpp diff --git a/src/files/util.hpp b/src/io/util.hpp similarity index 95% rename from src/files/util.hpp rename to src/io/util.hpp index 5967299e..df7682b9 100644 --- a/src/files/util.hpp +++ b/src/io/util.hpp @@ -3,7 +3,7 @@ #include #include -namespace files { +namespace io { inline bool is_valid_name(std::string_view name) { static std::string illegalChars = "\\/%?!<>:; "; for (char c : illegalChars) { diff --git a/src/logic/EngineController.cpp b/src/logic/EngineController.cpp index 9eeea3a6..fc0b1cb0 100644 --- a/src/logic/EngineController.cpp +++ b/src/logic/EngineController.cpp @@ -74,9 +74,6 @@ std::shared_ptr create_converter( content, report, [&engine, postRunnable]() { - //auto menu = engine.getGUI()->getMenu(); - //menu->reset(); - //menu->setPage("main", false); engine.postRunnable([=]() { postRunnable(); }); }, mode, diff --git a/src/logic/scripting/lua/libs/libcore.cpp b/src/logic/scripting/lua/libs/libcore.cpp index 80128971..3566e990 100644 --- a/src/logic/scripting/lua/libs/libcore.cpp +++ b/src/logic/scripting/lua/libs/libcore.cpp @@ -7,9 +7,9 @@ #include "content/Content.hpp" #include "debug/Logger.hpp" #include "engine/Engine.hpp" -#include "files/engine_paths.hpp" -#include "files/files.hpp" -#include "files/settings_io.hpp" +#include "io/engine_paths.hpp" +#include "io/io.hpp" +#include "io/settings_io.hpp" #include "frontend/menu.hpp" #include "frontend/screens/MenuScreen.hpp" #include "graphics/core/Texture.hpp" diff --git a/src/logic/scripting/lua/libs/libfile.cpp b/src/logic/scripting/lua/libs/libfile.cpp index 7fc70f46..cedef89b 100644 --- a/src/logic/scripting/lua/libs/libfile.cpp +++ b/src/logic/scripting/lua/libs/libfile.cpp @@ -4,8 +4,8 @@ #include "coders/gzip.hpp" #include "engine/Engine.hpp" -#include "files/engine_paths.hpp" -#include "files/files.hpp" +#include "io/engine_paths.hpp" +#include "io/io.hpp" #include "util/stringutil.hpp" #include "api_lua.hpp" #include "../lua_engine.hpp" @@ -41,7 +41,7 @@ static int l_resolve(lua::State* L) { static int l_read(lua::State* L) { fs::path path = resolve_path(lua::require_string(L, 1)); if (fs::is_regular_file(path)) { - return lua::pushstring(L, files::read_string(path)); + return lua::pushstring(L, io::read_string(path)); } throw std::runtime_error( "file does not exists " + util::quote(path.u8string()) @@ -65,7 +65,7 @@ static fs::path get_writeable_path(lua::State* L) { static int l_write(lua::State* L) { fs::path path = get_writeable_path(L); std::string text = lua::require_string(L, 2); - files::write_string(path, text); + io::write_string(path, text); return 1; } @@ -128,7 +128,7 @@ static int l_read_bytes(lua::State* L) { if (fs::is_regular_file(path)) { size_t length = static_cast(fs::file_size(path)); - auto bytes = files::read_bytes(path, length); + auto bytes = io::read_bytes(path, length); lua::createtable(L, length, 0); int newTable = lua::gettop(L); @@ -150,14 +150,14 @@ static int l_write_bytes(lua::State* L) { if (auto bytearray = lua::touserdata(L, 2)) { auto& bytes = bytearray->data(); return lua::pushboolean( - L, files::write_bytes(path, bytes.data(), bytes.size()) + L, io::write_bytes(path, bytes.data(), bytes.size()) ); } std::vector bytes; lua::read_bytes_from_table(L, 2, bytes); return lua::pushboolean( - L, files::write_bytes(path, bytes.data(), bytes.size()) + L, io::write_bytes(path, bytes.data(), bytes.size()) ); } diff --git a/src/logic/scripting/lua/libs/libgeneration.cpp b/src/logic/scripting/lua/libs/libgeneration.cpp index 90b681c3..3f4bc570 100644 --- a/src/logic/scripting/lua/libs/libgeneration.cpp +++ b/src/logic/scripting/lua/libs/libgeneration.cpp @@ -1,7 +1,7 @@ #include "api_lua.hpp" -#include "files/files.hpp" -#include "files/util.hpp" +#include "io/io.hpp" +#include "io/util.hpp" #include "coders/binary_json.hpp" #include "world/Level.hpp" #include "world/generator/VoxelFragment.hpp" @@ -17,7 +17,7 @@ static int l_save_fragment(lua::State* L) { auto file = paths.resolve(lua::require_string(L, 2), true); auto map = fragment->getFragment()->serialize(); auto bytes = json::to_binary(map, true); - files::write_bytes(file, bytes.data(), bytes.size()); + io::write_bytes(file, bytes.data(), bytes.size()); return 0; } @@ -41,7 +41,7 @@ static int l_load_fragment(lua::State* L) { if (!std::filesystem::exists(path)) { throw std::runtime_error("file "+path.u8string()+" does not exist"); } - auto map = files::read_binary_json(path); + auto map = io::read_binary_json(path); auto fragment = std::make_shared(); fragment->deserialize(map); diff --git a/src/logic/scripting/lua/libs/libinput.cpp b/src/logic/scripting/lua/libs/libinput.cpp index 4121a384..6796ade2 100644 --- a/src/logic/scripting/lua/libs/libinput.cpp +++ b/src/logic/scripting/lua/libs/libinput.cpp @@ -1,7 +1,7 @@ #include #include "engine/Engine.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "frontend/hud.hpp" #include "frontend/screens/Screen.hpp" #include "graphics/ui/GUI.hpp" @@ -141,7 +141,7 @@ static void resetPackBindings(fs::path& packFolder) { if (fs::is_regular_file(bindsFile)) { Events::loadBindings( bindsFile.u8string(), - files::read_string(bindsFile), + io::read_string(bindsFile), BindType::REBIND ); } diff --git a/src/logic/scripting/lua/libs/libpack.cpp b/src/logic/scripting/lua/libs/libpack.cpp index 3629679e..99561538 100644 --- a/src/logic/scripting/lua/libs/libpack.cpp +++ b/src/logic/scripting/lua/libs/libpack.cpp @@ -8,7 +8,7 @@ #include "content/Content.hpp" #include "engine/Engine.hpp" #include "world/files/WorldFiles.hpp" -#include "files/engine_paths.hpp" +#include "io/engine_paths.hpp" #include "world/Level.hpp" #include "world/World.hpp" #include "api_lua.hpp" diff --git a/src/logic/scripting/lua/libs/libworld.cpp b/src/logic/scripting/lua/libs/libworld.cpp index 24cfd733..07c64feb 100644 --- a/src/logic/scripting/lua/libs/libworld.cpp +++ b/src/logic/scripting/lua/libs/libworld.cpp @@ -7,8 +7,8 @@ #include "coders/json.hpp" #include "engine/Engine.hpp" #include "world/files/WorldFiles.hpp" -#include "files/engine_paths.hpp" -#include "files/files.hpp" +#include "io/engine_paths.hpp" +#include "io/io.hpp" #include "lighting/Lighting.hpp" #include "voxels/Chunk.hpp" #include "voxels/Chunks.hpp" @@ -44,7 +44,7 @@ static int l_get_list(lua::State* L) { const auto& folder = worlds[i]; auto root = - json::parse(files::read_string(folder / fs::u8path("world.json"))); + json::parse(io::read_string(folder / fs::u8path("world.json"))); const auto& versionMap = root["version"]; int versionMajor = versionMap["major"].asInteger(); int versionMinor = versionMap["minor"].asInteger(); diff --git a/src/logic/scripting/lua/lua_engine.cpp b/src/logic/scripting/lua/lua_engine.cpp index 1f4bde7d..6a494aa2 100644 --- a/src/logic/scripting/lua/lua_engine.cpp +++ b/src/logic/scripting/lua/lua_engine.cpp @@ -3,8 +3,8 @@ #include #include -#include "files/files.hpp" -#include "files/engine_paths.hpp" +#include "io/io.hpp" +#include "io/engine_paths.hpp" #include "debug/Logger.hpp" #include "util/stringutil.hpp" #include "libs/api_lua.hpp" @@ -161,7 +161,7 @@ State* lua::create_state(const EnginePaths& paths, StateType stateType) { auto resDir = paths.getResourcesFolder(); auto file = resDir / fs::u8path("scripts/stdmin.lua"); - auto src = files::read_string(file); + auto src = io::read_string(file); lua::pop(L, lua::execute(L, 0, src, "core:scripts/stdmin.lua")); return L; } diff --git a/src/logic/scripting/lua/usertypes/lua_type_heightmap.cpp b/src/logic/scripting/lua/usertypes/lua_type_heightmap.cpp index 0db89634..84aadbc0 100644 --- a/src/logic/scripting/lua/usertypes/lua_type_heightmap.cpp +++ b/src/logic/scripting/lua/usertypes/lua_type_heightmap.cpp @@ -9,7 +9,7 @@ #define FNL_IMPL #include "maths/FastNoiseLite.h" #include "coders/imageio.hpp" -#include "files/util.hpp" +#include "io/util.hpp" #include "graphics/core/ImageData.hpp" #include "maths/Heightmap.hpp" #include "engine/Engine.hpp" diff --git a/src/logic/scripting/scripting.cpp b/src/logic/scripting/scripting.cpp index 52eab4cd..ba39e334 100644 --- a/src/logic/scripting/scripting.cpp +++ b/src/logic/scripting/scripting.cpp @@ -8,8 +8,8 @@ #include "content/ContentPack.hpp" #include "debug/Logger.hpp" #include "engine/Engine.hpp" -#include "files/engine_paths.hpp" -#include "files/files.hpp" +#include "io/engine_paths.hpp" +#include "io/io.hpp" #include "frontend/UiDocument.hpp" #include "items/Inventory.hpp" #include "items/ItemDef.hpp" @@ -44,7 +44,7 @@ LevelController* scripting::controller = nullptr; void scripting::load_script(const fs::path& name, bool throwable) { const auto& paths = scripting::engine->getPaths(); fs::path file = paths.getResourcesFolder() / fs::path("scripts") / name; - std::string src = files::read_string(file); + std::string src = io::read_string(file); auto L = lua::get_main_state(); lua::loadbuffer(L, 0, src, "core:scripts/"+name.u8string()); if (throwable) { @@ -60,7 +60,7 @@ int scripting::load_script( const fs::path& file, const std::string& fileName ) { - std::string src = files::read_string(file); + std::string src = io::read_string(file); logger.info() << "script (" << type << ") " << file.u8string(); return lua::execute(lua::get_main_state(), env, src, fileName); } @@ -117,7 +117,7 @@ std::unique_ptr scripting::start_coroutine( ) { auto L = lua::get_main_state(); if (lua::getglobal(L, "__vc_start_coroutine")) { - auto source = files::read_string(script); + auto source = io::read_string(script); lua::loadbuffer(L, 0, source, script.filename().u8string()); if (lua::call(L, 1)) { int id = lua::tointeger(L, -1); @@ -872,7 +872,7 @@ void scripting::load_entity_component( const std::string& name, const fs::path& file, const std::string& fileName ) { auto L = lua::get_main_state(); - std::string src = files::read_string(file); + std::string src = io::read_string(file); logger.info() << "script (component) " << file.u8string(); lua::loadbuffer(L, 0, src, fileName); lua::store_in(L, lua::CHUNKS_TABLE, name); diff --git a/src/logic/scripting/scripting_hud.cpp b/src/logic/scripting/scripting_hud.cpp index c13a0010..66b14387 100644 --- a/src/logic/scripting/scripting_hud.cpp +++ b/src/logic/scripting/scripting_hud.cpp @@ -2,7 +2,7 @@ #include "debug/Logger.hpp" #include "engine/Engine.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "frontend/hud.hpp" #include "frontend/UiDocument.hpp" #include "graphics/render/WorldRenderer.hpp" @@ -20,7 +20,7 @@ WorldRenderer* scripting::renderer = nullptr; static void load_script(const std::string& name) { auto file = engine->getPaths().getResourcesFolder() / "scripts" / name; - std::string src = files::read_string(file); + std::string src = io::read_string(file); logger.info() << "loading script " << file.u8string(); lua::execute(lua::get_main_state(), 0, src, file.u8string()); @@ -84,7 +84,7 @@ void scripting::load_hud_script( const std::string& fileName ) { int env = *senv; - std::string src = files::read_string(file); + std::string src = io::read_string(file); logger.info() << "loading script " << file.u8string(); lua::execute(lua::get_main_state(), env, src, fileName); diff --git a/src/logic/scripting/scripting_world_generation.cpp b/src/logic/scripting/scripting_world_generation.cpp index 1169b64f..8a19e1b0 100644 --- a/src/logic/scripting/scripting_world_generation.cpp +++ b/src/logic/scripting/scripting_world_generation.cpp @@ -13,7 +13,7 @@ #include "data/dv.hpp" #include "world/generator/GeneratorDef.hpp" #include "util/timeutil.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "engine/Engine.hpp" #include "debug/Logger.hpp" @@ -55,7 +55,7 @@ public: pop(L); if (fs::exists(file)) { - std::string src = files::read_string(file); + std::string src = io::read_string(file); logger.info() << "script (generator) " << file.u8string(); pop(L, execute(L, *env, src, file.u8string())); } else { diff --git a/src/util/command_line.cpp b/src/util/command_line.cpp index 483b0f8b..6b579c01 100644 --- a/src/util/command_line.cpp +++ b/src/util/command_line.cpp @@ -3,7 +3,7 @@ #include #include -#include "files/engine_paths.hpp" +#include "io/engine_paths.hpp" #include "util/ArgsReader.hpp" #include "engine/Engine.hpp" diff --git a/src/world/World.cpp b/src/world/World.cpp index 2319fe2c..a04e5e9b 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -61,7 +61,7 @@ void World::writeResources(const Content& content) { } } } - files::write_json(wfile->getResourcesFile(), root); + io::write_json(wfile->getResourcesFile(), root); } void World::write(Level* level) { @@ -70,7 +70,7 @@ void World::write(Level* level) { wfile->write(this, &content); auto playerFile = level->players->serialize(); - files::write_json(wfile->getPlayerFile(), playerFile); + io::write_json(wfile->getPlayerFile(), playerFile); writeResources(content); } @@ -134,7 +134,7 @@ std::unique_ptr World::load( logger.warning() << "player.json does not exists"; level->players->create(); } else { - auto playerRoot = files::read_json(file); + auto playerRoot = io::read_json(file); level->players->deserialize(playerRoot); if (!playerRoot["players"].empty()) { diff --git a/src/world/files/WorldConverter.cpp b/src/world/files/WorldConverter.cpp index 25a0ca9d..287999de 100644 --- a/src/world/files/WorldConverter.cpp +++ b/src/world/files/WorldConverter.cpp @@ -8,7 +8,7 @@ #include "content/ContentReport.hpp" #include "compatibility.hpp" #include "debug/Logger.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "objects/Player.hpp" #include "util/ThreadPool.hpp" #include "voxels/Chunk.hpp" @@ -185,9 +185,9 @@ void WorldConverter::upgradeRegion( const fs::path& file, int x, int z, RegionLayerIndex layer ) const { auto path = wfile->getRegions().getRegionFilePath(layer, x, z); - auto bytes = files::read_bytes_buffer(path); + auto bytes = io::read_bytes_buffer(path); auto buffer = compatibility::convert_region_2to3(bytes, layer); - files::write_bytes(path, buffer.data(), buffer.size()); + io::write_bytes(path, buffer.data(), buffer.size()); } void WorldConverter::convertVoxels(const fs::path& file, int x, int z) const { @@ -208,9 +208,9 @@ void WorldConverter::convertInventories(const fs::path& file, int x, int z) cons void WorldConverter::convertPlayer(const fs::path& file) const { logger.info() << "converting player " << file.u8string(); - auto map = files::read_json(file); + auto map = io::read_json(file); Player::convert(map, report.get()); - files::write_json(file, map); + io::write_json(file, map); } void WorldConverter::convertBlocksData(int x, int z, const ContentReport& report) const { diff --git a/src/world/files/WorldFiles.cpp b/src/world/files/WorldFiles.cpp index 3759c96b..73132f33 100644 --- a/src/world/files/WorldFiles.cpp +++ b/src/world/files/WorldFiles.cpp @@ -100,7 +100,7 @@ void WorldFiles::writePacks(const std::vector& packs) { for (const auto& pack : packs) { ss << pack.id << "\n"; } - files::write_string(packsFile, ss.str()); + io::write_string(packsFile, ss.str()); } template @@ -139,11 +139,11 @@ void WorldFiles::writeIndices(const ContentIndices* indices) { createContentIndicesCache(indices, root); createBlockFieldsIndices(indices, root); - files::write_json(getIndicesFile(), root); + io::write_json(getIndicesFile(), root); } void WorldFiles::writeWorldInfo(const WorldInfo& info) { - files::write_json(getWorldFile(), info.serialize()); + io::write_json(getWorldFile(), info.serialize()); } std::optional WorldFiles::readWorldInfo() { @@ -152,7 +152,7 @@ std::optional WorldFiles::readWorldInfo() { logger.warning() << "world.json does not exists"; return std::nullopt; } - auto root = files::read_json(file); + auto root = io::read_json(file); WorldInfo info {}; info.deserialize(root); return info; @@ -180,7 +180,7 @@ bool WorldFiles::readResourcesData(const Content& content) { logger.warning() << "resources.json does not exists"; return false; } - auto root = files::read_json(file); + auto root = io::read_json(file); for (const auto& [key, arr] : root.asObject()) { if (auto resType = ResourceType_from(key)) { read_resources_data(content, arr, *resType); @@ -197,12 +197,12 @@ void WorldFiles::patchIndicesFile(const dv::value& map) { logger.error() << file.filename().u8string() << " does not exists"; return; } - auto root = files::read_json(file); + auto root = io::read_json(file); for (const auto& [key, value] : map.asObject()) { logger.info() << "patching indices.json: update " << util::quote(key); root[key] = value; } - files::write_json(file, root, true); + io::write_json(file, root, true); } static void erase_pack_indices(dv::value& root, const std::string& id) { @@ -223,11 +223,11 @@ static void erase_pack_indices(dv::value& root, const std::string& id) { } void WorldFiles::removeIndices(const std::vector& packs) { - auto root = files::read_json(getIndicesFile()); + auto root = io::read_json(getIndicesFile()); for (const auto& id : packs) { erase_pack_indices(root, id); } - files::write_json(getIndicesFile(), root); + io::write_json(getIndicesFile(), root); } fs::path WorldFiles::getFolder() const { diff --git a/src/world/files/WorldFiles.hpp b/src/world/files/WorldFiles.hpp index d8e1f62d..7c4fb2cd 100644 --- a/src/world/files/WorldFiles.hpp +++ b/src/world/files/WorldFiles.hpp @@ -11,7 +11,7 @@ #include "typedefs.hpp" #include "voxels/Chunk.hpp" #include "WorldRegions.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #define GLM_ENABLE_EXPERIMENTAL #include diff --git a/src/world/files/WorldRegions.hpp b/src/world/files/WorldRegions.hpp index 75be22ac..3f2805b1 100644 --- a/src/world/files/WorldRegions.hpp +++ b/src/world/files/WorldRegions.hpp @@ -13,7 +13,7 @@ #include "voxels/Chunk.hpp" #include "maths/voxmaths.hpp" #include "coders/compression.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "world_regions_fwd.hpp" #define GLM_ENABLE_EXPERIMENTAL @@ -54,7 +54,7 @@ public: }; struct regfile { - files::rafile file; + io::rafile file; int version; bool inUse = false; diff --git a/test/coders/lua_parsing.cpp b/test/coders/lua_parsing.cpp index 9788d1d7..bf35965e 100644 --- a/test/coders/lua_parsing.cpp +++ b/test/coders/lua_parsing.cpp @@ -2,12 +2,12 @@ #include "coders/commons.hpp" #include "coders/lua_parsing.hpp" -#include "files/files.hpp" +#include "io/io.hpp" #include "util/stringutil.hpp" TEST(lua_parsing, Tokenizer) { auto filename = "../../res/scripts/stdlib.lua"; - auto source = files::read_string(std::filesystem::u8path(filename)); + auto source = io::read_string(std::filesystem::u8path(filename)); try { auto tokens = lua::tokenize(filename, source); for (const auto& token : tokens) { diff --git a/test/coders/vec3.cpp b/test/coders/vec3.cpp index d404e92b..6dc5e724 100644 --- a/test/coders/vec3.cpp +++ b/test/coders/vec3.cpp @@ -1,12 +1,12 @@ #include #include "coders/vec3.hpp" -#include "files/files.hpp" +#include "io/io.hpp" TEST(VEC3, Decode) { auto file = std::filesystem::u8path( "res/models/block.vec3" ); - auto bytes = files::read_bytes_buffer(file); + auto bytes = io::read_bytes_buffer(file); auto model = vec3::load(file.u8string(), bytes); }