summaryrefslogtreecommitdiffstats
path: root/editor/import_dock.cpp
diff options
context:
space:
mode:
authorSaracenOne <SaracenOne@gmail.com>2022-09-09 19:39:37 +0100
committerSaracen <SaracenOne@gmail.com>2024-09-16 15:11:40 +0100
commitf44bce2ee0774bef4aadffe556ce2016cdc38be9 (patch)
tree03e34ed75b68e70cdfd1ebf037daaf3648cc8845 /editor/import_dock.cpp
parent6681f2563b99e14929a8acb27f4908fece398ef1 (diff)
downloadredot-engine-f44bce2ee0774bef4aadffe556ce2016cdc38be9.tar.gz
Add support for resource conversion plugins in filesystem dock.
Diffstat (limited to 'editor/import_dock.cpp')
-rw-r--r--editor/import_dock.cpp55
1 files changed, 13 insertions, 42 deletions
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<Ref<Resource>> external_resources;
ResourceCache::get_cached_resources(&external_resources);
+ Vector<Ref<Resource>> old_resources_to_replace;
+ Vector<Ref<Resource>> new_resources_to_replace;
for (const String &path : need_cleanup) {
Ref<Resource> old_res = old_resources[path];
- Ref<Resource> 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<Resource> 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<Resource> 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<Resource> 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<Resource> &old_resource, const Ref<Resource> &new_resource) {
- ERR_FAIL_NULL(p_object);
-
- List<PropertyInfo> 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<Resource> 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<Node>(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: {