diff --git a/src/inferno/io/gltffile.cpp b/src/inferno/io/gltffile.cpp index 3ac12f3..a06e7c0 100644 --- a/src/inferno/io/gltffile.cpp +++ b/src/inferno/io/gltffile.cpp @@ -2,9 +2,9 @@ #include // std::ifstream #include // std::ios +#include "ruc/file.h" #include "ruc/meta/assert.h" -#include "inferno/io/file.h" #include "inferno/io/gltffile.h" #include "inferno/io/log.h" #include "inferno/util/json.h" @@ -20,7 +20,7 @@ std::pair, std::shared_ptr> GltfFile::read(const return glb(path); } else if (extension.compare(".gltf") == 0) { - return { File::raw(path), nullptr }; + return { ruc::File::raw(path), nullptr }; } VERIFY(false, "GltfFile unknown file extension!"); @@ -38,7 +38,7 @@ std::pair, std::shared_ptr> GltfFile::glb(const constexpr uint32_t json = 27; // Minimum valid glTF has an asset property with version specifier // Get the actual length of the file - uint32_t length = static_cast(File::length(path, glb)); + uint32_t length = static_cast(ruc::File::length(path, glb)); VERIFY(length > header + json, "GltfFile too small to be valid '{}'", path); // Read header @@ -62,7 +62,7 @@ std::pair, std::shared_ptr> GltfFile::glb(const VERIFY(versionInt == 2, "Gltf unsupported version '{}'", versionInt); uint32_t fileLengthInt = *reinterpret_cast(fileLength); - VERIFY(fileLengthInt == length, "Gltf file and reported byte size mismatch '{}' '{}'", length, fileLengthInt); + VERIFY(fileLengthInt == static_cast(length), "Gltf file and reported byte size mismatch '{}' '{}'", length, fileLengthInt); // Read JSON data auto jsonChunk = readChunk(glb, header, 0x4e4f534a); diff --git a/src/inferno/render/font.cpp b/src/inferno/render/font.cpp index 1077222..48ba387 100644 --- a/src/inferno/render/font.cpp +++ b/src/inferno/render/font.cpp @@ -2,9 +2,9 @@ #include // std::getline, std::stoi #include // std::move +#include "ruc/file.h" #include "ruc/meta/assert.h" -#include "inferno/io/file.h" #include "inferno/render/font.h" #include "inferno/render/texture.h" #include "inferno/util/integer.h" @@ -17,7 +17,7 @@ Font::Font(const std::string& name) std::string path = name + ".fnt"; std::string image = name + ".png"; - std::string font = File::read(path); + std::string font = ruc::File(path).data(); parseFont(font); m_texture = std::make_shared(image); diff --git a/src/inferno/render/shader.cpp b/src/inferno/render/shader.cpp index 494b56b..dae057a 100644 --- a/src/inferno/render/shader.cpp +++ b/src/inferno/render/shader.cpp @@ -3,10 +3,10 @@ #include "glad/glad.h" #include "glm/gtc/type_ptr.hpp" // glm::value_ptr +#include "ruc/file.h" #include "ruc/meta/assert.h" #include "inferno/core.h" -#include "inferno/io/file.h" #include "inferno/io/log.h" #include "inferno/render/shader.h" @@ -17,8 +17,8 @@ Shader::Shader(const std::string& name) , m_id(0) { // Get file contents - std::string vertexSrc = File::read(name + ".vert"); - std::string fragmentSrc = File::read(name + ".frag"); + std::string vertexSrc = ruc::File(name + ".vert").data(); + std::string fragmentSrc = ruc::File(name + ".frag").data(); // Compile shaders uint32_t vertexID = compileShader(GL_VERTEX_SHADER, vertexSrc.c_str()); diff --git a/src/inferno/script/luascript.cpp b/src/inferno/script/luascript.cpp index 5432ec6..bbef506 100644 --- a/src/inferno/script/luascript.cpp +++ b/src/inferno/script/luascript.cpp @@ -1,10 +1,10 @@ +#include "ruc/file.h" #include "sol/unsafe_function_result.hpp" #include "inferno/component/cameracomponent.h" #include "inferno/component/spritecomponent.h" #include "inferno/component/tagcomponent.h" #include "inferno/component/transformcomponent.h" -#include "inferno/io/file.h" #include "inferno/scene/scene.h" #include "inferno/script/luascript.h" #include "inferno/script/registration.h" @@ -63,7 +63,7 @@ void LuaScript::update(float deltaTime) void LuaScript::loadScript() { - std::string script = File::read(m_path); + std::string script = ruc::File(m_path).data(); auto result = m_state.script(script.c_str(), [](lua_State*, sol::protected_function_result pfr) { return pfr; }); VERIFY(result.valid(), "LuaScript {}", ((sol::error)result).what()); diff --git a/src/inferno/settings.cpp b/src/inferno/settings.cpp index a4b8d78..2fe5795 100644 --- a/src/inferno/settings.cpp +++ b/src/inferno/settings.cpp @@ -1,9 +1,9 @@ #include // uint32_t #include // std::string +#include "ruc/file.h" #include "ruc/json/json.h" -#include "inferno/io/file.h" #include "inferno/io/log.h" #include "inferno/settings.h" #include "inferno/window.h" @@ -28,9 +28,9 @@ void Settings::destroy() bool Settings::load() { - ruc::Json object; + auto object = ruc::Json::parse(ruc::File(m_path).data()); - if (!File::ioRead(&object, m_path)) { + if (object.type() != ruc::Json::Type::Object) { warn() << "Settings invalid formatting, using default values"; return false; } @@ -44,10 +44,11 @@ bool Settings::save() { ruc::Json object = m_properties; - if (!File::ioWrite(&object, m_path)) { - warn() << "Settings could not be saved"; - return false; - } + auto file = ruc::File(m_path); + file.clear(); + file.append(object.dump(1, '\t')); + file.append("\n"); + file.flush(); info() << "Settings saved"; return true;