summaryrefslogtreecommitdiff
path: root/scene/main/node.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-06-08 00:33:10 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-06-08 00:33:10 -0300
commitf0521539831c2d3230e537a4efc0b485b8f64f49 (patch)
tree90fe0784e4f85746a16defebe35b91f6c1a31c3c /scene/main/node.cpp
parent798b55df3027843b942af2b76d4a879331e46898 (diff)
Added Node.find_node(mask) function
by popular request
Diffstat (limited to 'scene/main/node.cpp')
-rw-r--r--scene/main/node.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 5c60b9fbff..ab530866bb 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -840,6 +840,28 @@ bool Node::has_node(const NodePath& p_path) const {
return _get_node(p_path)!=NULL;
}
+
+Node* Node::find_node(const String& p_mask,bool p_recursive,bool p_owned) const {
+
+ Node * const*cptr = data.children.ptr();
+ int ccount = data.children.size();
+ for(int i=0;i<ccount;i++) {
+ if (p_owned && !cptr[i]->data.owner)
+ continue;
+ if (cptr[i]->data.name.operator String().match(p_mask))
+ return cptr[i];
+
+ if (!p_recursive)
+ continue;
+
+ Node* ret = cptr[i]->find_node(p_mask,true,p_owned);
+ if (ret)
+ return ret;
+ }
+ return NULL;
+
+}
+
Node *Node::get_parent() const {
return data.parent;
@@ -1807,6 +1829,7 @@ void Node::_bind_methods() {
ObjectTypeDB::bind_method(_MD("has_node","path"),&Node::has_node);
ObjectTypeDB::bind_method(_MD("get_node:Node","path"),&Node::get_node);
ObjectTypeDB::bind_method(_MD("get_parent:Parent"),&Node::get_parent);
+ ObjectTypeDB::bind_method(_MD("find_node:Node","mask","recursive","owned"),&Node::get_node,DEFVAL(true),DEFVAL(true));
ObjectTypeDB::bind_method(_MD("has_node_and_resource","path"),&Node::has_node_and_resource);
ObjectTypeDB::bind_method(_MD("get_node_and_resource","path"),&Node::_get_node_and_resource);