diff --git a/engine/asset/include/asset.hpp b/engine/asset/include/asset.hpp index 1fe35b9..854e8a5 100644 --- a/engine/asset/include/asset.hpp +++ b/engine/asset/include/asset.hpp @@ -130,7 +130,7 @@ std::unique_ptr load_mesh(const file::Path path); std::unique_ptr load_material(const file::Path path); std::unique_ptr load_texture(const file::Path path); -void save_material(Material* material, const std::string_view path); +void save_material(Material* material, const file::Path path); template std::unique_ptr load_asset(const file::Path path) { diff --git a/engine/asset/src/asset.cpp b/engine/asset/src/asset.cpp index 9ff8ad0..a6066eb 100644 --- a/engine/asset/src/asset.cpp +++ b/engine/asset/src/asset.cpp @@ -341,7 +341,7 @@ std::unique_ptr load_material(const file::Path path) { return mat; } -void save_material(Material* material, const std::string_view path) { +void save_material(Material* material, const file::Path path) { Expects(material != nullptr); Expects(!path.empty()); @@ -383,6 +383,6 @@ void save_material(Material* material, const std::string_view path) { j["nodes"].push_back(n); } - std::ofstream out(path.data()); + std::ofstream out(path); out << j; } diff --git a/engine/core/include/file.hpp b/engine/core/include/file.hpp index 8130457..e54c051 100755 --- a/engine/core/include/file.hpp +++ b/engine/core/include/file.hpp @@ -129,6 +129,7 @@ namespace file { std::optional open(const Path path, const bool binary_mode = false); Path root_path(const Path path); + Path get_file_path(const Path path); inline Path internal_domain = "/internal", app_domain = "/app"; } diff --git a/engine/core/src/file.cpp b/engine/core/src/file.cpp index 6905dfe..c9b55dd 100755 --- a/engine/core/src/file.cpp +++ b/engine/core/src/file.cpp @@ -17,7 +17,17 @@ file::Path file::root_path(const Path path) { std::optional file::open(const file::Path path, const bool binary_mode) { Expects(!path.empty()); - + + FILE* file = fopen(get_file_path(path).string().c_str(), binary_mode ? "rb" : "r"); + if(file == nullptr) { + console::error(System::File, "Failed to open file handle from {}!", path); + return {}; + } + + return file::File(file); +} + +file::Path file::get_file_path(const file::Path path) { auto fixed_path = path; if(root_path(path) == app_domain) { fixed_path = domain_data[static_cast(Domain::App)] / path.lexically_relative(root_path(path)); @@ -25,13 +35,7 @@ std::optional file::open(const file::Path path, const bool binary_mo fixed_path = domain_data[static_cast(Domain::Internal)] / path.lexically_relative(root_path(path)); } - FILE* file = fopen(fixed_path.string().c_str(), binary_mode ? "rb" : "r"); - if(file == nullptr) { - console::error(System::File, "Failed to open file handle from {}!", path); - return {}; - } - - return file::File(file); + return fixed_path; } file::Path file::get_domain_path(const Domain domain) { diff --git a/tools/editor/src/materialeditor.cpp b/tools/editor/src/materialeditor.cpp index 9fa60a5..4e226d0 100755 --- a/tools/editor/src/materialeditor.cpp +++ b/tools/editor/src/materialeditor.cpp @@ -83,7 +83,7 @@ void MaterialEditor::draw(CommonEditor* editor) { save_material(*material, path); }); } else { - //save_material(*material, file::get_file_path(FileDomain::GameData, path)); + save_material(*material, file::get_file_path(path)); } }