summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorMax Hilbrunner <mhilbrunner@users.noreply.github.com>2018-09-22 17:15:38 +0200
committerGitHub <noreply@github.com>2018-09-22 17:15:38 +0200
commitd878c828b5094b4cef845889055d429b207bd070 (patch)
tree0b51bc730b118f0c1f6b1e6d9fd136402ed36915 /scene
parenta4c2890a7b7e27bf2c4a662aef582473029d4762 (diff)
parent0fdbf6b2ef833afa929881f7281ea801ef4d6b8b (diff)
Merge pull request #22115 from akerudesu/find-parent
Added find_parent method to node class
Diffstat (limited to 'scene')
-rw-r--r--scene/main/node.cpp14
-rw-r--r--scene/main/node.h2
2 files changed, 16 insertions, 0 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 06bc12d774..d3282c6ada 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -1348,6 +1348,19 @@ Node *Node::get_parent() const {
return data.parent;
}
+Node *Node::find_parent(const String &p_mask) const {
+
+ Node *p = data.parent;
+ while (p) {
+
+ if (p->data.name.operator String().match(p_mask))
+ return p;
+ p = p->data.parent;
+ }
+
+ return NULL;
+}
+
bool Node::is_a_parent_of(const Node *p_node) const {
ERR_FAIL_NULL_V(p_node, false);
@@ -2629,6 +2642,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_node", "path"), &Node::get_node);
ClassDB::bind_method(D_METHOD("get_parent"), &Node::get_parent);
ClassDB::bind_method(D_METHOD("find_node", "mask", "recursive", "owned"), &Node::find_node, DEFVAL(true), DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("find_parent", "mask"), &Node::find_parent);
ClassDB::bind_method(D_METHOD("has_node_and_resource", "path"), &Node::has_node_and_resource);
ClassDB::bind_method(D_METHOD("get_node_and_resource", "path"), &Node::_get_node_and_resource);
diff --git a/scene/main/node.h b/scene/main/node.h
index 8d6c558e93..a7baebc9c2 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -257,6 +257,8 @@ public:
Node *get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property = true) const;
Node *get_parent() const;
+ Node *find_parent(const String &p_mask) const;
+
_FORCE_INLINE_ SceneTree *get_tree() const {
ERR_FAIL_COND_V(!data.tree, NULL);
return data.tree;