1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-21 14:57:09 +00:00

Merge pull request #12129 from willnationsdev/duplicate-fix

Node.duplicate(): instanced node's descendants' props = original's runtime values.
This commit is contained in:
Rémi Verschelde
2017-11-22 15:42:31 +01:00
committed by GitHub

36
scene/main/node.cpp Executable file → Normal file
View File

@@ -2104,20 +2104,41 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
ERR_FAIL_COND_V(!node, NULL); ERR_FAIL_COND_V(!node, NULL);
} }
List<PropertyInfo> plist; if (get_filename() != "") { //an instance
node->set_filename(get_filename());
get_property_list(&plist); }
StringName script_property_name = CoreStringNames::get_singleton()->_script; StringName script_property_name = CoreStringNames::get_singleton()->_script;
List<const Node *> node_tree;
node_tree.push_front(this);
if (instanced) {
for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) {
for (int i = 0; i < N->get()->get_child_count(); ++i) {
node_tree.push_back(N->get()->get_child(i));
}
}
}
for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) {
Node *current_node = node->get_node(get_path_to(N->get()));
if (p_flags & DUPLICATE_SCRIPTS) { if (p_flags & DUPLICATE_SCRIPTS) {
bool is_valid = false; bool is_valid = false;
Variant script = get(script_property_name, &is_valid); Variant script = N->get()->get(script_property_name, &is_valid);
if (is_valid) { if (is_valid) {
node->set(script_property_name, script); current_node->set(script_property_name, script);
} }
} }
List<PropertyInfo> plist;
N->get()->get_property_list(&plist);
if (!current_node)
continue;
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
@@ -2126,7 +2147,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
if (name == script_property_name) if (name == script_property_name)
continue; continue;
Variant value = get(name); Variant value = N->get()->get(name);
// Duplicate dictionaries and arrays, mainly needed for __meta__ // Duplicate dictionaries and arrays, mainly needed for __meta__
if (value.get_type() == Variant::DICTIONARY) { if (value.get_type() == Variant::DICTIONARY) {
value = Dictionary(value).copy(); value = Dictionary(value).copy();
@@ -2134,7 +2155,8 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
value = Array(value).duplicate(); value = Array(value).duplicate();
} }
node->set(name, value); current_node->set(name, value);
}
} }
node->set_name(get_name()); node->set_name(get_name());