Add Blackboard::top()
This commit is contained in:
parent
fe2cf00c6c
commit
3f01c26719
|
@ -6,6 +6,14 @@
|
||||||
#include "scene/main/node.h"
|
#include "scene/main/node.h"
|
||||||
#include <cstddef>
|
#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 {
|
Variant Blackboard::get_var(const Variant &p_key, const Variant &p_default) const {
|
||||||
if (data.has(p_key)) {
|
if (data.has(p_key)) {
|
||||||
return data.get_valid(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("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("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("prefetch_nodepath_vars", "p_node"), &Blackboard::prefetch_nodepath_vars);
|
||||||
|
ClassDB::bind_method(D_METHOD("top"), &Blackboard::top);
|
||||||
}
|
}
|
|
@ -25,6 +25,8 @@ public:
|
||||||
void set_parent_scope(const Ref<Blackboard> &p_blackboard) { parent = p_blackboard; }
|
void set_parent_scope(const Ref<Blackboard> &p_blackboard) { parent = p_blackboard; }
|
||||||
Ref<Blackboard> get_parent_scope() const { return parent; }
|
Ref<Blackboard> get_parent_scope() const { return parent; }
|
||||||
|
|
||||||
|
Ref<Blackboard> top() const;
|
||||||
|
|
||||||
Variant get_var(const Variant &p_key, const Variant &p_default) const;
|
Variant get_var(const Variant &p_key, const Variant &p_default) const;
|
||||||
void set_var(const Variant &p_key, const Variant &p_value);
|
void set_var(const Variant &p_key, const Variant &p_value);
|
||||||
bool has_var(const Variant &p_key) const;
|
bool has_var(const Variant &p_key) const;
|
||||||
|
|
Loading…
Reference in New Issue