Skip to content

Commit

Permalink
Revert what needs to be reverted
Browse files Browse the repository at this point in the history
  • Loading branch information
ajreckof authored and Rindbee committed Apr 10, 2024
1 parent 41f6a68 commit 248e5bf
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 86 deletions.
3 changes: 1 addition & 2 deletions doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,8 @@
<return type="void" />
<param index="0" name="node" type="Node" />
<param index="1" name="keep_groups" type="bool" default="false" />
<param index="2" name="keep_children" type="bool" default="true" />
<description>
Replaces this node by the given [param node]. If [param keep_children] is [code]true[/code] all children of this node are moved to [param node].
Replaces this node by the given [param node]. All children of this node are moved to [param node].
If [param keep_groups] is [code]true[/code], the [param node] is added to the same groups that the replaced node is in (see [method add_to_group]).
[b]Warning:[/b] The replaced node is removed from the tree, but it is [b]not[/b] deleted. To prevent memory leaks, store a reference to the node in a variable, or use [method Object.free].
</description>
Expand Down
4 changes: 1 addition & 3 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3674,9 +3674,7 @@ void EditorNode::set_edited_scene(Node *p_scene) {
if (old_edited_scene_root->get_parent() == scene_root) {
scene_root->remove_child(old_edited_scene_root);
}
if (old_edited_scene_root->is_connected("replacing_by", callable_mp(this, &EditorNode::set_edited_scene))) {
old_edited_scene_root->disconnect(SNAME("replacing_by"), callable_mp(this, &EditorNode::set_edited_scene));
}
old_edited_scene_root->disconnect(SNAME("replacing_by"), callable_mp(this, &EditorNode::set_edited_scene));
}
get_editor_data().set_edited_scene_root(p_scene);

Expand Down
7 changes: 0 additions & 7 deletions misc/extension_api_validation/4.2-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@ Validate extension JSON: Error: Field 'classes/AcceptDialog/methods/remove_butto
Changed argument type to the more specific one actually expected by the method. Compatibility method registered.


GH-89992
--------
Validate extension JSON: Error: Field 'classes/Node/methods/replace_by/arguments': size changed value in new API, from 2 to 3.

Added optional argument to prevent children to be reparented during replace_by. Compatibility method registered.


GH-88047
--------
Validate extension JSON: Error: Field 'classes/AStar2D/methods/get_id_path/arguments': size changed value in new API, from 2 to 3.
Expand Down
41 changes: 0 additions & 41 deletions scene/main/node.compat.inc

This file was deleted.

51 changes: 24 additions & 27 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
/**************************************************************************/

#include "node.h"
#include "node.compat.inc"

#include "core/config/project_settings.h"
#include "core/core_string_names.h"
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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);
}
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);
}
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);
}
for (Node *E : owned_by_owner) {
if (E->data.owner != owner) {
E->set_owner(owner);
}
}

p_node->set_owner(owner);
p_node->set_scene_file_path(get_scene_file_path());
}

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions scene/main/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,6 @@ class Node : public Object {
Variant _call_thread_safe_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);

protected:
#ifndef DISABLE_DEPRECATED
void _replace_by_bind_compat_89992(Node *p_node, bool p_keep_data = false);
static void _bind_compatibility_methods();
#endif // DISABLE_DEPRECATED

void _block() { data.blocked++; }
void _unblock() { data.blocked--; }

Expand Down Expand Up @@ -634,7 +629,7 @@ class Node : public Object {
return binds;
}

void replace_by(Node *p_node, bool p_keep_groups = false, bool p_keep_children = true);
void replace_by(Node *p_node, bool p_keep_data = false);

void set_process_mode(ProcessMode p_mode);
ProcessMode get_process_mode() const;
Expand Down

0 comments on commit 248e5bf

Please sign in to comment.