MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / replace_by

Method replace_by

scene/main/node.cpp:3215–3280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3213}
3214
3215void Node::replace_by(Node *p_node, bool p_keep_groups) {
3216 ERR_THREAD_GUARD
3217 ERR_FAIL_NULL(p_node);
3218 ERR_FAIL_COND(p_node->data.parent);
3219
3220 List<Node *> owned = data.owned;
3221 List<Node *> owned_by_owner;
3222 Node *owner = (data.owner == this) ? p_node : data.owner;
3223
3224 if (p_keep_groups) {
3225 List<GroupInfo> groups;
3226 get_groups(&groups);
3227
3228 for (const GroupInfo &E : groups) {
3229 p_node->add_to_group(E.name, E.persistent);
3230 }
3231 }
3232
3233 _replace_connections_target(p_node);
3234
3235 if (data.owner) {
3236 for (int i = 0; i < get_child_count(); i++) {
3237 find_owned_by(data.owner, get_child(i), &owned_by_owner);
3238 }
3239
3240 _clean_up_owner();
3241 }
3242
3243 Node *parent = data.parent;
3244 int index_in_parent = get_index(false);
3245
3246 if (data.parent) {
3247 parent->remove_child(this);
3248 parent->add_child(p_node);
3249 parent->move_child(p_node, index_in_parent);
3250 }
3251
3252 emit_signal(SNAME("replacing_by"), p_node);
3253
3254 while (get_child_count()) {
3255 Node *child = get_child(0);
3256 remove_child(child);
3257 if (!child->is_internal()) {
3258 // Add the custom children to the p_node.
3259 Node *child_owner = child->get_owner() == this ? p_node : child->get_owner();
3260 child->set_owner(nullptr);
3261 p_node->add_child(child);
3262 child->set_owner(child_owner);
3263 }
3264 }
3265
3266 p_node->set_owner(owner);
3267 for (Node *E : owned) {
3268 if (E->data.owner != p_node) {
3269 E->set_owner(p_node);
3270 }
3271 }
3272

Callers 11

_fill_sceneMethod · 0.80
_pre_fix_nodeMethod · 0.80
_post_fix_nodeMethod · 0.80
_generate_meshesMethod · 0.80
import_sceneMethod · 0.80
_replace_nodeMethod · 0.80
test_node.hFile · 0.80

Calls 9

find_owned_byFunction · 0.85
move_childMethod · 0.80
set_ownerMethod · 0.80
set_scene_file_pathMethod · 0.80
add_to_groupMethod · 0.45
remove_childMethod · 0.45
add_childMethod · 0.45
is_internalMethod · 0.45
get_ownerMethod · 0.45

Tested by

no test coverage detected