|
10 | 10 | */
|
11 | 11 |
|
12 | 12 | #include "blackboard.h"
|
| 13 | +#include "../util/limbo_compat.h" |
13 | 14 |
|
14 | 15 | #ifdef LIMBOAI_MODULE
|
15 | 16 | #include "core/variant/variant.h"
|
@@ -75,6 +76,26 @@ TypedArray<StringName> Blackboard::list_vars() const {
|
75 | 76 | return var_names;
|
76 | 77 | }
|
77 | 78 |
|
| 79 | +void Blackboard::print_state() const { |
| 80 | + Ref<Blackboard> bb{ this }; |
| 81 | + int scope_idx = 0; |
| 82 | + while (bb.is_valid()) { |
| 83 | + int i = 0; |
| 84 | + String line = "Scope " + itos(scope_idx) + ": { "; |
| 85 | + for (const KeyValue<StringName, BBVariable> &kv : bb->data) { |
| 86 | + if (i > 0) { |
| 87 | + line += ", "; |
| 88 | + } |
| 89 | + line += String(kv.key) + ": " + String(kv.value.get_value()); |
| 90 | + i++; |
| 91 | + } |
| 92 | + line += " }"; |
| 93 | + PRINT_LINE(line); |
| 94 | + bb = bb->get_parent(); |
| 95 | + scope_idx++; |
| 96 | + } |
| 97 | +} |
| 98 | + |
78 | 99 | Dictionary Blackboard::get_vars_as_dict() const {
|
79 | 100 | Dictionary dict;
|
80 | 101 | for (const KeyValue<StringName, BBVariable> &kv : data) {
|
@@ -136,6 +157,7 @@ void Blackboard::_bind_methods() {
|
136 | 157 | ClassDB::bind_method(D_METHOD("erase_var", "var_name"), &Blackboard::erase_var);
|
137 | 158 | ClassDB::bind_method(D_METHOD("clear"), &Blackboard::clear);
|
138 | 159 | ClassDB::bind_method(D_METHOD("list_vars"), &Blackboard::list_vars);
|
| 160 | + ClassDB::bind_method(D_METHOD("print_state"), &Blackboard::print_state); |
139 | 161 | ClassDB::bind_method(D_METHOD("get_vars_as_dict"), &Blackboard::get_vars_as_dict);
|
140 | 162 | ClassDB::bind_method(D_METHOD("populate_from_dict", "dictionary"), &Blackboard::populate_from_dict);
|
141 | 163 | ClassDB::bind_method(D_METHOD("top"), &Blackboard::top);
|
|
0 commit comments