summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2017-02-20 20:05:01 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2017-02-20 20:05:01 +0100
commit4e22b6acd7e898182cb488f096ca1ad7191513da (patch)
tree6d6c3c6d9ea67c3579f8d619520dd049acad5ab4 /scene
parent6e2bf31e5a8f3dbe18e31b1aff9c26ee184ad8c8 (diff)
Add more options to Node.duplicate()
to decide whether signals, groups and/or scripts should be set in the copied nodes or not; it's default value makes the method include everything, as usual
Diffstat (limited to 'scene')
-rw-r--r--scene/main/node.cpp34
-rw-r--r--scene/main/node.h12
2 files changed, 32 insertions, 14 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 488256970f..a189702894 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -2288,7 +2288,7 @@ int Node::get_position_in_parent() const {
-Node *Node::_duplicate(bool p_use_instancing) const {
+Node *Node::_duplicate(int p_flags) const {
Node *node=NULL;
@@ -2302,7 +2302,7 @@ Node *Node::_duplicate(bool p_use_instancing) const {
nip->set_instance_path( ip->get_instance_path() );
node=nip;
- } else if (p_use_instancing && get_filename()!=String()) {
+ } else if ((p_flags&DUPLICATE_USE_INSTANCING) && get_filename()!=String()) {
Ref<PackedScene> res = ResourceLoader::load(get_filename());
ERR_FAIL_COND_V(res.is_null(),NULL);
@@ -2335,20 +2335,26 @@ Node *Node::_duplicate(bool p_use_instancing) const {
if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
continue;
String name = E->get().name;
+ if (!(p_flags&DUPLICATE_SCRIPTS) && name=="script/script")
+ continue;
+
node->set( name, get(name) );
}
node->set_name(get_name());
- List<GroupInfo> gi;
- get_groups(&gi);
- for (List<GroupInfo>::Element *E=gi.front();E;E=E->next()) {
+ if (p_flags & DUPLICATE_GROUPS) {
+ List<GroupInfo> gi;
+ get_groups(&gi);
+ for (List<GroupInfo>::Element *E=gi.front();E;E=E->next()) {
- node->add_to_group(E->get().name, E->get().persistent);
+ node->add_to_group(E->get().name, E->get().persistent);
+ }
}
- _duplicate_signals(this, node);
+ if (p_flags & DUPLICATE_SIGNALS)
+ _duplicate_signals(this, node);
for(int i=0;i<get_child_count();i++) {
@@ -2357,7 +2363,7 @@ Node *Node::_duplicate(bool p_use_instancing) const {
if (instanced && get_child(i)->data.owner==this)
continue; //part of instance
- Node *dup = get_child(i)->duplicate(p_use_instancing);
+ Node *dup = get_child(i)->duplicate(p_flags);
if (!dup) {
memdelete(node);
@@ -2371,11 +2377,11 @@ Node *Node::_duplicate(bool p_use_instancing) const {
return node;
}
-Node *Node::duplicate(bool p_use_instancing) const {
+Node *Node::duplicate(int p_flags) const {
- Node* dupe = _duplicate(p_use_instancing);
+ Node* dupe = _duplicate(p_flags);
- if (dupe) {
+ if (dupe && (p_flags&DUPLICATE_SIGNALS)) {
_duplicate_signals(this,dupe);
}
@@ -2968,7 +2974,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tree:SceneTree"),&Node::get_tree);
- ClassDB::bind_method(D_METHOD("duplicate:Node","use_instancing"),&Node::duplicate,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("duplicate:Node","flags"),&Node::duplicate,DEFVAL(DUPLICATE_USE_INSTANCING|DUPLICATE_SIGNALS|DUPLICATE_GROUPS|DUPLICATE_SCRIPTS));
ClassDB::bind_method(D_METHOD("replace_by","node:Node","keep_data"),&Node::replace_by,DEFVAL(false));
ClassDB::bind_method(D_METHOD("set_scene_instance_load_placeholder","load_placeholder"),&Node::set_scene_instance_load_placeholder);
@@ -3058,6 +3064,10 @@ void Node::_bind_methods() {
BIND_CONSTANT( PAUSE_MODE_STOP );
BIND_CONSTANT( PAUSE_MODE_PROCESS );
+ BIND_CONSTANT( DUPLICATE_SIGNALS );
+ BIND_CONSTANT( DUPLICATE_GROUPS );
+ BIND_CONSTANT( DUPLICATE_SCRIPTS );
+
ADD_SIGNAL( MethodInfo("renamed") );
ADD_SIGNAL( MethodInfo("tree_entered") );
ADD_SIGNAL( MethodInfo("tree_exited") );
diff --git a/scene/main/node.h b/scene/main/node.h
index d88db8ecb0..27b21d5e13 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -54,6 +54,14 @@ public:
PAUSE_MODE_PROCESS
};
+ enum DuplicateFlags {
+
+ DUPLICATE_SIGNALS=1,
+ DUPLICATE_GROUPS=2,
+ DUPLICATE_SCRIPTS=4,
+ DUPLICATE_USE_INSTANCING=8
+ };
+
enum NetworkMode {
NETWORK_MODE_INHERIT,
@@ -177,7 +185,7 @@ private:
void _duplicate_signals(const Node* p_original,Node* p_copy) const;
void _duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const;
- Node *_duplicate(bool p_use_instancing) const;
+ Node *_duplicate(int p_flags) const;
Array _get_children() const;
Array _get_groups() const;
@@ -332,7 +340,7 @@ public:
int get_position_in_parent() const;
- Node *duplicate(bool p_use_instancing=false) const;
+ Node *duplicate(int p_flags=DUPLICATE_GROUPS|DUPLICATE_SIGNALS|DUPLICATE_SCRIPTS) const;
Node *duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const;
//Node *clone_tree() const;