1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Add support for resource conversion plugins in filesystem dock.

This commit is contained in:
SaracenOne
2022-09-09 19:39:37 +01:00
committed by Saracen
parent 6681f2563b
commit f44bce2ee0
7 changed files with 324 additions and 58 deletions

View File

@@ -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: {