Add Blackboard::top()

This commit is contained in:
Serhii Snitsaruk 2022-11-23 18:02:46 +01:00
parent fe2cf00c6c
commit 3f01c26719
2 changed files with 11 additions and 0 deletions

View File

@ -6,6 +6,14 @@
#include "scene/main/node.h"
#include <cstddef>
Ref<Blackboard> Blackboard::top() const {
Ref<Blackboard> bb(this);
while (bb->get_parent_scope().is_valid()) {
bb = bb->get_parent_scope();
}
return bb;
}
Variant Blackboard::get_var(const Variant &p_key, const Variant &p_default) const {
if (data.has(p_key)) {
return data.get_valid(p_key);
@ -46,4 +54,5 @@ void Blackboard::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_parent_scope", "p_blackboard"), &Blackboard::set_parent_scope);
ClassDB::bind_method(D_METHOD("get_parent_scope"), &Blackboard::get_parent_scope);
ClassDB::bind_method(D_METHOD("prefetch_nodepath_vars", "p_node"), &Blackboard::prefetch_nodepath_vars);
ClassDB::bind_method(D_METHOD("top"), &Blackboard::top);
}

View File

@ -25,6 +25,8 @@ public:
void set_parent_scope(const Ref<Blackboard> &p_blackboard) { parent = p_blackboard; }
Ref<Blackboard> get_parent_scope() const { return parent; }
Ref<Blackboard> top() const;
Variant get_var(const Variant &p_key, const Variant &p_default) const;
void set_var(const Variant &p_key, const Variant &p_value);
bool has_var(const Variant &p_key) const;