Compare commits

..

No commits in common. "56bb91df0a8d03965b8fd278530789e70cbfffce" and "49f5e3be79133304f3fb83f7f0d7764fe7697c2e" have entirely different histories.

12 changed files with 25 additions and 333 deletions

1
SCsub
View File

@ -8,7 +8,6 @@ module_env = env.Clone()
module_env.Append(CPPDEFINES=["LIMBOAI_MODULE"]) module_env.Append(CPPDEFINES=["LIMBOAI_MODULE"])
import limboai_version import limboai_version
limboai_version.generate_module_version_header() limboai_version.generate_module_version_header()
module_env.add_source_files(env.modules_sources, "*.cpp") module_env.add_source_files(env.modules_sources, "*.cpp")

View File

@ -64,36 +64,6 @@ void Blackboard::erase_var(const StringName &p_name) {
data.erase(p_name); data.erase(p_name);
} }
TypedArray<StringName> Blackboard::list_vars() const {
TypedArray<StringName> var_names;
var_names.resize(data.size());
int idx = 0;
for (const KeyValue<StringName, BBVariable> &kv : data) {
var_names[idx] = kv.key;
idx += 1;
}
return var_names;
}
Dictionary Blackboard::get_vars_as_dict() const {
Dictionary dict;
for (const KeyValue<StringName, BBVariable> &kv : data) {
dict[kv.key] = kv.value.get_value();
}
return dict;
}
void Blackboard::populate_from_dict(const Dictionary &p_dictionary) {
Array keys = p_dictionary.keys();
for (int i = 0; i < keys.size(); i++) {
if (keys[i].get_type() == Variant::STRING_NAME || keys[i].get_type() == Variant::STRING) {
set_var(keys[i], p_dictionary[keys[i]]);
} else {
ERR_PRINT("Blackboard: Invalid key type in dictionary to populate blackboard. Must be StringName or String.");
}
}
}
void Blackboard::bind_var_to_property(const StringName &p_name, Object *p_object, const StringName &p_property, bool p_create) { void Blackboard::bind_var_to_property(const StringName &p_name, Object *p_object, const StringName &p_property, bool p_create) {
if (!data.has(p_name)) { if (!data.has(p_name)) {
if (p_create) { if (p_create) {
@ -106,7 +76,7 @@ void Blackboard::bind_var_to_property(const StringName &p_name, Object *p_object
} }
void Blackboard::unbind_var(const StringName &p_name) { void Blackboard::unbind_var(const StringName &p_name) {
ERR_FAIL_COND_MSG(!data.has(p_name), "Blackboard: Can't unbind variable that doesn't exist (var: " + p_name + ")."); ERR_FAIL_COND_MSG(data.has(p_name), "Blackboard: Can't unbind variable that doesn't exist (var: " + p_name + ").");
data[p_name].unbind(); data[p_name].unbind();
} }
@ -128,16 +98,12 @@ void Blackboard::link_var(const StringName &p_name, const Ref<Blackboard> &p_tar
} }
void Blackboard::_bind_methods() { void Blackboard::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_var", "var_name", "default", "complain"), &Blackboard::get_var, DEFVAL(Variant()), DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_var", "var_name", "default", "complain"), &Blackboard::get_var, Variant(), true);
ClassDB::bind_method(D_METHOD("set_var", "var_name", "value"), &Blackboard::set_var); ClassDB::bind_method(D_METHOD("set_var", "var_name", "value"), &Blackboard::set_var);
ClassDB::bind_method(D_METHOD("has_var", "var_name"), &Blackboard::has_var); ClassDB::bind_method(D_METHOD("has_var", "var_name"), &Blackboard::has_var);
ClassDB::bind_method(D_METHOD("set_parent", "blackboard"), &Blackboard::set_parent); ClassDB::bind_method(D_METHOD("set_parent", "blackboard"), &Blackboard::set_parent);
ClassDB::bind_method(D_METHOD("get_parent"), &Blackboard::get_parent); ClassDB::bind_method(D_METHOD("get_parent"), &Blackboard::get_parent);
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("list_vars"), &Blackboard::list_vars);
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("top"), &Blackboard::top); ClassDB::bind_method(D_METHOD("top"), &Blackboard::top);
ClassDB::bind_method(D_METHOD("bind_var_to_property", "var_name", "object", "property", "create"), &Blackboard::bind_var_to_property, DEFVAL(false)); ClassDB::bind_method(D_METHOD("bind_var_to_property", "var_name", "object", "property", "create"), &Blackboard::bind_var_to_property, DEFVAL(false));
ClassDB::bind_method(D_METHOD("unbind_var", "var_name"), &Blackboard::unbind_var); ClassDB::bind_method(D_METHOD("unbind_var", "var_name"), &Blackboard::unbind_var);

View File

@ -46,15 +46,10 @@ public:
Ref<Blackboard> top() const; Ref<Blackboard> top() const;
Variant get_var(const StringName &p_name, const Variant &p_default = Variant(), bool p_complain = true) const; Variant get_var(const StringName &p_name, const Variant &p_default, bool p_complain = true) const;
void set_var(const StringName &p_name, const Variant &p_value); void set_var(const StringName &p_name, const Variant &p_value);
bool has_var(const StringName &p_name) const; bool has_var(const StringName &p_name) const;
void erase_var(const StringName &p_name); void erase_var(const StringName &p_name);
void clear() { data.clear(); }
TypedArray<StringName> list_vars() const;
Dictionary get_vars_as_dict() const;
void populate_from_dict(const Dictionary &p_dictionary);
void bind_var_to_property(const StringName &p_name, Object *p_object, const StringName &p_property, bool p_create = false); void bind_var_to_property(const StringName &p_name, Object *p_object, const StringName &p_property, bool p_create = false);
void unbind_var(const StringName &p_name); void unbind_var(const StringName &p_name);
@ -62,6 +57,8 @@ public:
void assign_var(const StringName &p_name, const BBVariable &p_var); void assign_var(const StringName &p_name, const BBVariable &p_var);
void link_var(const StringName &p_name, const Ref<Blackboard> &p_target_blackboard, const StringName &p_target_var, bool p_create = false); void link_var(const StringName &p_name, const Ref<Blackboard> &p_target_blackboard, const StringName &p_target_var, bool p_create = false);
// TODO: Add serialization API.
}; };
#endif // BLACKBOARD_H #endif // BLACKBOARD_H

View File

@ -240,8 +240,8 @@ Pair<StringName, BBVariable> BlackboardPlan::get_var_by_index(int p_index) {
return var_list[p_index]; return var_list[p_index];
} }
TypedArray<StringName> BlackboardPlan::list_vars() const { PackedStringArray BlackboardPlan::list_vars() const {
TypedArray<StringName> ret; PackedStringArray ret;
for (const Pair<StringName, BBVariable> &p : var_list) { for (const Pair<StringName, BBVariable> &p : var_list) {
ret.append(p.first); ret.append(p.first);
} }

View File

@ -76,7 +76,7 @@ public:
_FORCE_INLINE_ bool is_empty() const { return var_map.is_empty(); } _FORCE_INLINE_ bool is_empty() const { return var_map.is_empty(); }
int get_var_count() const { return var_map.size(); } int get_var_count() const { return var_map.size(); }
TypedArray<StringName> list_vars() const; PackedStringArray list_vars() const;
StringName get_var_name(const BBVariable &p_var) const; StringName get_var_name(const BBVariable &p_var) const;
bool is_valid_var_name(const StringName &p_name) const; bool is_valid_var_name(const StringName &p_name) const;
void rename_var(const StringName &p_name, const StringName &p_new_name); void rename_var(const StringName &p_name, const StringName &p_new_name);

View File

@ -36,24 +36,16 @@ Methods
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`bind_var_to_property<class_Blackboard_method_bind_var_to_property>` **(** StringName var_name, Object object, StringName property, bool create=false **)** | | void | :ref:`bind_var_to_property<class_Blackboard_method_bind_var_to_property>` **(** StringName var_name, Object object, StringName property, bool create=false **)** |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`clear<class_Blackboard_method_clear>` **(** **)** |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`erase_var<class_Blackboard_method_erase_var>` **(** StringName var_name **)** | | void | :ref:`erase_var<class_Blackboard_method_erase_var>` **(** StringName var_name **)** |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Blackboard<class_Blackboard>` | :ref:`get_parent<class_Blackboard_method_get_parent>` **(** **)** |const| | | :ref:`Blackboard<class_Blackboard>` | :ref:`get_parent<class_Blackboard_method_get_parent>` **(** **)** |const| |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Variant | :ref:`get_var<class_Blackboard_method_get_var>` **(** StringName var_name, Variant default=null, bool complain=true **)** |const| | | Variant | :ref:`get_var<class_Blackboard_method_get_var>` **(** StringName var_name, Variant default=null, bool complain=true **)** |const| |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Dictionary | :ref:`get_vars_as_dict<class_Blackboard_method_get_vars_as_dict>` **(** **)** |const| |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| bool | :ref:`has_var<class_Blackboard_method_has_var>` **(** StringName var_name **)** |const| | | bool | :ref:`has_var<class_Blackboard_method_has_var>` **(** StringName var_name **)** |const| |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`link_var<class_Blackboard_method_link_var>` **(** StringName var_name, :ref:`Blackboard<class_Blackboard>` target_blackboard, StringName target_var, bool create=false **)** | | void | :ref:`link_var<class_Blackboard_method_link_var>` **(** StringName var_name, :ref:`Blackboard<class_Blackboard>` target_blackboard, StringName target_var, bool create=false **)** |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| StringName[] | :ref:`list_vars<class_Blackboard_method_list_vars>` **(** **)** |const| |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`populate_from_dict<class_Blackboard_method_populate_from_dict>` **(** Dictionary dictionary **)** |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_parent<class_Blackboard_method_set_parent>` **(** :ref:`Blackboard<class_Blackboard>` blackboard **)** | | void | :ref:`set_parent<class_Blackboard_method_set_parent>` **(** :ref:`Blackboard<class_Blackboard>` blackboard **)** |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_var<class_Blackboard_method_set_var>` **(** StringName var_name, Variant value **)** | | void | :ref:`set_var<class_Blackboard_method_set_var>` **(** StringName var_name, Variant value **)** |
@ -84,18 +76,6 @@ Establish a binding between a variable and the object's property specified by ``
---- ----
.. _class_Blackboard_method_clear:
.. rst-class:: classref-method
void **clear** **(** **)**
Removes all variables from the Blackboard. Parent scopes are not affected.
.. rst-class:: classref-item-separator
----
.. _class_Blackboard_method_erase_var: .. _class_Blackboard_method_erase_var:
.. rst-class:: classref-method .. rst-class:: classref-method
@ -132,18 +112,6 @@ Returns variable value or ``default`` if variable doesn't exist. If ``complain``
---- ----
.. _class_Blackboard_method_get_vars_as_dict:
.. rst-class:: classref-method
Dictionary **get_vars_as_dict** **(** **)** |const|
Returns all variables in the Blackboard as a dictionary. Keys are the variable names, values are the variable values. Parent scopes are not included.
.. rst-class:: classref-item-separator
----
.. _class_Blackboard_method_has_var: .. _class_Blackboard_method_has_var:
.. rst-class:: classref-method .. rst-class:: classref-method
@ -170,30 +138,6 @@ You can use this method to link a variable in the current scope to a variable in
---- ----
.. _class_Blackboard_method_list_vars:
.. rst-class:: classref-method
StringName[] **list_vars** **(** **)** |const|
Returns all variable names in the Blackboard. Parent scopes are not included.
.. rst-class:: classref-item-separator
----
.. _class_Blackboard_method_populate_from_dict:
.. rst-class:: classref-method
void **populate_from_dict** **(** Dictionary dictionary **)**
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.
.. rst-class:: classref-item-separator
----
.. _class_Blackboard_method_set_parent: .. _class_Blackboard_method_set_parent:
.. rst-class:: classref-method .. rst-class:: classref-method

View File

@ -21,12 +21,6 @@
Establish a binding between a variable and the object's property specified by [param property] and [param object]. Changes to the variable update the property, and vice versa. If [param create] is [code]true[/code], the variable will be created if it doesn't exist. Establish a binding between a variable and the object's property specified by [param property] and [param object]. Changes to the variable update the property, and vice versa. If [param create] is [code]true[/code], the variable will be created if it doesn't exist.
</description> </description>
</method> </method>
<method name="clear">
<return type="void" />
<description>
Removes all variables from the Blackboard. Parent scopes are not affected.
</description>
</method>
<method name="erase_var"> <method name="erase_var">
<return type="void" /> <return type="void" />
<param index="0" name="var_name" type="StringName" /> <param index="0" name="var_name" type="StringName" />
@ -49,12 +43,6 @@
Returns variable value or [param default] if variable doesn't exist. If [param complain] is [code]true[/code], an error will be printed if variable doesn't exist. Returns variable value or [param default] if variable doesn't exist. If [param complain] is [code]true[/code], an error will be printed if variable doesn't exist.
</description> </description>
</method> </method>
<method name="get_vars_as_dict" qualifiers="const">
<return type="Dictionary" />
<description>
Returns all variables in the Blackboard as a dictionary. Keys are the variable names, values are the variable values. Parent scopes are not included.
</description>
</method>
<method name="has_var" qualifiers="const"> <method name="has_var" qualifiers="const">
<return type="bool" /> <return type="bool" />
<param index="0" name="var_name" type="StringName" /> <param index="0" name="var_name" type="StringName" />
@ -73,19 +61,6 @@
You can use this method to link a variable in the current scope to a variable in another scope, or in another Blackboard instance. A variable can only be linked to one other variable. Calling this method again will overwrite the previous link. However, it is possible to link to the same variable from multiple different variables. You can use this method to link a variable in the current scope to a variable in another scope, or in another Blackboard instance. A variable can only be linked to one other variable. Calling this method again will overwrite the previous link. However, it is possible to link to the same variable from multiple different variables.
</description> </description>
</method> </method>
<method name="list_vars" qualifiers="const">
<return type="StringName[]" />
<description>
Returns all variable names in the Blackboard. Parent scopes are not included.
</description>
</method>
<method name="populate_from_dict">
<return type="void" />
<param index="0" name="dictionary" type="Dictionary" />
<description>
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>
</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" />

View File

@ -260,14 +260,14 @@ void BlackboardPlanEditor::_refresh() {
nodepath_prefetching->set_pressed(plan->is_prefetching_nodepath_vars()); nodepath_prefetching->set_pressed(plan->is_prefetching_nodepath_vars());
TypedArray<StringName> names = plan->list_vars(); PackedStringArray names = plan->list_vars();
for (int i = 0; i < names.size(); i++) { int idx = 0;
const String &var_name = names[i]; for (const String &var_name : names) {
BBVariable var = plan->get_var(var_name); BBVariable var = plan->get_var(var_name);
PanelContainer *row_panel = memnew(PanelContainer); PanelContainer *row_panel = memnew(PanelContainer);
rows_vbox->add_child(row_panel); rows_vbox->add_child(row_panel);
ADD_STYLEBOX_OVERRIDE(row_panel, LW_NAME(panel), i % 2 ? theme_cache.odd_style : theme_cache.even_style); ADD_STYLEBOX_OVERRIDE(row_panel, LW_NAME(panel), idx % 2 ? theme_cache.odd_style : theme_cache.even_style);
row_panel->set_h_size_flags(Control::SIZE_EXPAND_FILL); row_panel->set_h_size_flags(Control::SIZE_EXPAND_FILL);
HBoxContainer *props_hbox = memnew(HBoxContainer); HBoxContainer *props_hbox = memnew(HBoxContainer);
@ -288,7 +288,7 @@ void BlackboardPlanEditor::_refresh() {
name_edit->set_placeholder(TTR("Variable name")); name_edit->set_placeholder(TTR("Variable name"));
name_edit->set_flat(true); name_edit->set_flat(true);
name_edit->set_custom_minimum_size(Size2(300.0, 0.0) * EDSCALE); name_edit->set_custom_minimum_size(Size2(300.0, 0.0) * EDSCALE);
name_edit->connect(LW_NAME(text_changed), callable_mp(this, &BlackboardPlanEditor::_rename_var).bind(i)); name_edit->connect(LW_NAME(text_changed), callable_mp(this, &BlackboardPlanEditor::_rename_var).bind(idx));
name_edit->connect(LW_NAME(text_submitted), callable_mp(this, &BlackboardPlanEditor::_refresh).unbind(1)); name_edit->connect(LW_NAME(text_submitted), callable_mp(this, &BlackboardPlanEditor::_refresh).unbind(1));
Button *type_choice = memnew(Button); Button *type_choice = memnew(Button);
@ -300,7 +300,7 @@ void BlackboardPlanEditor::_refresh() {
type_choice->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); type_choice->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
type_choice->set_flat(true); type_choice->set_flat(true);
type_choice->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT); type_choice->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
type_choice->connect(LW_NAME(pressed), callable_mp(this, &BlackboardPlanEditor::_show_button_popup).bind(type_choice, type_menu, i)); type_choice->connect(LW_NAME(pressed), callable_mp(this, &BlackboardPlanEditor::_show_button_popup).bind(type_choice, type_menu, idx));
Button *hint_choice = memnew(Button); Button *hint_choice = memnew(Button);
props_hbox->add_child(hint_choice); props_hbox->add_child(hint_choice);
@ -310,7 +310,7 @@ void BlackboardPlanEditor::_refresh() {
hint_choice->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); hint_choice->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
hint_choice->set_flat(true); hint_choice->set_flat(true);
hint_choice->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT); hint_choice->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
hint_choice->connect(LW_NAME(pressed), callable_mp(this, &BlackboardPlanEditor::_show_button_popup).bind(hint_choice, hint_menu, i)); hint_choice->connect(LW_NAME(pressed), callable_mp(this, &BlackboardPlanEditor::_show_button_popup).bind(hint_choice, hint_menu, idx));
LineEdit *hint_string_edit = memnew(LineEdit); LineEdit *hint_string_edit = memnew(LineEdit);
props_hbox->add_child(hint_string_edit); props_hbox->add_child(hint_string_edit);
@ -319,14 +319,16 @@ void BlackboardPlanEditor::_refresh() {
hint_string_edit->set_placeholder(TTR("Hint string")); hint_string_edit->set_placeholder(TTR("Hint string"));
hint_string_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL); hint_string_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
hint_string_edit->set_flat(true); hint_string_edit->set_flat(true);
hint_string_edit->connect(LW_NAME(text_changed), callable_mp(this, &BlackboardPlanEditor::_change_var_hint_string).bind(i)); hint_string_edit->connect(LW_NAME(text_changed), callable_mp(this, &BlackboardPlanEditor::_change_var_hint_string).bind(idx));
hint_string_edit->connect(LW_NAME(text_submitted), callable_mp(this, &BlackboardPlanEditor::_refresh).unbind(1)); hint_string_edit->connect(LW_NAME(text_submitted), callable_mp(this, &BlackboardPlanEditor::_refresh).unbind(1));
Button *trash_button = memnew(Button); Button *trash_button = memnew(Button);
props_hbox->add_child(trash_button); props_hbox->add_child(trash_button);
trash_button->set_custom_minimum_size(Size2(24.0, 0.0) * EDSCALE); trash_button->set_custom_minimum_size(Size2(24.0, 0.0) * EDSCALE);
BUTTON_SET_ICON(trash_button, theme_cache.trash_icon); BUTTON_SET_ICON(trash_button, theme_cache.trash_icon);
trash_button->connect(LW_NAME(pressed), callable_mp(this, &BlackboardPlanEditor::_trash_var).bind(i)); trash_button->connect(LW_NAME(pressed), callable_mp(this, &BlackboardPlanEditor::_trash_var).bind(idx));
idx += 1;
} }
} }

View File

@ -40,9 +40,10 @@ void EditorPropertyVariableName::_show_variables_popup() {
variables_popup->clear(); variables_popup->clear();
variables_popup->reset_size(); variables_popup->reset_size();
TypedArray<StringName> var_names = plan->list_vars(); int idx = 0;
for (int i = 0; i < var_names.size(); i++) { for (String var_name : plan->list_vars()) {
variables_popup->add_item(var_names[i], i); variables_popup->add_item(var_name, idx);
idx += 1;
} }
Transform2D xform = name_edit->get_screen_transform(); Transform2D xform = name_edit->get_screen_transform();

View File

@ -15,7 +15,6 @@ env = SConscript("godot-cpp/SConstruct")
# Generate version header. # Generate version header.
sys.path.append("./limboai") sys.path.append("./limboai")
import limboai_version import limboai_version
os.chdir("./limboai") os.chdir("./limboai")
limboai_version.generate_module_version_header() limboai_version.generate_module_version_header()
os.chdir("..") os.chdir("..")

View File

@ -8,10 +8,8 @@ doc_branch = "latest"
# Code that generates version header # Code that generates version header
def _git_hash(short: bool = False): def _git_hash(short: bool = False):
import subprocess import subprocess
ret = "unknown" ret = "unknown"
try: try:
if short: if short:
@ -33,7 +31,7 @@ def _get_version_info():
"status": status, "status": status,
"doc_branch": doc_branch, "doc_branch": doc_branch,
"git_short_hash": _git_hash(short=True), "git_short_hash": _git_hash(short=True),
"git_hash": _git_hash(short=False), "git_hash": _git_hash(short=False)
} }
@ -57,8 +55,5 @@ def generate_module_version_header():
#define LIMBOAI_VERSION_DOC_URL "https://limboai.readthedocs.io/en/" LIMBOAI_VERSION_DOC_BRANCH "/" #define LIMBOAI_VERSION_DOC_URL "https://limboai.readthedocs.io/en/" LIMBOAI_VERSION_DOC_BRANCH "/"
#endif // LIMBOAI_VERSION_GEN_H #endif // LIMBOAI_VERSION_GEN_H
""".format( """.format(**version_info))
**version_info
)
)
f.close() f.close()

View File

@ -1,186 +0,0 @@
#ifndef TEST_BLACKBOARD_H
#define TEST_BLACKBOARD_H
#include "core/variant/variant.h"
#include "limbo_test.h"
#include "modules/limboai/blackboard/blackboard.h"
namespace TestBlackboard {
class TestPropertyHolder : public RefCounted {
GDCLASS(TestPropertyHolder, RefCounted);
public:
int property = 0;
void set_property(int p_property) { property = p_property; }
int get_property() { return property; }
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("set_property", "property"), &TestPropertyHolder::set_property);
ClassDB::bind_method(D_METHOD("get_property"), &TestPropertyHolder::get_property);
ADD_PROPERTY(PropertyInfo(Variant::INT, "property"), "set_property", "get_property");
}
};
TEST_CASE("[Modules][LimboAI] Test Blackboard") {
Ref<Blackboard> blackboard = memnew(Blackboard);
blackboard->set_var("a", 1);
blackboard->set_var("b", Vector2(2, 2));
blackboard->set_var("c", String("3"));
Variant not_found("not_found");
SUBCASE("Test getter") {
CHECK_EQ(blackboard->get_var("a", not_found), Variant(1));
CHECK_EQ(blackboard->get_var("b", not_found), Variant(Vector2(2, 2)));
CHECK_EQ(blackboard->get_var("c", not_found), Variant("3"));
}
SUBCASE("Test has_var()") {
CHECK(blackboard->has_var("a"));
CHECK(blackboard->has_var("b"));
CHECK(blackboard->has_var("c"));
CHECK_FALSE(blackboard->has_var("d"));
}
SUBCASE("Test erase_var()") {
blackboard->erase_var("b");
CHECK_FALSE(blackboard->has_var("b"));
CHECK(blackboard->has_var("a"));
CHECK(blackboard->has_var("c"));
}
SUBCASE("Test clear()") {
blackboard->clear();
CHECK_FALSE(blackboard->has_var("a"));
CHECK_FALSE(blackboard->has_var("b"));
CHECK_FALSE(blackboard->has_var("c"));
}
SUBCASE("Test list_vars()") {
TypedArray<StringName> vars = blackboard->list_vars();
CHECK_EQ(vars.size(), 3);
CHECK(vars.has("a"));
CHECK(vars.has("b"));
CHECK(vars.has("c"));
}
SUBCASE("Test get_vars_as_dict()") {
Dictionary dict = blackboard->get_vars_as_dict();
CHECK_EQ(dict.size(), 3);
CHECK(dict.has("a"));
CHECK(dict.has("b"));
CHECK(dict.has("c"));
CHECK_EQ(dict["a"], Variant(1));
CHECK_EQ(dict["b"], Variant(Vector2(2, 2)));
CHECK_EQ(dict["c"], Variant("3"));
// * Should not include parent scope values
Ref<Blackboard> parent_scope = memnew(Blackboard);
blackboard->set_parent(parent_scope);
parent_scope->set_var("d", 1);
dict = blackboard->get_vars_as_dict();
CHECK_EQ(dict.size(), 3);
CHECK_FALSE(dict.has("d"));
}
SUBCASE("Test populate_from_dict() overriding values") {
Dictionary dict;
dict["a"] = "value_a";
dict["b"] = "value_b";
dict["c"] = "value_c";
blackboard->populate_from_dict(dict);
CHECK_EQ(blackboard->list_vars().size(), 3);
CHECK_EQ(blackboard->get_var("a", not_found), Variant("value_a"));
CHECK_EQ(blackboard->get_var("b", not_found), Variant("value_b"));
CHECK_EQ(blackboard->get_var("c", not_found), Variant("value_c"));
}
SUBCASE("Test populate_from_dict() creating new values") {
Dictionary dict;
dict["d"] = "value_d";
dict["e"] = "value_e";
blackboard->populate_from_dict(dict);
CHECK_EQ(blackboard->list_vars().size(), 5);
CHECK_EQ(blackboard->get_var("d", not_found), Variant("value_d"));
CHECK_EQ(blackboard->get_var("e", not_found), Variant("value_e"));
}
SUBCASE("Test scoping") {
CHECK_EQ(blackboard->top(), blackboard);
Ref<Blackboard> parent_scope = memnew(Blackboard);
blackboard->set_parent(parent_scope);
CHECK_EQ(blackboard->get_parent(), parent_scope);
CHECK_EQ(blackboard->top(), parent_scope);
parent_scope->set_var("a", 5);
CHECK_EQ(blackboard->get_var("a", not_found), Variant(1)); // * should return current scope value
CHECK_EQ(parent_scope->get_var("a", not_found), Variant(5)); // * should return parent scope value
CHECK_EQ(parent_scope->get_var("b", not_found, false), not_found); // * should not return current scope value
parent_scope->set_var("d", 123);
CHECK_EQ(blackboard->get_var("d", not_found), Variant(123)); // * should return parent scope value
blackboard->set_var("d", 456);
CHECK_EQ(blackboard->get_var("d", not_found), Variant(456)); // * should return new value
CHECK_EQ(parent_scope->get_var("d", not_found), Variant(123)); // * should return parent scope value
Ref<Blackboard> grand_parent_scope = memnew(Blackboard);
parent_scope->set_parent(grand_parent_scope);
CHECK_EQ(blackboard->top(), grand_parent_scope);
grand_parent_scope->set_var("a", "value_found");
CHECK_EQ(grand_parent_scope->get_var("a", not_found), Variant("value_found"));
CHECK_EQ(grand_parent_scope->get_var("b", not_found, false), not_found);
CHECK_EQ(grand_parent_scope->get_var("c", not_found, false), not_found);
CHECK_EQ(grand_parent_scope->get_var("d", not_found, false), not_found);
CHECK_EQ(parent_scope->get_var("a", not_found), Variant(5));
CHECK_EQ(blackboard->get_var("a", not_found), Variant(1));
}
SUBCASE("Test binding") {
Ref<TestPropertyHolder> holder = memnew(TestPropertyHolder);
blackboard->bind_var_to_property("a", holder.ptr(), "property");
holder->set_property(5);
CHECK_EQ(blackboard->get_var("a", not_found), Variant(5));
blackboard->set_var("a", Variant(6));
CHECK_EQ(holder->get_property(), 6);
blackboard->unbind_var("a");
blackboard->set_var("a", Variant(7));
CHECK_EQ(holder->get_property(), 6);
CHECK_EQ(blackboard->get_var("a", not_found), Variant(7));
}
SUBCASE("Test linking") {
Ref<Blackboard> target_blackboard = memnew(Blackboard);
target_blackboard->set_var("aa", Variant(111));
blackboard->link_var("a", target_blackboard, "aa");
CHECK(target_blackboard->has_var("aa"));
CHECK_FALSE(target_blackboard->has_var("a"));
CHECK_EQ(blackboard->get_var("a", not_found), Variant(111));
CHECK_EQ(target_blackboard->get_var("aa", not_found), Variant(111));
blackboard->set_var("a", Variant(222));
CHECK_EQ(blackboard->get_var("a", not_found), Variant(222));
CHECK_EQ(target_blackboard->get_var("aa", not_found), Variant(222));
target_blackboard->set_var("aa", Variant(333));
CHECK_EQ(blackboard->get_var("a", not_found), Variant(333));
CHECK_EQ(target_blackboard->get_var("aa", not_found), Variant(333));
}
}
} //namespace TestBlackboard
#endif // TEST_BLACKBOARD_H