Blackboard: Add erase_var()

This commit is contained in:
Serhii Snitsaruk 2022-12-16 12:13:03 +01:00
parent 6ae7ea8e40
commit fa098fec09
2 changed files with 7 additions and 0 deletions

View File

@ -31,6 +31,10 @@ bool Blackboard::has_var(const Variant &p_key) const {
return data.has(p_key) || (parent.is_valid() && parent->has_var(p_key));
}
void Blackboard::erase_var(const Variant &p_key) {
data.erase(p_key);
}
void Blackboard::prefetch_nodepath_vars(Node *p_node) {
ERR_FAIL_COND(p_node == nullptr);
for (int i = 0; i < data.size(); i++) {
@ -52,6 +56,7 @@ void Blackboard::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_var", "p_key"), &Blackboard::has_var);
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("erase_var"), &Blackboard::erase_var);
ClassDB::bind_method(D_METHOD("prefetch_nodepath_vars", "p_node"), &Blackboard::prefetch_nodepath_vars);
ClassDB::bind_method(D_METHOD("top"), &Blackboard::top);
}

View File

@ -31,6 +31,8 @@ public:
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;
void erase_var(const Variant &p_key);
void prefetch_nodepath_vars(Node *p_node);
};