From c3606cb5f3ab82248cac0d748bb291aa978b0b58 Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 3 Jun 2022 01:33:42 +0200 Subject: [PATCH] Swap arguments of ResourceSaver.save() --- core/core_bind.cpp | 8 +++---- core/core_bind.h | 2 +- core/crypto/crypto.cpp | 2 +- core/crypto/crypto.h | 2 +- core/io/resource_format_binary.cpp | 4 ++-- core/io/resource_format_binary.h | 2 +- core/io/resource_saver.cpp | 24 ++++++++++++------- core/io/resource_saver.h | 6 ++--- doc/classes/ResourceFormatSaver.xml | 4 ++-- doc/classes/ResourceSaver.xml | 6 ++--- drivers/png/resource_saver_png.cpp | 2 +- drivers/png/resource_saver_png.h | 2 +- editor/editor_audio_buses.cpp | 4 ++-- editor/editor_node.cpp | 10 ++++---- editor/editor_resource_preview.cpp | 4 ++-- editor/editor_settings.cpp | 12 +++------- editor/editor_settings.h | 2 -- editor/import/resource_importer_bitmask.cpp | 2 +- editor/import/resource_importer_bmfont.cpp | 2 +- .../resource_importer_csv_translation.cpp | 2 +- .../import/resource_importer_dynamic_font.cpp | 2 +- editor/import/resource_importer_imagefont.cpp | 2 +- editor/import/resource_importer_obj.cpp | 2 +- editor/import/resource_importer_scene.cpp | 8 +++---- .../import/resource_importer_shader_file.cpp | 2 +- .../resource_importer_texture_atlas.cpp | 4 ++-- editor/import/resource_importer_wav.cpp | 2 +- editor/import/scene_import_settings.cpp | 2 +- editor/plugin_config_dialog.cpp | 4 ++-- editor/plugins/shader_editor_plugin.cpp | 8 +++---- editor/plugins/skeleton_3d_editor_plugin.cpp | 2 +- editor/plugins/voxel_gi_editor_plugin.cpp | 2 +- editor/project_manager.cpp | 2 +- editor/scene_tree_dock.cpp | 2 +- editor/script_create_dialog.cpp | 2 +- editor/shader_create_dialog.cpp | 4 ++-- modules/gdscript/gdscript.cpp | 2 +- modules/gdscript/gdscript.h | 2 +- modules/minimp3/resource_importer_mp3.cpp | 2 +- modules/mono/csharp_script.cpp | 2 +- modules/mono/csharp_script.h | 2 +- .../editor/openxr_action_map_editor.cpp | 2 +- modules/openxr/openxr_interface.cpp | 2 +- .../vorbis/resource_importer_ogg_vorbis.cpp | 2 +- modules/webp/resource_saver_webp.cpp | 2 +- modules/webp/resource_saver_webp.h | 2 +- platform/macos/export/export_plugin.cpp | 2 +- scene/3d/lightmap_gi.cpp | 2 +- scene/3d/occluder_instance_3d.cpp | 2 +- scene/debugger/scene_debugger.cpp | 2 +- scene/resources/resource_format_text.cpp | 2 +- scene/resources/resource_format_text.h | 2 +- scene/resources/shader.cpp | 2 +- scene/resources/shader.h | 2 +- scene/resources/shader_include.cpp | 2 +- scene/resources/shader_include.h | 2 +- tests/core/io/test_resource.h | 4 ++-- 57 files changed, 97 insertions(+), 99 deletions(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index dd4dda5e426a..3852f77bfc11 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -147,9 +147,9 @@ void ResourceLoader::_bind_methods() { ////// ResourceSaver ////// -Error ResourceSaver::save(const String &p_path, const Ref &p_resource, BitField p_flags) { - ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path '" + String(p_path) + "'."); - return ::ResourceSaver::save(p_path, p_resource, p_flags); +Error ResourceSaver::save(const Ref &p_resource, const String &p_path, BitField p_flags) { + ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path '" + p_path + "'."); + return ::ResourceSaver::save(p_resource, p_path, p_flags); } Vector ResourceSaver::get_recognized_extensions(const Ref &p_resource) { @@ -174,7 +174,7 @@ void ResourceSaver::remove_resource_format_saver(Ref p_form ResourceSaver *ResourceSaver::singleton = nullptr; void ResourceSaver::_bind_methods() { - ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &ResourceSaver::save, DEFVAL((uint32_t)FLAG_NONE)); + ClassDB::bind_method(D_METHOD("save", "resource", "path", "flags"), &ResourceSaver::save, DEFVAL(""), DEFVAL((uint32_t)FLAG_NONE)); ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions); ClassDB::bind_method(D_METHOD("add_resource_format_saver", "format_saver", "at_front"), &ResourceSaver::add_resource_format_saver, DEFVAL(false)); ClassDB::bind_method(D_METHOD("remove_resource_format_saver", "format_saver"), &ResourceSaver::remove_resource_format_saver); diff --git a/core/core_bind.h b/core/core_bind.h index f98de81354c0..068d2a6dc38e 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -109,7 +109,7 @@ public: static ResourceSaver *get_singleton() { return singleton; } - Error save(const String &p_path, const Ref &p_resource, BitField p_flags); + Error save(const Ref &p_resource, const String &p_path, BitField p_flags); Vector get_recognized_extensions(const Ref &p_resource); void add_resource_format_saver(Ref p_format_saver, bool p_at_front); void remove_resource_format_saver(Ref p_format_saver); diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index d0fd4feaa5f0..a164eb7a5712 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -185,7 +185,7 @@ String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const return ""; } -Error ResourceFormatSaverCrypto::save(const String &p_path, const Ref &p_resource, uint32_t p_flags) { +Error ResourceFormatSaverCrypto::save(const Ref &p_resource, const String &p_path, uint32_t p_flags) { Error err; Ref cert = p_resource; Ref key = p_resource; diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h index fb4f7dd88fd6..10c9564ad930 100644 --- a/core/crypto/crypto.h +++ b/core/crypto/crypto.h @@ -125,7 +125,7 @@ public: class ResourceFormatSaverCrypto : public ResourceFormatSaver { public: - virtual Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = 0); + virtual Error save(const Ref &p_resource, const String &p_path, uint32_t p_flags = 0); virtual void get_recognized_extensions(const Ref &p_resource, List *p_extensions) const; virtual bool recognize(const Ref &p_resource) const; }; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 016302c65341..b731608b4f28 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1267,7 +1267,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons Ref res = loader.get_resource(); ERR_FAIL_COND_V(!res.is_valid(), ERR_FILE_CORRUPT); - return ResourceFormatSaverBinary::singleton->save(p_path, res); + return ResourceFormatSaverBinary::singleton->save(res, p_path); } if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { @@ -2204,7 +2204,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref &p_resource, uint32_t p_flags) { +Error ResourceFormatSaverBinary::save(const Ref &p_resource, const String &p_path, uint32_t p_flags) { String local_path = ProjectSettings::get_singleton()->localize_path(p_path); ResourceFormatSaverBinaryInstance saver; return saver.save(local_path, p_resource, p_flags); diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 2b043302fd09..c891a61e99a1 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -176,7 +176,7 @@ public: class ResourceFormatSaverBinary : public ResourceFormatSaver { public: static ResourceFormatSaverBinary *singleton; - virtual Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = 0); + virtual Error save(const Ref &p_resource, const String &p_path, uint32_t p_flags = 0); virtual bool recognize(const Ref &p_resource) const; virtual void get_recognized_extensions(const Ref &p_resource, List *p_extensions) const; diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 2f5c5b54dd6b..41e2f0e11684 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -41,9 +41,9 @@ bool ResourceSaver::timestamp_on_save = false; ResourceSavedCallback ResourceSaver::save_callback = nullptr; ResourceSaverGetResourceIDForPath ResourceSaver::save_get_id_for_path = nullptr; -Error ResourceFormatSaver::save(const String &p_path, const Ref &p_resource, uint32_t p_flags) { +Error ResourceFormatSaver::save(const Ref &p_resource, const String &p_path, uint32_t p_flags) { int64_t res; - if (GDVIRTUAL_CALL(_save, p_path, p_resource, p_flags, res)) { + if (GDVIRTUAL_CALL(_save, p_resource, p_path, p_flags, res)) { return (Error)res; } @@ -75,8 +75,14 @@ void ResourceFormatSaver::_bind_methods() { GDVIRTUAL_BIND(_get_recognized_extensions, "resource"); } -Error ResourceSaver::save(const String &p_path, const Ref &p_resource, uint32_t p_flags) { - String extension = p_path.get_extension(); +Error ResourceSaver::save(const Ref &p_resource, const String &p_path, uint32_t p_flags) { + String path = p_path; + if (path.is_empty()) { + path = p_resource->get_path(); + } + ERR_FAIL_COND_V_MSG(p_path.is_empty(), ERR_INVALID_PARAMETER, "Can't save resource to empty path. Provide non-empty path or a Resource with non-empty resource_path."); + + String extension = path.get_extension(); Error err = ERR_FILE_UNRECOGNIZED; for (int i = 0; i < saver_count; i++) { @@ -100,21 +106,21 @@ Error ResourceSaver::save(const String &p_path, const Ref &p_resource, String old_path = p_resource->get_path(); - String local_path = ProjectSettings::get_singleton()->localize_path(p_path); + String local_path = ProjectSettings::get_singleton()->localize_path(path); Ref rwcopy = p_resource; if (p_flags & FLAG_CHANGE_PATH) { rwcopy->set_path(local_path); } - err = saver[i]->save(p_path, p_resource, p_flags); + err = saver[i]->save(p_resource, path, p_flags); if (err == OK) { #ifdef TOOLS_ENABLED ((Resource *)p_resource.ptr())->set_edited(false); if (timestamp_on_save) { - uint64_t mt = FileAccess::get_modified_time(p_path); + uint64_t mt = FileAccess::get_modified_time(path); ((Resource *)p_resource.ptr())->set_last_modified_time(mt); } @@ -124,8 +130,8 @@ Error ResourceSaver::save(const String &p_path, const Ref &p_resource, rwcopy->set_path(old_path); } - if (save_callback && p_path.begins_with("res://")) { - save_callback(p_resource, p_path); + if (save_callback && path.begins_with("res://")) { + save_callback(p_resource, path); } return OK; diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 088317bfbea9..4fee2bcfd114 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -41,12 +41,12 @@ class ResourceFormatSaver : public RefCounted { protected: static void _bind_methods(); - GDVIRTUAL3R(int64_t, _save, String, Ref, uint32_t) + GDVIRTUAL3R(int64_t, _save, Ref, String, uint32_t) GDVIRTUAL1RC(bool, _recognize, Ref) GDVIRTUAL1RC(Vector, _get_recognized_extensions, Ref) public: - virtual Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = 0); + virtual Error save(const Ref &p_resource, const String &p_path, uint32_t p_flags = 0); virtual bool recognize(const Ref &p_resource) const; virtual void get_recognized_extensions(const Ref &p_resource, List *p_extensions) const; @@ -81,7 +81,7 @@ public: FLAG_REPLACE_SUBRESOURCE_PATHS = 64, }; - static Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = (uint32_t)FLAG_NONE); + static Error save(const Ref &p_resource, const String &p_path = "", uint32_t p_flags = (uint32_t)FLAG_NONE); static void get_recognized_extensions(const Ref &p_resource, List *p_extensions); static void add_resource_format_saver(Ref p_format_saver, bool p_at_front = false); static void remove_resource_format_saver(Ref p_format_saver); diff --git a/doc/classes/ResourceFormatSaver.xml b/doc/classes/ResourceFormatSaver.xml index c156814a1d07..f9c4ca0d4988 100644 --- a/doc/classes/ResourceFormatSaver.xml +++ b/doc/classes/ResourceFormatSaver.xml @@ -26,8 +26,8 @@ - - + + Saves the given resource object to a file at the target [code]path[/code]. [code]flags[/code] is a bitmask composed with [enum ResourceSaver.SaverFlags] constants. diff --git a/doc/classes/ResourceSaver.xml b/doc/classes/ResourceSaver.xml index 240c72a1313d..10387a4f1440 100644 --- a/doc/classes/ResourceSaver.xml +++ b/doc/classes/ResourceSaver.xml @@ -35,11 +35,11 @@ - - + + - Saves a resource to disk to the given path, using a [ResourceFormatSaver] that recognizes the resource object. + Saves a resource to disk to the given path, using a [ResourceFormatSaver] that recognizes the resource object. If [code]path[/code] is empty, [ResourceSaver] will try to use [member Resource.resource_path]. The [code]flags[/code] bitmask can be specified to customize the save behavior using [enum SaverFlags] flags. Returns [constant OK] on success. diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index 704ddca726da..275f3240d7a4 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -35,7 +35,7 @@ #include "drivers/png/png_driver_common.h" #include "scene/resources/texture.h" -Error ResourceSaverPNG::save(const String &p_path, const Ref &p_resource, uint32_t p_flags) { +Error ResourceSaverPNG::save(const Ref &p_resource, const String &p_path, uint32_t p_flags) { Ref texture = p_resource; ERR_FAIL_COND_V_MSG(!texture.is_valid(), ERR_INVALID_PARAMETER, "Can't save invalid texture as PNG."); diff --git a/drivers/png/resource_saver_png.h b/drivers/png/resource_saver_png.h index 1a681faaecf5..260a643a1b42 100644 --- a/drivers/png/resource_saver_png.h +++ b/drivers/png/resource_saver_png.h @@ -39,7 +39,7 @@ public: static Error save_image(const String &p_path, const Ref &p_img); static Vector save_image_to_buffer(const Ref &p_img); - virtual Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = 0); + virtual Error save(const Ref &p_resource, const String &p_path, uint32_t p_flags = 0); virtual bool recognize(const Ref &p_resource) const; virtual void get_recognized_extensions(const Ref &p_resource, List *p_extensions) const; diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 1a51593fac46..556a0176cb56 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -1174,7 +1174,7 @@ void EditorAudioBuses::_drop_at_index(int p_bus, int p_index) { void EditorAudioBuses::_server_save() { Ref state = AudioServer::get_singleton()->generate_bus_layout(); - ResourceSaver::save(edited_path, state); + ResourceSaver::save(state, edited_path); } void EditorAudioBuses::_select_layout() { @@ -1244,7 +1244,7 @@ void EditorAudioBuses::_file_dialog_callback(const String &p_string) { AudioServer::get_singleton()->set_bus_layout(empty_state); } - Error err = ResourceSaver::save(p_string, AudioServer::get_singleton()->generate_bus_layout()); + Error err = ResourceSaver::save(AudioServer::get_singleton()->generate_bus_layout(), p_string); if (err != OK) { EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving file: %s"), p_string)); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 00855e01bc41..e10394a2a81c 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1225,7 +1225,7 @@ void EditorNode::save_resource_in_path(const Ref &p_resource, const St } String path = ProjectSettings::get_singleton()->localize_path(p_path); - Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); + Error err = ResourceSaver::save(p_resource, path, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); if (err != OK) { if (ResourceLoader::is_imported(p_resource->get_path())) { @@ -1448,7 +1448,7 @@ bool EditorNode::_find_and_save_resource(Ref p_res, HashMapget_path().is_resource_file()) { if (changed || subchanged) { - ResourceSaver::save(p_res->get_path(), p_res, flags); + ResourceSaver::save(p_res, p_res->get_path(), flags); } processed[p_res] = false; // Because it's a file. return false; @@ -1679,7 +1679,7 @@ int EditorNode::_save_external_resources() { if (ps.is_valid()) { continue; // Do not save PackedScenes, this will mess up the editor. } - ResourceSaver::save(res->get_path(), res, flg); + ResourceSaver::save(res, res->get_path(), flg); saved++; } @@ -1750,7 +1750,7 @@ void EditorNode::_save_scene(String p_file, int idx) { } flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; - err = ResourceSaver::save(p_file, sdata, flg); + err = ResourceSaver::save(sdata, p_file, flg); // This needs to be emitted before saving external resources. emit_signal(SNAME("scene_saved"), p_file); @@ -1957,7 +1957,7 @@ void EditorNode::_dialog_action(String p_file) { MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(), ml, true, file_export_lib_apply_xforms->is_pressed()); - Error err = ResourceSaver::save(p_file, ml); + Error err = ResourceSaver::save(ml, p_file); if (err) { show_accept(TTR("Error saving MeshLibrary!"), TTR("OK")); return; diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index b84e654d42b4..c0ea2b743e35 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -195,9 +195,9 @@ void EditorResourcePreview::_generate_preview(Ref &r_texture, Ref< if (r_texture.is_valid()) { //wow it generated a preview... save cache bool has_small_texture = r_small_texture.is_valid(); - ResourceSaver::save(cache_base + ".png", r_texture); + ResourceSaver::save(r_texture, cache_base + ".png"); if (has_small_texture) { - ResourceSaver::save(cache_base + "_small.png", r_small_texture); + ResourceSaver::save(r_small_texture, cache_base + "_small.png"); } Ref f = FileAccess::open(cache_base + ".txt", FileAccess::WRITE); ERR_FAIL_COND_MSG(f.is_null(), "Cannot create file '" + cache_base + ".txt'. Check user write permissions."); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index bde9f3e93112..37a531299ffe 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -867,7 +867,6 @@ void EditorSettings::create() { } singleton->save_changed_setting = true; - singleton->config_file_path = config_file_path; print_verbose("EditorSettings: Load OK!"); @@ -892,8 +891,8 @@ fail: } singleton = Ref(memnew(EditorSettings)); + singleton->set_path(config_file_path, true); singleton->save_changed_setting = true; - singleton->config_file_path = config_file_path; singleton->_load_defaults(extra_config); singleton->setup_language(); singleton->setup_network(); @@ -953,15 +952,10 @@ void EditorSettings::save() { return; } - if (singleton->config_file_path.is_empty()) { - ERR_PRINT("Cannot save EditorSettings config, no valid path"); - return; - } - - Error err = ResourceSaver::save(singleton->config_file_path, singleton); + Error err = ResourceSaver::save(singleton); if (err != OK) { - ERR_PRINT("Error saving editor settings to " + singleton->config_file_path); + ERR_PRINT("Error saving editor settings to " + singleton->get_path()); } else { singleton->changed_settings.clear(); print_verbose("EditorSettings: Save OK!"); diff --git a/editor/editor_settings.h b/editor/editor_settings.h index 24e77295bb48..5faeec88c8a2 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -88,8 +88,6 @@ private: mutable HashMap> shortcuts; HashMap>> builtin_action_overrides; - String config_file_path; - Vector favorites; Vector recent_dirs; diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp index 966719dc48e1..c03962b8a495 100644 --- a/editor/import/resource_importer_bitmask.cpp +++ b/editor/import/resource_importer_bitmask.cpp @@ -103,7 +103,7 @@ Error ResourceImporterBitMap::import(const String &p_source_file, const String & } } - return ResourceSaver::save(p_save_path + ".res", bitmap); + return ResourceSaver::save(bitmap, p_save_path + ".res"); } ResourceImporterBitMap::ResourceImporterBitMap() { diff --git a/editor/import/resource_importer_bmfont.cpp b/editor/import/resource_importer_bmfont.cpp index 987ca4b91130..14b563875599 100644 --- a/editor/import/resource_importer_bmfont.cpp +++ b/editor/import/resource_importer_bmfont.cpp @@ -84,7 +84,7 @@ Error ResourceImporterBMFont::import(const String &p_source_file, const String & } print_verbose("Saving to: " + p_save_path + ".fontdata"); - err = ResourceSaver::save(p_save_path + ".fontdata", font, flg); + err = ResourceSaver::save(font, p_save_path + ".fontdata", flg); ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save font to file \"" + p_save_path + ".res\"."); print_verbose("Done saving to: " + p_save_path + ".fontdata"); return OK; diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index 0b3622e3c0e2..8b429e74d12d 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -131,7 +131,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const String save_path = p_source_file.get_basename() + "." + translations[i]->get_locale() + ".translation"; - ResourceSaver::save(save_path, xlt); + ResourceSaver::save(xlt, save_path); if (r_gen_files) { r_gen_files->push_back(save_path); } diff --git a/editor/import/resource_importer_dynamic_font.cpp b/editor/import/resource_importer_dynamic_font.cpp index f1a70ff30a09..32fd94b093e6 100644 --- a/editor/import/resource_importer_dynamic_font.cpp +++ b/editor/import/resource_importer_dynamic_font.cpp @@ -219,7 +219,7 @@ Error ResourceImporterDynamicFont::import(const String &p_source_file, const Str } print_verbose("Saving to: " + p_save_path + ".fontdata"); - Error err = ResourceSaver::save(p_save_path + ".fontdata", font, flg); + Error err = ResourceSaver::save(font, p_save_path + ".fontdata", flg); ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save font to file \"" + p_save_path + ".res\"."); print_verbose("Done saving to: " + p_save_path + ".fontdata"); return OK; diff --git a/editor/import/resource_importer_imagefont.cpp b/editor/import/resource_importer_imagefont.cpp index ea84d4c883c1..374cbe7ce212 100644 --- a/editor/import/resource_importer_imagefont.cpp +++ b/editor/import/resource_importer_imagefont.cpp @@ -159,7 +159,7 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin } print_verbose("Saving to: " + p_save_path + ".fontdata"); - err = ResourceSaver::save(p_save_path + ".fontdata", font, flg); + err = ResourceSaver::save(font, p_save_path + ".fontdata", flg); ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save font to file \"" + p_save_path + ".res\"."); print_verbose("Done saving to: " + p_save_path + ".fontdata"); return OK; diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 6fbfecfdfac6..d1c4e1f8dd50 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -519,7 +519,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s String save_path = p_save_path + ".mesh"; - err = ResourceSaver::save(save_path, meshes.front()->get()); + err = ResourceSaver::save(meshes.front()->get(), save_path); ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save Mesh to file '" + save_path + "'."); diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index fab3e000cfd2..3c0de61d24af 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -1224,7 +1224,7 @@ Ref ResourceImporterScene::_save_animation_to_file(Ref ani } } anim->set_path(p_save_to_path, true); // Set path to save externally. - Error err = ResourceSaver::save(p_save_to_path, anim, ResourceSaver::FLAG_CHANGE_PATH); + Error err = ResourceSaver::save(anim, p_save_to_path, ResourceSaver::FLAG_CHANGE_PATH); ERR_FAIL_COND_V_MSG(err != OK, anim, "Saving of animation failed: " + p_save_to_path); return anim; } @@ -1842,7 +1842,7 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m } mesh = src_mesh_node->get_mesh()->get_mesh(existing); - ResourceSaver::save(save_to_file, mesh); //override + ResourceSaver::save(mesh, save_to_file); //override mesh->set_path(save_to_file, true); //takeover existing, if needed @@ -2310,14 +2310,14 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p } print_verbose("Saving animation to: " + p_save_path + ".scn"); - err = ResourceSaver::save(p_save_path + ".res", library); //do not take over, let the changed files reload themselves + err = ResourceSaver::save(library, p_save_path + ".res"); //do not take over, let the changed files reload themselves ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save animation to file '" + p_save_path + ".res'."); } else { Ref packer = memnew(PackedScene); packer->pack(scene); print_verbose("Saving scene to: " + p_save_path + ".scn"); - err = ResourceSaver::save(p_save_path + ".scn", packer); //do not take over, let the changed files reload themselves + err = ResourceSaver::save(packer, p_save_path + ".scn"); //do not take over, let the changed files reload themselves ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save scene to file '" + p_save_path + ".scn'."); } diff --git a/editor/import/resource_importer_shader_file.cpp b/editor/import/resource_importer_shader_file.cpp index 64839bf199f2..d3079141e081 100644 --- a/editor/import/resource_importer_shader_file.cpp +++ b/editor/import/resource_importer_shader_file.cpp @@ -109,7 +109,7 @@ Error ResourceImporterShaderFile::import(const String &p_source_file, const Stri } } - ResourceSaver::save(p_save_path + ".res", shader_file); + ResourceSaver::save(shader_file, p_save_path + ".res"); return OK; } diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index 93afb3381ed1..bae1b903c67c 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -88,7 +88,7 @@ Error ResourceImporterTextureAtlas::import(const String &p_source_file, const St //use an xpm because it's size independent, the editor images are vector and size dependent //it's a simple hack Ref broken = memnew(Image((const char **)atlas_import_failed_xpm)); - ResourceSaver::save(p_save_path + ".tex", ImageTexture::create_from_image(broken)); + ResourceSaver::save(ImageTexture::create_from_image(broken), p_save_path + ".tex"); return OK; } @@ -386,7 +386,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file } String save_path = p_base_paths[E.key] + ".res"; - ResourceSaver::save(save_path, texture); + ResourceSaver::save(texture, save_path); idx++; } diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index 3a47bfb29f60..a1e00f7d3084 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -531,7 +531,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s sample->set_loop_end(loop_end); sample->set_stereo(format_channels == 2); - ResourceSaver::save(p_save_path + ".sample", sample); + ResourceSaver::save(sample, p_save_path + ".sample"); return OK; } diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp index 1c39c425b1de..410f01a9c69e 100644 --- a/editor/import/scene_import_settings.cpp +++ b/editor/import/scene_import_settings.cpp @@ -1184,7 +1184,7 @@ void SceneImportSettings::_save_dir_confirm() { ERR_CONTINUE(!material_map.has(id)); MaterialData &md = material_map[id]; - Error err = ResourceSaver::save(path, md.material); + Error err = ResourceSaver::save(md.material, path); if (err != OK) { EditorNode::get_singleton()->add_io_error(TTR("Can't make material external to file, write error:") + "\n\t" + path); continue; diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index 7061204832b2..6d323572e632 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -81,8 +81,8 @@ void PluginConfigDialog::_on_confirmed() { template_content = templates[0].content; } Ref