Add `Blackboard.print_state()` (#264)
Method that prints values of all variables in each scope.
This commit is contained in:
parent
0982804a86
commit
a952009293
|
@ -10,6 +10,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "blackboard.h"
|
#include "blackboard.h"
|
||||||
|
#include "../util/limbo_compat.h"
|
||||||
|
|
||||||
#ifdef LIMBOAI_MODULE
|
#ifdef LIMBOAI_MODULE
|
||||||
#include "core/variant/variant.h"
|
#include "core/variant/variant.h"
|
||||||
|
@ -75,6 +76,26 @@ TypedArray<StringName> Blackboard::list_vars() const {
|
||||||
return var_names;
|
return var_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Blackboard::print_state() const {
|
||||||
|
Ref<Blackboard> bb{ this };
|
||||||
|
int scope_idx = 0;
|
||||||
|
while (bb.is_valid()) {
|
||||||
|
int i = 0;
|
||||||
|
String line = "Scope " + itos(scope_idx) + ": { ";
|
||||||
|
for (const KeyValue<StringName, BBVariable> &kv : bb->data) {
|
||||||
|
if (i > 0) {
|
||||||
|
line += ", ";
|
||||||
|
}
|
||||||
|
line += String(kv.key) + ": " + String(kv.value.get_value());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
line += " }";
|
||||||
|
PRINT_LINE(line);
|
||||||
|
bb = bb->get_parent();
|
||||||
|
scope_idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Dictionary Blackboard::get_vars_as_dict() const {
|
Dictionary Blackboard::get_vars_as_dict() const {
|
||||||
Dictionary dict;
|
Dictionary dict;
|
||||||
for (const KeyValue<StringName, BBVariable> &kv : data) {
|
for (const KeyValue<StringName, BBVariable> &kv : data) {
|
||||||
|
@ -136,6 +157,7 @@ void Blackboard::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("erase_var", "var_name"), &Blackboard::erase_var);
|
ClassDB::bind_method(D_METHOD("erase_var", "var_name"), &Blackboard::erase_var);
|
||||||
ClassDB::bind_method(D_METHOD("clear"), &Blackboard::clear);
|
ClassDB::bind_method(D_METHOD("clear"), &Blackboard::clear);
|
||||||
ClassDB::bind_method(D_METHOD("list_vars"), &Blackboard::list_vars);
|
ClassDB::bind_method(D_METHOD("list_vars"), &Blackboard::list_vars);
|
||||||
|
ClassDB::bind_method(D_METHOD("print_state"), &Blackboard::print_state);
|
||||||
ClassDB::bind_method(D_METHOD("get_vars_as_dict"), &Blackboard::get_vars_as_dict);
|
ClassDB::bind_method(D_METHOD("get_vars_as_dict"), &Blackboard::get_vars_as_dict);
|
||||||
ClassDB::bind_method(D_METHOD("populate_from_dict", "dictionary"), &Blackboard::populate_from_dict);
|
ClassDB::bind_method(D_METHOD("populate_from_dict", "dictionary"), &Blackboard::populate_from_dict);
|
||||||
ClassDB::bind_method(D_METHOD("top"), &Blackboard::top);
|
ClassDB::bind_method(D_METHOD("top"), &Blackboard::top);
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
void erase_var(const StringName &p_name);
|
void erase_var(const StringName &p_name);
|
||||||
void clear() { data.clear(); }
|
void clear() { data.clear(); }
|
||||||
TypedArray<StringName> list_vars() const;
|
TypedArray<StringName> list_vars() const;
|
||||||
|
void print_state() const;
|
||||||
|
|
||||||
Dictionary get_vars_as_dict() const;
|
Dictionary get_vars_as_dict() const;
|
||||||
void populate_from_dict(const Dictionary &p_dictionary);
|
void populate_from_dict(const Dictionary &p_dictionary);
|
||||||
|
|
|
@ -86,6 +86,12 @@
|
||||||
Fills the Blackboard with multiple variables from a dictionary. The dictionary keys must be variable names and the dictionary values must be variable values. Keys must be StringName or String.
|
Fills the Blackboard with multiple variables from a dictionary. The dictionary keys must be variable names and the dictionary values must be variable values. Keys must be StringName or String.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="print_state" qualifiers="const">
|
||||||
|
<return type="void" />
|
||||||
|
<description>
|
||||||
|
Prints the values of all variables in each scope.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="set_parent">
|
<method name="set_parent">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<param index="0" name="blackboard" type="Blackboard" />
|
<param index="0" name="blackboard" type="Blackboard" />
|
||||||
|
|
Loading…
Reference in New Issue