Revert what needs to be reverted

This commit is contained in:
ajreckof
2024-04-09 18:07:07 +02:00
committed by 风青山
parent 41f6a683b6
commit 248e5bfba2
6 changed files with 30 additions and 89 deletions

View File

@@ -29,7 +29,6 @@
/**************************************************************************/
#include "node.h"
#include "node.compat.inc"
#include "core/config/project_settings.h"
#include "core/core_string_names.h"
@@ -3006,7 +3005,7 @@ static void find_owned_by(Node *p_by, Node *p_node, List<Node *> *p_owned) {
}
}
void Node::replace_by(Node *p_node, bool p_keep_groups, bool p_keep_children) {
void Node::replace_by(Node *p_node, bool p_keep_groups) {
ERR_THREAD_GUARD
ERR_FAIL_NULL(p_node);
ERR_FAIL_COND(p_node->data.parent);
@@ -3027,13 +3026,13 @@ void Node::replace_by(Node *p_node, bool p_keep_groups, bool p_keep_children) {
_replace_connections_target(p_node);
if (data.owner) {
if (p_keep_children) {
for (int i = 0; i < get_child_count(); i++) {
find_owned_by(data.owner, get_child(i), &owned_by_owner);
}
for (int i = 0; i < get_child_count(); i++) {
find_owned_by(data.owner, get_child(i), &owned_by_owner);
}
_clean_up_owner();
}
Node *parent = data.parent;
int index_in_parent = get_index(false);
@@ -3045,33 +3044,31 @@ void Node::replace_by(Node *p_node, bool p_keep_groups, bool p_keep_children) {
emit_signal(SNAME("replacing_by"), p_node);
if (p_keep_children) {
while (get_child_count()) {
Node *child = get_child(0);
remove_child(child);
if (!child->is_owned_by_parent()) {
// add the custom children to the p_node
Node *child_owner = child->get_owner() == this ? p_node : child->get_owner();
child->set_owner(nullptr);
p_node->add_child(child);
child->set_owner(child_owner);
}
}
for (Node *E : owned) {
if (E->data.owner != p_node) {
E->set_owner(p_node);
}
}
for (Node *E : owned_by_owner) {
if (E->data.owner != owner) {
E->set_owner(owner);
}
while (get_child_count()) {
Node *child = get_child(0);
remove_child(child);
if (!child->is_owned_by_parent()) {
// add the custom children to the p_node
Node *child_owner = child->get_owner() == this ? p_node : child->get_owner();
child->set_owner(nullptr);
p_node->add_child(child);
child->set_owner(child_owner);
}
}
p_node->set_owner(owner);
for (Node *E : owned) {
if (E->data.owner != p_node) {
E->set_owner(p_node);
}
}
for (Node *E : owned_by_owner) {
if (E->data.owner != owner) {
E->set_owner(owner);
}
}
p_node->set_scene_file_path(get_scene_file_path());
}
@@ -3598,7 +3595,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("create_tween"), &Node::create_tween);
ClassDB::bind_method(D_METHOD("duplicate", "flags"), &Node::duplicate, DEFVAL(DUPLICATE_USE_INSTANTIATION | DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS));
ClassDB::bind_method(D_METHOD("replace_by", "node", "keep_groups", "keep_children"), &Node::replace_by, DEFVAL(false), DEFVAL(true));
ClassDB::bind_method(D_METHOD("replace_by", "node", "keep_groups"), &Node::replace_by, DEFVAL(false));
ClassDB::bind_method(D_METHOD("set_scene_instance_load_placeholder", "load_placeholder"), &Node::set_scene_instance_load_placeholder);
ClassDB::bind_method(D_METHOD("get_scene_instance_load_placeholder"), &Node::get_scene_instance_load_placeholder);