rename 'files' to 'io'
This commit is contained in:
parent
e5d558d357
commit
1e22882284
@ -9,8 +9,8 @@
|
|||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "content/ContentPack.hpp"
|
#include "content/ContentPack.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "graphics/core/Texture.hpp"
|
#include "graphics/core/Texture.hpp"
|
||||||
#include "logic/scripting/scripting.hpp"
|
#include "logic/scripting/scripting.hpp"
|
||||||
#include "objects/rigging.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) {
|
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::ATLAS, root["atlases"]);
|
||||||
processPreloadList(AssetType::FONT, root["fonts"]);
|
processPreloadList(AssetType::FONT, root["fonts"]);
|
||||||
processPreloadList(AssetType::SHADER, root["shaders"]);
|
processPreloadList(AssetType::SHADER, root["shaders"]);
|
||||||
|
|||||||
@ -13,8 +13,8 @@
|
|||||||
#include "coders/vec3.hpp"
|
#include "coders/vec3.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "frontend/UiDocument.hpp"
|
#include "frontend/UiDocument.hpp"
|
||||||
#include "graphics/core/Atlas.hpp"
|
#include "graphics/core/Atlas.hpp"
|
||||||
#include "graphics/core/Font.hpp"
|
#include "graphics/core/Font.hpp"
|
||||||
@ -72,8 +72,8 @@ assetload::postfunc assetload::shader(
|
|||||||
fs::path vertexFile = paths->find(filename + ".glslv");
|
fs::path vertexFile = paths->find(filename + ".glslv");
|
||||||
fs::path fragmentFile = paths->find(filename + ".glslf");
|
fs::path fragmentFile = paths->find(filename + ".glslf");
|
||||||
|
|
||||||
std::string vertexSource = files::read_string(vertexFile);
|
std::string vertexSource = io::read_string(vertexFile);
|
||||||
std::string fragmentSource = files::read_string(fragmentFile);
|
std::string fragmentSource = io::read_string(fragmentFile);
|
||||||
|
|
||||||
vertexSource = Shader::preprocessor->process(vertexFile, vertexSource);
|
vertexSource = Shader::preprocessor->process(vertexFile, vertexSource);
|
||||||
fragmentSource =
|
fragmentSource =
|
||||||
@ -273,7 +273,7 @@ assetload::postfunc assetload::model(
|
|||||||
) {
|
) {
|
||||||
auto path = paths->find(file + ".vec3");
|
auto path = paths->find(file + ".vec3");
|
||||||
if (fs::exists(path)) {
|
if (fs::exists(path)) {
|
||||||
auto bytes = files::read_bytes_buffer(path);
|
auto bytes = io::read_bytes_buffer(path);
|
||||||
auto modelVEC3 = std::make_shared<vec3::File>(vec3::load(path.u8string(), bytes));
|
auto modelVEC3 = std::make_shared<vec3::File>(vec3::load(path.u8string(), bytes));
|
||||||
return [loader, name, modelVEC3=std::move(modelVEC3)](Assets* assets) {
|
return [loader, name, modelVEC3=std::move(modelVEC3)](Assets* assets) {
|
||||||
for (auto& [modelName, model] : modelVEC3->models) {
|
for (auto& [modelName, model] : modelVEC3->models) {
|
||||||
@ -292,7 +292,7 @@ assetload::postfunc assetload::model(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
path = paths->find(file + ".obj");
|
path = paths->find(file + ".obj");
|
||||||
auto text = files::read_string(path);
|
auto text = io::read_string(path);
|
||||||
try {
|
try {
|
||||||
auto model = obj::parse(path.u8string(), text).release();
|
auto model = obj::parse(path.u8string(), text).release();
|
||||||
return [=](Assets* assets) {
|
return [=](Assets* assets) {
|
||||||
@ -309,7 +309,7 @@ static void read_anim_file(
|
|||||||
const std::string& animFile,
|
const std::string& animFile,
|
||||||
std::vector<std::pair<std::string, int>>& frameList
|
std::vector<std::pair<std::string, int>>& frameList
|
||||||
) {
|
) {
|
||||||
auto root = files::read_json(animFile);
|
auto root = io::read_json(animFile);
|
||||||
float frameDuration = DEFAULT_FRAME_DURATION;
|
float frameDuration = DEFAULT_FRAME_DURATION;
|
||||||
std::string frameName;
|
std::string frameName;
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,8 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ void GLSLExtension::setPaths(const ResPaths* paths) {
|
|||||||
|
|
||||||
void GLSLExtension::loadHeader(const std::string& name) {
|
void GLSLExtension::loadHeader(const std::string& name) {
|
||||||
fs::path file = paths->find("shaders/lib/" + name + ".glsl");
|
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, "");
|
||||||
addHeader(name, process(file, source, true));
|
addHeader(name, process(file, source, true));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "graphics/core/ImageData.hpp"
|
#include "graphics/core/ImageData.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "png.hpp"
|
#include "png.hpp"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
@ -41,7 +41,7 @@ std::unique_ptr<ImageData> imageio::read(const fs::path& filename) {
|
|||||||
"file format is not supported (read): " + filename.u8string()
|
"file format is not supported (read): " + filename.u8string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
auto bytes = files::read_bytes_buffer(filename);
|
auto bytes = io::read_bytes_buffer(filename);
|
||||||
try {
|
try {
|
||||||
return std::unique_ptr<ImageData>(found->second(bytes.data(), bytes.size()));
|
return std::unique_ptr<ImageData>(found->second(bytes.data(), bytes.size()));
|
||||||
} catch (const std::runtime_error& err) {
|
} catch (const std::runtime_error& err) {
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "graphics/core/GLTexture.hpp"
|
#include "graphics/core/GLTexture.hpp"
|
||||||
#include "graphics/core/ImageData.hpp"
|
#include "graphics/core/ImageData.hpp"
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ std::unique_ptr<Texture> png::load_texture(const ubyte* bytes, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Texture> png::load_texture(const std::string& filename) {
|
std::unique_ptr<Texture> 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 {
|
try {
|
||||||
return load_texture(bytes.data(), bytes.size());
|
return load_texture(bytes.data(), bytes.size());
|
||||||
} catch (const std::runtime_error& err) {
|
} catch (const std::runtime_error& err) {
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "data/setting.hpp"
|
#include "data/setting.hpp"
|
||||||
#include "files/settings_io.hpp"
|
#include "io/settings_io.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
#include "commons.hpp"
|
#include "commons.hpp"
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
#include "coders/json.hpp"
|
#include "coders/json.hpp"
|
||||||
#include "core_defs.hpp"
|
#include "core_defs.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "items/ItemDef.hpp"
|
#include "items/ItemDef.hpp"
|
||||||
#include "logic/scripting/scripting.hpp"
|
#include "logic/scripting/scripting.hpp"
|
||||||
#include "objects/rigging.hpp"
|
#include "objects/rigging.hpp"
|
||||||
@ -54,8 +54,8 @@ static void detect_defs(
|
|||||||
if (name[0] == '_') {
|
if (name[0] == '_') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (fs::is_regular_file(file) && files::is_data_file(file)) {
|
if (fs::is_regular_file(file) && io::is_data_file(file)) {
|
||||||
auto map = files::read_object(file);
|
auto map = io::read_object(file);
|
||||||
std::string id = prefix.empty() ? name : prefix + ":" + name;
|
std::string id = prefix.empty() ? name : prefix + ":" + name;
|
||||||
detected.emplace_back(id);
|
detected.emplace_back(id);
|
||||||
} else if (fs::is_directory(file) &&
|
} else if (fs::is_directory(file) &&
|
||||||
@ -78,9 +78,9 @@ static void detect_defs_pairs(
|
|||||||
if (name[0] == '_') {
|
if (name[0] == '_') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (fs::is_regular_file(file) && files::is_data_file(file)) {
|
if (fs::is_regular_file(file) && io::is_data_file(file)) {
|
||||||
try {
|
try {
|
||||||
auto map = files::read_object(file);
|
auto map = io::read_object(file);
|
||||||
auto id = prefix.empty() ? name : prefix + ":" + name;
|
auto id = prefix.empty() ? name : prefix + ":" + name;
|
||||||
auto caption = util::id_to_caption(id);
|
auto caption = util::id_to_caption(id);
|
||||||
map.at("caption").get(caption);
|
map.at("caption").get(caption);
|
||||||
@ -147,7 +147,7 @@ void ContentLoader::fixPackIndices() {
|
|||||||
|
|
||||||
dv::value root;
|
dv::value root;
|
||||||
if (fs::is_regular_file(contentFile)) {
|
if (fs::is_regular_file(contentFile)) {
|
||||||
root = files::read_json(contentFile);
|
root = io::read_json(contentFile);
|
||||||
} else {
|
} else {
|
||||||
root = dv::object();
|
root = dv::object();
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ void ContentLoader::fixPackIndices() {
|
|||||||
|
|
||||||
if (modified) {
|
if (modified) {
|
||||||
// rewrite modified json
|
// rewrite modified json
|
||||||
files::write_json(contentFile, root);
|
io::write_json(contentFile, root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ static void process_method(
|
|||||||
void ContentLoader::loadBlock(
|
void ContentLoader::loadBlock(
|
||||||
Block& def, const std::string& name, const fs::path& file
|
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) {
|
if (def.properties == nullptr) {
|
||||||
def.properties = dv::object();
|
def.properties = dv::object();
|
||||||
def.properties["name"] = name;
|
def.properties["name"] = name;
|
||||||
@ -404,7 +404,7 @@ void ContentLoader::loadBlock(
|
|||||||
void ContentLoader::loadItem(
|
void ContentLoader::loadItem(
|
||||||
ItemDef& def, const std::string& name, const fs::path& file
|
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;
|
def.properties = root;
|
||||||
|
|
||||||
if (root.has("parent")) {
|
if (root.has("parent")) {
|
||||||
@ -448,7 +448,7 @@ void ContentLoader::loadItem(
|
|||||||
void ContentLoader::loadEntity(
|
void ContentLoader::loadEntity(
|
||||||
EntityDef& def, const std::string& name, const fs::path& file
|
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")) {
|
if (root.has("parent")) {
|
||||||
const auto& parentName = root["parent"].asString();
|
const auto& parentName = root["parent"].asString();
|
||||||
@ -568,7 +568,7 @@ static std::tuple<std::string, std::string, std::string> create_unit_id(
|
|||||||
void ContentLoader::loadBlockMaterial(
|
void ContentLoader::loadBlockMaterial(
|
||||||
BlockMaterial& def, const fs::path& file
|
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("steps-sound").get(def.stepsSound);
|
||||||
root.at("place-sound").get(def.placeSound);
|
root.at("place-sound").get(def.placeSound);
|
||||||
root.at("break-sound").get(def.breakSound);
|
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");
|
auto configFile = pack->folder / fs::path(prefix + "/" + name + ".json");
|
||||||
std::string parent;
|
std::string parent;
|
||||||
if (fs::exists(configFile)) {
|
if (fs::exists(configFile)) {
|
||||||
auto root = files::read_json(configFile);
|
auto root = io::read_json(configFile);
|
||||||
root.at("parent").get(parent);
|
root.at("parent").get(parent);
|
||||||
}
|
}
|
||||||
return parent;
|
return parent;
|
||||||
@ -778,7 +778,7 @@ void ContentLoader::load() {
|
|||||||
// Load pack resources.json
|
// Load pack resources.json
|
||||||
fs::path resourcesFile = folder / fs::u8path("resources.json");
|
fs::path resourcesFile = folder / fs::u8path("resources.json");
|
||||||
if (fs::exists(resourcesFile)) {
|
if (fs::exists(resourcesFile)) {
|
||||||
auto resRoot = files::read_json(resourcesFile);
|
auto resRoot = io::read_json(resourcesFile);
|
||||||
for (const auto& [key, arr] : resRoot.asObject()) {
|
for (const auto& [key, arr] : resRoot.asObject()) {
|
||||||
if (auto resType = ResourceType_from(key)) {
|
if (auto resType = ResourceType_from(key)) {
|
||||||
loadResources(*resType, arr);
|
loadResources(*resType, arr);
|
||||||
@ -792,7 +792,7 @@ void ContentLoader::load() {
|
|||||||
// Load pack resources aliases
|
// Load pack resources aliases
|
||||||
fs::path aliasesFile = folder / fs::u8path("resource-aliases.json");
|
fs::path aliasesFile = folder / fs::u8path("resource-aliases.json");
|
||||||
if (fs::exists(aliasesFile)) {
|
if (fs::exists(aliasesFile)) {
|
||||||
auto resRoot = files::read_json(aliasesFile);
|
auto resRoot = io::read_json(aliasesFile);
|
||||||
for (const auto& [key, arr] : resRoot.asObject()) {
|
for (const auto& [key, arr] : resRoot.asObject()) {
|
||||||
if (auto resType = ResourceType_from(key)) {
|
if (auto resType = ResourceType_from(key)) {
|
||||||
loadResourceAliases(*resType, arr);
|
loadResourceAliases(*resType, arr);
|
||||||
@ -821,7 +821,7 @@ void ContentLoader::load() {
|
|||||||
fs::path skeletonsDir = folder / fs::u8path("skeletons");
|
fs::path skeletonsDir = folder / fs::u8path("skeletons");
|
||||||
foreach_file(skeletonsDir, [this](const fs::path& file) {
|
foreach_file(skeletonsDir, [this](const fs::path& file) {
|
||||||
std::string name = pack->id + ":" + file.stem().u8string();
|
std::string name = pack->id + ":" + file.stem().u8string();
|
||||||
std::string text = files::read_string(file);
|
std::string text = io::read_string(file);
|
||||||
builder.add(
|
builder.add(
|
||||||
rigging::SkeletonConfig::parse(text, file.u8string(), name)
|
rigging::SkeletonConfig::parse(text, file.u8string(), name)
|
||||||
);
|
);
|
||||||
@ -830,7 +830,7 @@ void ContentLoader::load() {
|
|||||||
// Process content.json and load defined content units
|
// Process content.json and load defined content units
|
||||||
auto contentFile = pack->getContentFile();
|
auto contentFile = pack->getContentFile();
|
||||||
if (fs::exists(contentFile)) {
|
if (fs::exists(contentFile)) {
|
||||||
loadContent(files::read_json(contentFile));
|
loadContent(io::read_json(contentFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,8 @@
|
|||||||
#include "coders/json.hpp"
|
#include "coders/json.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "data/dv.hpp"
|
#include "data/dv.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
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) {
|
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;
|
ContentPack pack;
|
||||||
root.at("id").get(pack.id);
|
root.at("id").get(pack.id);
|
||||||
root.at("title").get(pack.title);
|
root.at("title").get(pack.title);
|
||||||
@ -151,7 +151,7 @@ std::vector<std::string> ContentPack::worldPacksList(const fs::path& folder) {
|
|||||||
if (!fs::is_regular_file(listfile)) {
|
if (!fs::is_regular_file(listfile)) {
|
||||||
throw std::runtime_error("missing file 'packs.list'");
|
throw std::runtime_error("missing file 'packs.list'");
|
||||||
}
|
}
|
||||||
return files::read_list(listfile);
|
return io::read_list(listfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path ContentPack::findPack(
|
fs::path ContentPack::findPack(
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "coders/json.hpp"
|
#include "coders/json.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "items/ItemDef.hpp"
|
#include "items/ItemDef.hpp"
|
||||||
#include "voxels/Block.hpp"
|
#include "voxels/Block.hpp"
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
@ -75,7 +75,7 @@ std::shared_ptr<ContentReport> ContentReport::create(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto root = files::read_json(filename);
|
auto root = io::read_json(filename);
|
||||||
uint regionsVersion = 2U; // old worlds compatibility (pre 0.23)
|
uint regionsVersion = 2U; // old worlds compatibility (pre 0.23)
|
||||||
root.at("region-version").get(regionsVersion);
|
root.at("region-version").get(regionsVersion);
|
||||||
auto& blocklist = root["blocks"];
|
auto& blocklist = root["blocks"];
|
||||||
|
|||||||
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
#include "../ContentPack.hpp"
|
#include "../ContentPack.hpp"
|
||||||
|
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "logic/scripting/scripting.hpp"
|
#include "logic/scripting/scripting.hpp"
|
||||||
#include "world/generator/GeneratorDef.hpp"
|
#include "world/generator/GeneratorDef.hpp"
|
||||||
#include "world/generator/VoxelFragment.hpp"
|
#include "world/generator/VoxelFragment.hpp"
|
||||||
@ -146,7 +146,7 @@ static std::vector<std::unique_ptr<VoxelStructure>> load_structures(
|
|||||||
structFile.u8string());
|
structFile.u8string());
|
||||||
}
|
}
|
||||||
auto fragment = std::make_unique<VoxelFragment>();
|
auto fragment = std::make_unique<VoxelFragment>();
|
||||||
fragment->deserialize(files::read_binary_json(structFile));
|
fragment->deserialize(io::read_binary_json(structFile));
|
||||||
logger.info() << "fragment " << name << " has size [" <<
|
logger.info() << "fragment " << name << " has size [" <<
|
||||||
fragment->getSize().x << ", " << fragment->getSize().y << ", " <<
|
fragment->getSize().x << ", " << fragment->getSize().y << ", " <<
|
||||||
fragment->getSize().z << "]";
|
fragment->getSize().z << "]";
|
||||||
@ -202,7 +202,7 @@ void ContentLoader::loadGenerator(
|
|||||||
if (!fs::exists(generatorFile)) {
|
if (!fs::exists(generatorFile)) {
|
||||||
return;
|
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("caption").get(def.caption);
|
||||||
map.at("biome-parameters").get(def.biomeParameters);
|
map.at("biome-parameters").get(def.biomeParameters);
|
||||||
map.at("biome-bpd").get(def.biomesBPD);
|
map.at("biome-bpd").get(def.biomesBPD);
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
#include "items/ItemDef.hpp"
|
#include "items/ItemDef.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "content/ContentBuilder.hpp"
|
#include "content/ContentBuilder.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "window/Window.hpp"
|
#include "window/Window.hpp"
|
||||||
#include "window/Events.hpp"
|
#include "window/Events.hpp"
|
||||||
#include "window/input.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");
|
auto bindsFile = paths.getResourcesFolder()/fs::path("bindings.toml");
|
||||||
if (fs::is_regular_file(bindsFile)) {
|
if (fs::is_regular_file(bindsFile)) {
|
||||||
Events::loadBindings(
|
Events::loadBindings(
|
||||||
bindsFile.u8string(), files::read_string(bindsFile), BindType::BIND
|
bindsFile.u8string(), io::read_string(bindsFile), BindType::BIND
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
#include "content/ContentBuilder.hpp"
|
#include "content/ContentBuilder.hpp"
|
||||||
#include "content/ContentLoader.hpp"
|
#include "content/ContentLoader.hpp"
|
||||||
#include "core_defs.hpp"
|
#include "core_defs.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "frontend/locale.hpp"
|
#include "frontend/locale.hpp"
|
||||||
#include "frontend/menu.hpp"
|
#include "frontend/menu.hpp"
|
||||||
#include "frontend/screens/Screen.hpp"
|
#include "frontend/screens/Screen.hpp"
|
||||||
@ -128,14 +128,14 @@ void Engine::initialize(CoreParameters coreParameters) {
|
|||||||
keepAlive(settings.ui.language.observe([this](auto lang) {
|
keepAlive(settings.ui.language.observe([this](auto lang) {
|
||||||
setLanguage(lang);
|
setLanguage(lang);
|
||||||
}, true));
|
}, true));
|
||||||
basePacks = files::read_list(resdir/fs::path("config/builtins.list"));
|
basePacks = io::read_list(resdir/fs::path("config/builtins.list"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::loadSettings() {
|
void Engine::loadSettings() {
|
||||||
fs::path settings_file = paths.getSettingsFile();
|
fs::path settings_file = paths.getSettingsFile();
|
||||||
if (fs::is_regular_file(settings_file)) {
|
if (fs::is_regular_file(settings_file)) {
|
||||||
logger.info() << "loading settings";
|
logger.info() << "loading settings";
|
||||||
std::string text = files::read_string(settings_file);
|
std::string text = io::read_string(settings_file);
|
||||||
try {
|
try {
|
||||||
toml::parse(*settingsHandler, settings_file.string(), text);
|
toml::parse(*settingsHandler, settings_file.string(), text);
|
||||||
} catch (const parsing_error& err) {
|
} catch (const parsing_error& err) {
|
||||||
@ -149,7 +149,7 @@ void Engine::loadControls() {
|
|||||||
fs::path controls_file = paths.getControlsFile();
|
fs::path controls_file = paths.getControlsFile();
|
||||||
if (fs::is_regular_file(controls_file)) {
|
if (fs::is_regular_file(controls_file)) {
|
||||||
logger.info() << "loading controls";
|
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);
|
Events::loadBindings(controls_file.u8string(), text, BindType::BIND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,10 +219,10 @@ void Engine::renderFrame() {
|
|||||||
|
|
||||||
void Engine::saveSettings() {
|
void Engine::saveSettings() {
|
||||||
logger.info() << "saving settings";
|
logger.info() << "saving settings";
|
||||||
files::write_string(paths.getSettingsFile(), toml::stringify(*settingsHandler));
|
io::write_string(paths.getSettingsFile(), toml::stringify(*settingsHandler));
|
||||||
if (!params.headless) {
|
if (!params.headless) {
|
||||||
logger.info() << "saving bindings";
|
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");
|
auto bindsFile = configFolder/fs::path("bindings.toml");
|
||||||
if (fs::is_regular_file(bindsFile)) {
|
if (fs::is_regular_file(bindsFile)) {
|
||||||
Events::loadBindings(
|
Events::loadBindings(
|
||||||
bindsFile.u8string(), files::read_string(bindsFile), BindType::BIND
|
bindsFile.u8string(), io::read_string(bindsFile), BindType::BIND
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,8 @@
|
|||||||
#include "content/content_fwd.hpp"
|
#include "content/content_fwd.hpp"
|
||||||
#include "content/ContentPack.hpp"
|
#include "content/ContentPack.hpp"
|
||||||
#include "content/PacksManager.hpp"
|
#include "content/PacksManager.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "files/settings_io.hpp"
|
#include "io/settings_io.hpp"
|
||||||
#include "util/ObjectsKeeper.hpp"
|
#include "util/ObjectsKeeper.hpp"
|
||||||
#include "PostRunnables.hpp"
|
#include "PostRunnables.hpp"
|
||||||
#include "Time.hpp"
|
#include "Time.hpp"
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "graphics/ui/elements/UINode.hpp"
|
#include "graphics/ui/elements/UINode.hpp"
|
||||||
#include "graphics/ui/elements/InventoryView.hpp"
|
#include "graphics/ui/elements/InventoryView.hpp"
|
||||||
#include "graphics/ui/gui_xml.hpp"
|
#include "graphics/ui/gui_xml.hpp"
|
||||||
@ -59,7 +59,7 @@ std::unique_ptr<UiDocument> UiDocument::read(
|
|||||||
const fs::path& file,
|
const fs::path& file,
|
||||||
const std::string& fileName
|
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 xmldoc = xml::parse(file.u8string(), text);
|
||||||
|
|
||||||
auto env = penv == nullptr
|
auto env = penv == nullptr
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include "coders/json.hpp"
|
#include "coders/json.hpp"
|
||||||
#include "coders/commons.hpp"
|
#include "coders/commons.hpp"
|
||||||
#include "content/ContentPack.hpp"
|
#include "content/ContentPack.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
#include "data/dv.hpp"
|
#include "data/dv.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
@ -71,7 +71,7 @@ namespace {
|
|||||||
|
|
||||||
void langs::loadLocalesInfo(const fs::path& resdir, std::string& fallback) {
|
void langs::loadLocalesInfo(const fs::path& resdir, std::string& fallback) {
|
||||||
auto file = resdir/fs::u8path(langs::TEXTS_FOLDER)/fs::u8path("langs.json");
|
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();
|
langs::locales_info.clear();
|
||||||
root.at("fallback").get(fallback);
|
root.at("fallback").get(fallback);
|
||||||
@ -123,14 +123,14 @@ void langs::load(const fs::path& resdir,
|
|||||||
fs::path core_file = resdir/filename;
|
fs::path core_file = resdir/filename;
|
||||||
|
|
||||||
if (fs::is_regular_file(core_file)) {
|
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 reader(core_file.string(), text);
|
||||||
reader.read(lang, "");
|
reader.read(lang, "");
|
||||||
}
|
}
|
||||||
for (auto pack : packs) {
|
for (auto pack : packs) {
|
||||||
fs::path file = pack.folder/filename;
|
fs::path file = pack.folder/filename;
|
||||||
if (fs::is_regular_file(file)) {
|
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 reader(file.string(), text);
|
||||||
reader.read(lang, "");
|
reader.read(lang, "");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "data/dv.hpp"
|
#include "data/dv.hpp"
|
||||||
#include "interfaces/Task.hpp"
|
#include "interfaces/Task.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "graphics/ui/elements/Menu.hpp"
|
#include "graphics/ui/elements/Menu.hpp"
|
||||||
#include "graphics/ui/gui_util.hpp"
|
#include "graphics/ui/gui_util.hpp"
|
||||||
#include "graphics/ui/GUI.hpp"
|
#include "graphics/ui/GUI.hpp"
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#include "core_defs.hpp"
|
#include "core_defs.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "frontend/LevelFrontend.hpp"
|
#include "frontend/LevelFrontend.hpp"
|
||||||
#include "frontend/hud.hpp"
|
#include "frontend/hud.hpp"
|
||||||
#include "graphics/core/DrawContext.hpp"
|
#include "graphics/core/DrawContext.hpp"
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
#include "logic/LevelController.hpp"
|
#include "logic/LevelController.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
|||||||
@ -293,7 +293,7 @@ dv::value ResPaths::readCombinedList(const std::string& filename) const {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
auto value = files::read_object(path);
|
auto value = io::read_object(path);
|
||||||
if (!value.isList()) {
|
if (!value.isList()) {
|
||||||
logger.warning() << "reading combined list " << root.name << ":"
|
logger.warning() << "reading combined list " << root.name << ":"
|
||||||
<< filename << " is not a list (skipped)";
|
<< filename << " is not a list (skipped)";
|
||||||
@ -318,7 +318,7 @@ dv::value ResPaths::readCombinedObject(const std::string& filename) const {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
auto value = files::read_object(path);
|
auto value = io::read_object(path);
|
||||||
if (!value.isObject()) {
|
if (!value.isObject()) {
|
||||||
logger.warning()
|
logger.warning()
|
||||||
<< "reading combined object " << root.name << ": "
|
<< "reading combined object " << root.name << ": "
|
||||||
@ -1,4 +1,4 @@
|
|||||||
#include "files.hpp"
|
#include "io.hpp"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
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) {
|
: file(filename, std::ios::binary | std::ios::ate) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
throw std::runtime_error("could not to open file " + filename.string());
|
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);
|
file.seekg(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t files::rafile::length() const {
|
size_t io::rafile::length() const {
|
||||||
return filelength;
|
return filelength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void files::rafile::seekg(std::streampos pos) {
|
void io::rafile::seekg(std::streampos pos) {
|
||||||
file.seekg(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);
|
file.read(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool files::write_bytes(
|
bool io::write_bytes(
|
||||||
const fs::path& filename, const ubyte* data, size_t size
|
const fs::path& filename, const ubyte* data, size_t size
|
||||||
) {
|
) {
|
||||||
std::ofstream output(filename, std::ios::binary);
|
std::ofstream output(filename, std::ios::binary);
|
||||||
@ -46,7 +46,7 @@ bool files::write_bytes(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint files::append_bytes(
|
uint io::append_bytes(
|
||||||
const fs::path& filename, const ubyte* data, size_t size
|
const fs::path& filename, const ubyte* data, size_t size
|
||||||
) {
|
) {
|
||||||
std::ofstream output(filename, std::ios::binary | std::ios::app);
|
std::ofstream output(filename, std::ios::binary | std::ios::app);
|
||||||
@ -57,7 +57,7 @@ uint files::append_bytes(
|
|||||||
return position;
|
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);
|
std::ifstream output(filename, std::ios::binary);
|
||||||
if (!output.is_open()) return false;
|
if (!output.is_open()) return false;
|
||||||
output.read(data, size);
|
output.read(data, size);
|
||||||
@ -65,13 +65,13 @@ bool files::read(const fs::path& filename, char* data, size_t size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
util::Buffer<ubyte> files::read_bytes_buffer(const fs::path& path) {
|
util::Buffer<ubyte> io::read_bytes_buffer(const fs::path& path) {
|
||||||
size_t size;
|
size_t size;
|
||||||
auto bytes = files::read_bytes(path, size);
|
auto bytes = io::read_bytes(path, size);
|
||||||
return util::Buffer<ubyte>(std::move(bytes), size);
|
return util::Buffer<ubyte>(std::move(bytes), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ubyte[]> files::read_bytes(
|
std::unique_ptr<ubyte[]> io::read_bytes(
|
||||||
const fs::path& filename, size_t& length
|
const fs::path& filename, size_t& length
|
||||||
) {
|
) {
|
||||||
std::ifstream input(filename, std::ios::binary);
|
std::ifstream input(filename, std::ios::binary);
|
||||||
@ -90,7 +90,7 @@ std::unique_ptr<ubyte[]> files::read_bytes(
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ubyte> files::read_bytes(const fs::path& filename) {
|
std::vector<ubyte> io::read_bytes(const fs::path& filename) {
|
||||||
std::ifstream input(filename, std::ios::binary);
|
std::ifstream input(filename, std::ios::binary);
|
||||||
if (!input.is_open()) return {};
|
if (!input.is_open()) return {};
|
||||||
input.seekg(0, std::ios_base::end);
|
input.seekg(0, std::ios_base::end);
|
||||||
@ -104,13 +104,13 @@ std::vector<ubyte> files::read_bytes(const fs::path& filename) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string files::read_string(const fs::path& filename) {
|
std::string io::read_string(const fs::path& filename) {
|
||||||
size_t size;
|
size_t size;
|
||||||
auto bytes = read_bytes(filename, size);
|
auto bytes = read_bytes(filename, size);
|
||||||
return std::string((const char*)bytes.get(), 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);
|
std::ofstream file(filename);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return false;
|
return false;
|
||||||
@ -119,35 +119,35 @@ bool files::write_string(const fs::path& filename, std::string_view content) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool files::write_json(
|
bool io::write_json(
|
||||||
const fs::path& filename, const dv::value& obj, bool nice
|
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
|
const fs::path& filename, const dv::value& obj, bool compression
|
||||||
) {
|
) {
|
||||||
auto bytes = json::to_binary(obj, 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) {
|
dv::value io::read_json(const fs::path& filename) {
|
||||||
std::string text = files::read_string(filename);
|
std::string text = io::read_string(filename);
|
||||||
return json::parse(filename.string(), text);
|
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;
|
size_t size;
|
||||||
auto bytes = files::read_bytes(file, size);
|
auto bytes = io::read_bytes(file, size);
|
||||||
return json::from_binary(bytes.get(), size);
|
return json::from_binary(bytes.get(), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
dv::value files::read_toml(const fs::path& file) {
|
dv::value io::read_toml(const fs::path& file) {
|
||||||
return toml::parse(file.u8string(), files::read_string(file));
|
return toml::parse(file.u8string(), io::read_string(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> files::read_list(const fs::path& filename) {
|
std::vector<std::string> io::read_list(const fs::path& filename) {
|
||||||
std::ifstream file(filename);
|
std::ifstream file(filename);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
@ -177,15 +177,15 @@ static std::map<fs::path, DecodeFunc> data_decoders {
|
|||||||
{fs::u8path(".toml"), toml::parse},
|
{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());
|
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();
|
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());
|
const auto& found = data_decoders.find(file.extension());
|
||||||
if (found == data_decoders.end()) {
|
if (found == data_decoders.end()) {
|
||||||
throw std::runtime_error("unknown file format");
|
throw std::runtime_error("unknown file format");
|
||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
namespace files {
|
namespace io {
|
||||||
/// @brief Read-only random access file
|
/// @brief Read-only random access file
|
||||||
class rafile {
|
class rafile {
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
@ -3,7 +3,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace files {
|
namespace io {
|
||||||
inline bool is_valid_name(std::string_view name) {
|
inline bool is_valid_name(std::string_view name) {
|
||||||
static std::string illegalChars = "\\/%?!<>:; ";
|
static std::string illegalChars = "\\/%?!<>:; ";
|
||||||
for (char c : illegalChars) {
|
for (char c : illegalChars) {
|
||||||
@ -74,9 +74,6 @@ std::shared_ptr<Task> create_converter(
|
|||||||
content,
|
content,
|
||||||
report,
|
report,
|
||||||
[&engine, postRunnable]() {
|
[&engine, postRunnable]() {
|
||||||
//auto menu = engine.getGUI()->getMenu();
|
|
||||||
//menu->reset();
|
|
||||||
//menu->setPage("main", false);
|
|
||||||
engine.postRunnable([=]() { postRunnable(); });
|
engine.postRunnable([=]() { postRunnable(); });
|
||||||
},
|
},
|
||||||
mode,
|
mode,
|
||||||
|
|||||||
@ -7,9 +7,9 @@
|
|||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "files/settings_io.hpp"
|
#include "io/settings_io.hpp"
|
||||||
#include "frontend/menu.hpp"
|
#include "frontend/menu.hpp"
|
||||||
#include "frontend/screens/MenuScreen.hpp"
|
#include "frontend/screens/MenuScreen.hpp"
|
||||||
#include "graphics/core/Texture.hpp"
|
#include "graphics/core/Texture.hpp"
|
||||||
|
|||||||
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
#include "coders/gzip.hpp"
|
#include "coders/gzip.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
#include "../lua_engine.hpp"
|
#include "../lua_engine.hpp"
|
||||||
@ -41,7 +41,7 @@ static int l_resolve(lua::State* L) {
|
|||||||
static int l_read(lua::State* L) {
|
static int l_read(lua::State* L) {
|
||||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||||
if (fs::is_regular_file(path)) {
|
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(
|
throw std::runtime_error(
|
||||||
"file does not exists " + util::quote(path.u8string())
|
"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) {
|
static int l_write(lua::State* L) {
|
||||||
fs::path path = get_writeable_path(L);
|
fs::path path = get_writeable_path(L);
|
||||||
std::string text = lua::require_string(L, 2);
|
std::string text = lua::require_string(L, 2);
|
||||||
files::write_string(path, text);
|
io::write_string(path, text);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ static int l_read_bytes(lua::State* L) {
|
|||||||
if (fs::is_regular_file(path)) {
|
if (fs::is_regular_file(path)) {
|
||||||
size_t length = static_cast<size_t>(fs::file_size(path));
|
size_t length = static_cast<size_t>(fs::file_size(path));
|
||||||
|
|
||||||
auto bytes = files::read_bytes(path, length);
|
auto bytes = io::read_bytes(path, length);
|
||||||
|
|
||||||
lua::createtable(L, length, 0);
|
lua::createtable(L, length, 0);
|
||||||
int newTable = lua::gettop(L);
|
int newTable = lua::gettop(L);
|
||||||
@ -150,14 +150,14 @@ static int l_write_bytes(lua::State* L) {
|
|||||||
if (auto bytearray = lua::touserdata<lua::LuaBytearray>(L, 2)) {
|
if (auto bytearray = lua::touserdata<lua::LuaBytearray>(L, 2)) {
|
||||||
auto& bytes = bytearray->data();
|
auto& bytes = bytearray->data();
|
||||||
return lua::pushboolean(
|
return lua::pushboolean(
|
||||||
L, files::write_bytes(path, bytes.data(), bytes.size())
|
L, io::write_bytes(path, bytes.data(), bytes.size())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ubyte> bytes;
|
std::vector<ubyte> bytes;
|
||||||
lua::read_bytes_from_table(L, 2, bytes);
|
lua::read_bytes_from_table(L, 2, bytes);
|
||||||
return lua::pushboolean(
|
return lua::pushboolean(
|
||||||
L, files::write_bytes(path, bytes.data(), bytes.size())
|
L, io::write_bytes(path, bytes.data(), bytes.size())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
|
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "files/util.hpp"
|
#include "io/util.hpp"
|
||||||
#include "coders/binary_json.hpp"
|
#include "coders/binary_json.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/generator/VoxelFragment.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 file = paths.resolve(lua::require_string(L, 2), true);
|
||||||
auto map = fragment->getFragment()->serialize();
|
auto map = fragment->getFragment()->serialize();
|
||||||
auto bytes = json::to_binary(map, true);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ static int l_load_fragment(lua::State* L) {
|
|||||||
if (!std::filesystem::exists(path)) {
|
if (!std::filesystem::exists(path)) {
|
||||||
throw std::runtime_error("file "+path.u8string()+" does not exist");
|
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<VoxelFragment>();
|
auto fragment = std::make_shared<VoxelFragment>();
|
||||||
fragment->deserialize(map);
|
fragment->deserialize(map);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "frontend/hud.hpp"
|
#include "frontend/hud.hpp"
|
||||||
#include "frontend/screens/Screen.hpp"
|
#include "frontend/screens/Screen.hpp"
|
||||||
#include "graphics/ui/GUI.hpp"
|
#include "graphics/ui/GUI.hpp"
|
||||||
@ -141,7 +141,7 @@ static void resetPackBindings(fs::path& packFolder) {
|
|||||||
if (fs::is_regular_file(bindsFile)) {
|
if (fs::is_regular_file(bindsFile)) {
|
||||||
Events::loadBindings(
|
Events::loadBindings(
|
||||||
bindsFile.u8string(),
|
bindsFile.u8string(),
|
||||||
files::read_string(bindsFile),
|
io::read_string(bindsFile),
|
||||||
BindType::REBIND
|
BindType::REBIND
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "world/files/WorldFiles.hpp"
|
#include "world/files/WorldFiles.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
|
|||||||
@ -7,8 +7,8 @@
|
|||||||
#include "coders/json.hpp"
|
#include "coders/json.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "world/files/WorldFiles.hpp"
|
#include "world/files/WorldFiles.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "lighting/Lighting.hpp"
|
#include "lighting/Lighting.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
@ -44,7 +44,7 @@ static int l_get_list(lua::State* L) {
|
|||||||
const auto& folder = worlds[i];
|
const auto& folder = worlds[i];
|
||||||
|
|
||||||
auto root =
|
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"];
|
const auto& versionMap = root["version"];
|
||||||
int versionMajor = versionMap["major"].asInteger();
|
int versionMajor = versionMap["major"].asInteger();
|
||||||
int versionMinor = versionMap["minor"].asInteger();
|
int versionMinor = versionMap["minor"].asInteger();
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
#include "libs/api_lua.hpp"
|
#include "libs/api_lua.hpp"
|
||||||
@ -161,7 +161,7 @@ State* lua::create_state(const EnginePaths& paths, StateType stateType) {
|
|||||||
|
|
||||||
auto resDir = paths.getResourcesFolder();
|
auto resDir = paths.getResourcesFolder();
|
||||||
auto file = resDir / fs::u8path("scripts/stdmin.lua");
|
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"));
|
lua::pop(L, lua::execute(L, 0, src, "core:scripts/stdmin.lua"));
|
||||||
return L;
|
return L;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
#define FNL_IMPL
|
#define FNL_IMPL
|
||||||
#include "maths/FastNoiseLite.h"
|
#include "maths/FastNoiseLite.h"
|
||||||
#include "coders/imageio.hpp"
|
#include "coders/imageio.hpp"
|
||||||
#include "files/util.hpp"
|
#include "io/util.hpp"
|
||||||
#include "graphics/core/ImageData.hpp"
|
#include "graphics/core/ImageData.hpp"
|
||||||
#include "maths/Heightmap.hpp"
|
#include "maths/Heightmap.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
|
|||||||
@ -8,8 +8,8 @@
|
|||||||
#include "content/ContentPack.hpp"
|
#include "content/ContentPack.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "frontend/UiDocument.hpp"
|
#include "frontend/UiDocument.hpp"
|
||||||
#include "items/Inventory.hpp"
|
#include "items/Inventory.hpp"
|
||||||
#include "items/ItemDef.hpp"
|
#include "items/ItemDef.hpp"
|
||||||
@ -44,7 +44,7 @@ LevelController* scripting::controller = nullptr;
|
|||||||
void scripting::load_script(const fs::path& name, bool throwable) {
|
void scripting::load_script(const fs::path& name, bool throwable) {
|
||||||
const auto& paths = scripting::engine->getPaths();
|
const auto& paths = scripting::engine->getPaths();
|
||||||
fs::path file = paths.getResourcesFolder() / fs::path("scripts") / name;
|
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();
|
auto L = lua::get_main_state();
|
||||||
lua::loadbuffer(L, 0, src, "core:scripts/"+name.u8string());
|
lua::loadbuffer(L, 0, src, "core:scripts/"+name.u8string());
|
||||||
if (throwable) {
|
if (throwable) {
|
||||||
@ -60,7 +60,7 @@ int scripting::load_script(
|
|||||||
const fs::path& file,
|
const fs::path& file,
|
||||||
const std::string& fileName
|
const std::string& fileName
|
||||||
) {
|
) {
|
||||||
std::string src = files::read_string(file);
|
std::string src = io::read_string(file);
|
||||||
logger.info() << "script (" << type << ") " << file.u8string();
|
logger.info() << "script (" << type << ") " << file.u8string();
|
||||||
return lua::execute(lua::get_main_state(), env, src, fileName);
|
return lua::execute(lua::get_main_state(), env, src, fileName);
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ std::unique_ptr<Process> scripting::start_coroutine(
|
|||||||
) {
|
) {
|
||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
if (lua::getglobal(L, "__vc_start_coroutine")) {
|
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());
|
lua::loadbuffer(L, 0, source, script.filename().u8string());
|
||||||
if (lua::call(L, 1)) {
|
if (lua::call(L, 1)) {
|
||||||
int id = lua::tointeger(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
|
const std::string& name, const fs::path& file, const std::string& fileName
|
||||||
) {
|
) {
|
||||||
auto L = lua::get_main_state();
|
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();
|
logger.info() << "script (component) " << file.u8string();
|
||||||
lua::loadbuffer(L, 0, src, fileName);
|
lua::loadbuffer(L, 0, src, fileName);
|
||||||
lua::store_in(L, lua::CHUNKS_TABLE, name);
|
lua::store_in(L, lua::CHUNKS_TABLE, name);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "frontend/hud.hpp"
|
#include "frontend/hud.hpp"
|
||||||
#include "frontend/UiDocument.hpp"
|
#include "frontend/UiDocument.hpp"
|
||||||
#include "graphics/render/WorldRenderer.hpp"
|
#include "graphics/render/WorldRenderer.hpp"
|
||||||
@ -20,7 +20,7 @@ WorldRenderer* scripting::renderer = nullptr;
|
|||||||
|
|
||||||
static void load_script(const std::string& name) {
|
static void load_script(const std::string& name) {
|
||||||
auto file = engine->getPaths().getResourcesFolder() / "scripts" / 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();
|
logger.info() << "loading script " << file.u8string();
|
||||||
|
|
||||||
lua::execute(lua::get_main_state(), 0, src, 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
|
const std::string& fileName
|
||||||
) {
|
) {
|
||||||
int env = *senv;
|
int env = *senv;
|
||||||
std::string src = files::read_string(file);
|
std::string src = io::read_string(file);
|
||||||
logger.info() << "loading script " << file.u8string();
|
logger.info() << "loading script " << file.u8string();
|
||||||
|
|
||||||
lua::execute(lua::get_main_state(), env, src, fileName);
|
lua::execute(lua::get_main_state(), env, src, fileName);
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
#include "data/dv.hpp"
|
#include "data/dv.hpp"
|
||||||
#include "world/generator/GeneratorDef.hpp"
|
#include "world/generator/GeneratorDef.hpp"
|
||||||
#include "util/timeutil.hpp"
|
#include "util/timeutil.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public:
|
|||||||
pop(L);
|
pop(L);
|
||||||
|
|
||||||
if (fs::exists(file)) {
|
if (fs::exists(file)) {
|
||||||
std::string src = files::read_string(file);
|
std::string src = io::read_string(file);
|
||||||
logger.info() << "script (generator) " << file.u8string();
|
logger.info() << "script (generator) " << file.u8string();
|
||||||
pop(L, execute(L, *env, src, file.u8string()));
|
pop(L, execute(L, *env, src, file.u8string()));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "files/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "util/ArgsReader.hpp"
|
#include "util/ArgsReader.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
|
|
||||||
|
|||||||
@ -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) {
|
void World::write(Level* level) {
|
||||||
@ -70,7 +70,7 @@ void World::write(Level* level) {
|
|||||||
wfile->write(this, &content);
|
wfile->write(this, &content);
|
||||||
|
|
||||||
auto playerFile = level->players->serialize();
|
auto playerFile = level->players->serialize();
|
||||||
files::write_json(wfile->getPlayerFile(), playerFile);
|
io::write_json(wfile->getPlayerFile(), playerFile);
|
||||||
|
|
||||||
writeResources(content);
|
writeResources(content);
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ std::unique_ptr<Level> World::load(
|
|||||||
logger.warning() << "player.json does not exists";
|
logger.warning() << "player.json does not exists";
|
||||||
level->players->create();
|
level->players->create();
|
||||||
} else {
|
} else {
|
||||||
auto playerRoot = files::read_json(file);
|
auto playerRoot = io::read_json(file);
|
||||||
level->players->deserialize(playerRoot);
|
level->players->deserialize(playerRoot);
|
||||||
|
|
||||||
if (!playerRoot["players"].empty()) {
|
if (!playerRoot["players"].empty()) {
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#include "content/ContentReport.hpp"
|
#include "content/ContentReport.hpp"
|
||||||
#include "compatibility.hpp"
|
#include "compatibility.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "objects/Player.hpp"
|
#include "objects/Player.hpp"
|
||||||
#include "util/ThreadPool.hpp"
|
#include "util/ThreadPool.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
@ -185,9 +185,9 @@ void WorldConverter::upgradeRegion(
|
|||||||
const fs::path& file, int x, int z, RegionLayerIndex layer
|
const fs::path& file, int x, int z, RegionLayerIndex layer
|
||||||
) const {
|
) const {
|
||||||
auto path = wfile->getRegions().getRegionFilePath(layer, x, z);
|
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);
|
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 {
|
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 {
|
void WorldConverter::convertPlayer(const fs::path& file) const {
|
||||||
logger.info() << "converting player " << file.u8string();
|
logger.info() << "converting player " << file.u8string();
|
||||||
auto map = files::read_json(file);
|
auto map = io::read_json(file);
|
||||||
Player::convert(map, report.get());
|
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 {
|
void WorldConverter::convertBlocksData(int x, int z, const ContentReport& report) const {
|
||||||
|
|||||||
@ -100,7 +100,7 @@ void WorldFiles::writePacks(const std::vector<ContentPack>& packs) {
|
|||||||
for (const auto& pack : packs) {
|
for (const auto& pack : packs) {
|
||||||
ss << pack.id << "\n";
|
ss << pack.id << "\n";
|
||||||
}
|
}
|
||||||
files::write_string(packsFile, ss.str());
|
io::write_string(packsFile, ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -139,11 +139,11 @@ void WorldFiles::writeIndices(const ContentIndices* indices) {
|
|||||||
createContentIndicesCache(indices, root);
|
createContentIndicesCache(indices, root);
|
||||||
createBlockFieldsIndices(indices, root);
|
createBlockFieldsIndices(indices, root);
|
||||||
|
|
||||||
files::write_json(getIndicesFile(), root);
|
io::write_json(getIndicesFile(), root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFiles::writeWorldInfo(const WorldInfo& info) {
|
void WorldFiles::writeWorldInfo(const WorldInfo& info) {
|
||||||
files::write_json(getWorldFile(), info.serialize());
|
io::write_json(getWorldFile(), info.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<WorldInfo> WorldFiles::readWorldInfo() {
|
std::optional<WorldInfo> WorldFiles::readWorldInfo() {
|
||||||
@ -152,7 +152,7 @@ std::optional<WorldInfo> WorldFiles::readWorldInfo() {
|
|||||||
logger.warning() << "world.json does not exists";
|
logger.warning() << "world.json does not exists";
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
auto root = files::read_json(file);
|
auto root = io::read_json(file);
|
||||||
WorldInfo info {};
|
WorldInfo info {};
|
||||||
info.deserialize(root);
|
info.deserialize(root);
|
||||||
return info;
|
return info;
|
||||||
@ -180,7 +180,7 @@ bool WorldFiles::readResourcesData(const Content& content) {
|
|||||||
logger.warning() << "resources.json does not exists";
|
logger.warning() << "resources.json does not exists";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto root = files::read_json(file);
|
auto root = io::read_json(file);
|
||||||
for (const auto& [key, arr] : root.asObject()) {
|
for (const auto& [key, arr] : root.asObject()) {
|
||||||
if (auto resType = ResourceType_from(key)) {
|
if (auto resType = ResourceType_from(key)) {
|
||||||
read_resources_data(content, arr, *resType);
|
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";
|
logger.error() << file.filename().u8string() << " does not exists";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto root = files::read_json(file);
|
auto root = io::read_json(file);
|
||||||
for (const auto& [key, value] : map.asObject()) {
|
for (const auto& [key, value] : map.asObject()) {
|
||||||
logger.info() << "patching indices.json: update " << util::quote(key);
|
logger.info() << "patching indices.json: update " << util::quote(key);
|
||||||
root[key] = value;
|
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) {
|
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<std::string>& packs) {
|
void WorldFiles::removeIndices(const std::vector<std::string>& packs) {
|
||||||
auto root = files::read_json(getIndicesFile());
|
auto root = io::read_json(getIndicesFile());
|
||||||
for (const auto& id : packs) {
|
for (const auto& id : packs) {
|
||||||
erase_pack_indices(root, id);
|
erase_pack_indices(root, id);
|
||||||
}
|
}
|
||||||
files::write_json(getIndicesFile(), root);
|
io::write_json(getIndicesFile(), root);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path WorldFiles::getFolder() const {
|
fs::path WorldFiles::getFolder() const {
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "WorldRegions.hpp"
|
#include "WorldRegions.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
#include <glm/gtx/hash.hpp>
|
#include <glm/gtx/hash.hpp>
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "maths/voxmaths.hpp"
|
#include "maths/voxmaths.hpp"
|
||||||
#include "coders/compression.hpp"
|
#include "coders/compression.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "world_regions_fwd.hpp"
|
#include "world_regions_fwd.hpp"
|
||||||
|
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
@ -54,7 +54,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct regfile {
|
struct regfile {
|
||||||
files::rafile file;
|
io::rafile file;
|
||||||
int version;
|
int version;
|
||||||
bool inUse = false;
|
bool inUse = false;
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
#include "coders/commons.hpp"
|
#include "coders/commons.hpp"
|
||||||
#include "coders/lua_parsing.hpp"
|
#include "coders/lua_parsing.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
|
|
||||||
TEST(lua_parsing, Tokenizer) {
|
TEST(lua_parsing, Tokenizer) {
|
||||||
auto filename = "../../res/scripts/stdlib.lua";
|
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 {
|
try {
|
||||||
auto tokens = lua::tokenize(filename, source);
|
auto tokens = lua::tokenize(filename, source);
|
||||||
for (const auto& token : tokens) {
|
for (const auto& token : tokens) {
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "coders/vec3.hpp"
|
#include "coders/vec3.hpp"
|
||||||
#include "files/files.hpp"
|
#include "io/io.hpp"
|
||||||
|
|
||||||
TEST(VEC3, Decode) {
|
TEST(VEC3, Decode) {
|
||||||
auto file = std::filesystem::u8path(
|
auto file = std::filesystem::u8path(
|
||||||
"res/models/block.vec3"
|
"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);
|
auto model = vec3::load(file.u8string(), bytes);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user