Fix material saving
This commit is contained in:
parent
2181611c2e
commit
cc151ad07e
5 changed files with 17 additions and 12 deletions
|
@ -130,7 +130,7 @@ std::unique_ptr<Mesh> load_mesh(const file::Path path);
|
|||
std::unique_ptr<Material> load_material(const file::Path path);
|
||||
std::unique_ptr<Texture> 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<typename T>
|
||||
std::unique_ptr<T> load_asset(const file::Path path) {
|
||||
|
|
|
@ -341,7 +341,7 @@ std::unique_ptr<Material> 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;
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ namespace file {
|
|||
std::optional<File> 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";
|
||||
}
|
||||
|
|
|
@ -18,6 +18,16 @@ file::Path file::root_path(const Path path) {
|
|||
std::optional<file::File> 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<int>(Domain::App)] / path.lexically_relative(root_path(path));
|
||||
|
@ -25,13 +35,7 @@ std::optional<file::File> file::open(const file::Path path, const bool binary_mo
|
|||
fixed_path = domain_data[static_cast<int>(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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue