From f44bce2ee0774bef4aadffe556ce2016cdc38be9 Mon Sep 17 00:00:00 2001 From: SaracenOne Date: Fri, 9 Sep 2022 19:39:37 +0100 Subject: Add support for resource conversion plugins in filesystem dock. --- editor/import_dock.cpp | 55 ++++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 42 deletions(-) (limited to 'editor/import_dock.cpp') diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index 16f4aeda95..14065abf73 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -606,23 +606,25 @@ void ImportDock::_reimport_and_cleanup() { List> external_resources; ResourceCache::get_cached_resources(&external_resources); + Vector> old_resources_to_replace; + Vector> new_resources_to_replace; for (const String &path : need_cleanup) { Ref old_res = old_resources[path]; - Ref new_res; if (params->importer.is_valid()) { - new_res = ResourceLoader::load(path); - } - - for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) { - Node *edited_scene_root = EditorNode::get_editor_data().get_edited_scene_root(i); - if (likely(edited_scene_root)) { - _replace_resource_in_object(edited_scene_root, old_res, new_res); + Ref new_res = ResourceLoader::load(path); + if (new_res.is_valid()) { + old_resources_to_replace.append(old_res); + new_resources_to_replace.append(new_res); } } - for (Ref res : external_resources) { - _replace_resource_in_object(res.ptr(), old_res, new_res); - } } + + EditorNode::get_singleton()->replace_resources_in_scenes(old_resources_to_replace, new_resources_to_replace); + + for (Ref res : external_resources) { + EditorNode::get_singleton()->replace_resources_in_object(res.ptr(), old_resources_to_replace, new_resources_to_replace); + } + need_cleanup.clear(); } @@ -693,37 +695,6 @@ void ImportDock::_reimport() { _set_dirty(false); } -void ImportDock::_replace_resource_in_object(Object *p_object, const Ref &old_resource, const Ref &new_resource) { - ERR_FAIL_NULL(p_object); - - List props; - p_object->get_property_list(&props); - - for (const PropertyInfo &p : props) { - if (p.type != Variant::OBJECT || p.hint != PROPERTY_HINT_RESOURCE_TYPE) { - continue; - } - - Ref res = p_object->get(p.name); - if (res.is_null()) { - continue; - } - - if (res == old_resource) { - p_object->set(p.name, new_resource); - } else { - _replace_resource_in_object(res.ptr(), old_resource, new_resource); - } - } - - Node *n = Object::cast_to(p_object); - if (n) { - for (int i = 0; i < n->get_child_count(); i++) { - _replace_resource_in_object(n->get_child(i), old_resource, new_resource); - } - } -} - void ImportDock::_notification(int p_what) { switch (p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { -- cgit v1.2.3