From 184361d46017c286eeb0dcb4d1df10b69a3af38f Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 15 Jan 2024 17:03:52 +0100 Subject: [PATCH 1/5] CallMethod: Store result on the blackboard --- bt/tasks/utility/bt_call_method.cpp | 28 ++++++++++++++++++++++------ bt/tasks/utility/bt_call_method.h | 4 ++++ util/limbo_string_names.cpp | 1 + util/limbo_string_names.h | 1 + 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bt/tasks/utility/bt_call_method.cpp b/bt/tasks/utility/bt_call_method.cpp index b61c46b..793b41f 100644 --- a/bt/tasks/utility/bt_call_method.cpp +++ b/bt/tasks/utility/bt_call_method.cpp @@ -12,6 +12,7 @@ #include "bt_call_method.h" #include "../../../util/limbo_compat.h" +#include "../../../util/limbo_utility.h" //**** Setters / Getters @@ -33,11 +34,16 @@ void BTCallMethod::set_include_delta(bool p_include_delta) { emit_changed(); } -void BTCallMethod::set_args(Array p_args) { +void BTCallMethod::set_args(TypedArray p_args) { args = p_args; emit_changed(); } +void BTCallMethod::set_result_var(const String &p_result_var) { + result_var = p_result_var; + emit_changed(); +} + //**** Task Implementation PackedStringArray BTCallMethod::get_configuration_warnings() { @@ -63,10 +69,11 @@ String BTCallMethod::_generate_name() { } args_str += vformat("%s", args).trim_prefix("[").trim_suffix("]"); } - return vformat("CallMethod %s(%s) node: %s", - (method != StringName() ? method : "???"), + return vformat("CallMethod %s(%s) node: %s %s", + method != StringName() ? method : "???", args_str, - (node_param.is_valid() && !node_param->to_string().is_empty() ? node_param->to_string() : "???")); + node_param.is_valid() && !node_param->to_string().is_empty() ? node_param->to_string() : "???", + result_var.is_empty() ? "" : LW_NAME(output_var_prefix) + LimboUtility::get_singleton()->decorate_var(result_var)); } BT::Status BTCallMethod::_tick(double p_delta) { @@ -75,6 +82,8 @@ BT::Status BTCallMethod::_tick(double p_delta) { Object *obj = node_param->get_value(get_agent(), get_blackboard()); ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTCallMethod: Failed to get object: " + node_param->to_string()); + Variant result; + #ifdef LIMBOAI_MODULE const Variant delta = include_delta ? Variant(p_delta) : Variant(); const Variant **argptrs = nullptr; @@ -91,7 +100,7 @@ BT::Status BTCallMethod::_tick(double p_delta) { } Callable::CallError ce; - obj->callp(method, argptrs, argument_count, ce); + result = obj->callp(method, argptrs, argument_count, ce); if (ce.error != Callable::CallError::CALL_OK) { ERR_FAIL_V_MSG(FAILURE, "BTCallMethod: Error calling method: " + Variant::get_call_error_text(obj, method, argptrs, argument_count, ce) + "."); } @@ -105,9 +114,13 @@ BT::Status BTCallMethod::_tick(double p_delta) { } // TODO: Unsure how to detect call error, so we return SUCCESS for now... - obj->callv(method, call_args); + result = obj->callv(method, call_args); #endif // LIMBOAI_MODULE & LIMBOAI_GDEXTENSION + if (!result_var.is_empty()) { + get_blackboard()->set_var(result_var, result); + } + return SUCCESS; } @@ -122,9 +135,12 @@ void BTCallMethod::_bind_methods() { ClassDB::bind_method(D_METHOD("get_args"), &BTCallMethod::get_args); ClassDB::bind_method(D_METHOD("set_include_delta", "p_include_delta"), &BTCallMethod::set_include_delta); ClassDB::bind_method(D_METHOD("is_delta_included"), &BTCallMethod::is_delta_included); + ClassDB::bind_method(D_METHOD("set_result_var", "p_result_var"), &BTCallMethod::set_result_var); + ClassDB::bind_method(D_METHOD("get_result_var"), &BTCallMethod::get_result_var); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "BBNode"), "set_node_param", "get_node_param"); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "method"), "set_method", "get_method"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "result_var"), "set_result_var", "get_result_var"); ADD_GROUP("Arguments", "args_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "args_include_delta"), "set_include_delta", "is_delta_included"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "args"), "set_args", "get_args"); diff --git a/bt/tasks/utility/bt_call_method.h b/bt/tasks/utility/bt_call_method.h index 093cf78..c070fdb 100644 --- a/bt/tasks/utility/bt_call_method.h +++ b/bt/tasks/utility/bt_call_method.h @@ -25,6 +25,7 @@ private: Ref node_param; Array args; bool include_delta = false; + String result_var; protected: static void _bind_methods(); @@ -45,6 +46,9 @@ public: void set_include_delta(bool p_include_delta); bool is_delta_included() const { return include_delta; } + void set_result_var(const String &p_result_var); + String get_result_var() const { return result_var; } + virtual PackedStringArray get_configuration_warnings() override; BTCallMethod(); diff --git a/util/limbo_string_names.cpp b/util/limbo_string_names.cpp index 4bcde51..ee045bd 100644 --- a/util/limbo_string_names.cpp +++ b/util/limbo_string_names.cpp @@ -136,4 +136,5 @@ LimboStringNames::LimboStringNames() { EVENT_FINISHED = "finished"; repeat_forever.parse_utf8("Repeat ∞"); + output_var_prefix.parse_utf8("➜"); } diff --git a/util/limbo_string_names.h b/util/limbo_string_names.h index 3d16585..d1bd93f 100644 --- a/util/limbo_string_names.h +++ b/util/limbo_string_names.h @@ -151,6 +151,7 @@ public: String EVENT_FINISHED; String repeat_forever; + String output_var_prefix; }; #define LW_NAME(m_arg) LimboStringNames::get_singleton()->m_arg From c63785b5bce2d00d79ae4dc598c5b4c462a6424e Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 15 Jan 2024 21:51:17 +0100 Subject: [PATCH 2/5] CallMethod: Use array of BBVariant to specify arguments This allows specifying variables on the blackboard as arguments in additions to raw values. WARNING: Breaks compatibility if you are using CallMethod tasks. CallMethod arguments in existing trees will need to be reassigned! --- bt/tasks/utility/bt_call_method.cpp | 19 +++++++++++++------ bt/tasks/utility/bt_call_method.h | 7 ++++--- util/limbo_compat.h | 1 + 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/bt/tasks/utility/bt_call_method.cpp b/bt/tasks/utility/bt_call_method.cpp index 793b41f..5a4e681 100644 --- a/bt/tasks/utility/bt_call_method.cpp +++ b/bt/tasks/utility/bt_call_method.cpp @@ -14,6 +14,10 @@ #include "../../../util/limbo_compat.h" #include "../../../util/limbo_utility.h" +#ifdef LIMBOAI_GDEXTENSION +#include "godot_cpp/classes/global_constants.hpp" +#endif // LIMBOAI_GDEXTENSION + //**** Setters / Getters void BTCallMethod::set_method(StringName p_method_name) { @@ -83,6 +87,7 @@ BT::Status BTCallMethod::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTCallMethod: Failed to get object: " + node_param->to_string()); Variant result; + Array call_args; #ifdef LIMBOAI_MODULE const Variant delta = include_delta ? Variant(p_delta) : Variant(); @@ -95,7 +100,9 @@ BT::Status BTCallMethod::_tick(double p_delta) { argptrs[0] = δ } for (int i = 0; i < args.size(); i++) { - argptrs[i + int(include_delta)] = &args[i]; + Ref param = args[i]; + call_args.push_back(param->get_value(get_agent(), get_blackboard())); + argptrs[i + int(include_delta)] = &call_args[i]; } } @@ -105,12 +112,12 @@ BT::Status BTCallMethod::_tick(double p_delta) { ERR_FAIL_V_MSG(FAILURE, "BTCallMethod: Error calling method: " + Variant::get_call_error_text(obj, method, argptrs, argument_count, ce) + "."); } #elif LIMBOAI_GDEXTENSION - Array call_args; if (include_delta) { call_args.push_back(Variant(p_delta)); - call_args.append_array(args); - } else { - call_args = args; + } + for (int i = 0; i < args.size(); i++) { + Ref param = args[i]; + call_args.push_back(param->get_value(get_agent(), get_blackboard())); } // TODO: Unsure how to detect call error, so we return SUCCESS for now... @@ -143,7 +150,7 @@ void BTCallMethod::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "result_var"), "set_result_var", "get_result_var"); ADD_GROUP("Arguments", "args_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "args_include_delta"), "set_include_delta", "is_delta_included"); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "args"), "set_args", "get_args"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "args", PROPERTY_HINT_ARRAY_TYPE, RESOURCE_TYPE_HINT("BBVariant")), "set_args", "get_args"); // ADD_PROPERTY_DEFAULT("args_include_delta", false); } diff --git a/bt/tasks/utility/bt_call_method.h b/bt/tasks/utility/bt_call_method.h index c070fdb..99912b3 100644 --- a/bt/tasks/utility/bt_call_method.h +++ b/bt/tasks/utility/bt_call_method.h @@ -15,6 +15,7 @@ #include "../bt_action.h" #include "../../../blackboard/bb_param/bb_node.h" +#include "../../../blackboard/bb_param/bb_variant.h" class BTCallMethod : public BTAction { GDCLASS(BTCallMethod, BTAction); @@ -23,7 +24,7 @@ class BTCallMethod : public BTAction { private: StringName method; Ref node_param; - Array args; + TypedArray args; bool include_delta = false; String result_var; @@ -40,8 +41,8 @@ public: void set_node_param(Ref p_object); Ref get_node_param() const { return node_param; } - void set_args(Array p_args); - Array get_args() const { return args; } + void set_args(TypedArray p_args); + TypedArray get_args() const { return args; } void set_include_delta(bool p_include_delta); bool is_delta_included() const { return include_delta; } diff --git a/util/limbo_compat.h b/util/limbo_compat.h index d165cc9..81191e9 100644 --- a/util/limbo_compat.h +++ b/util/limbo_compat.h @@ -170,6 +170,7 @@ inline void VARIANT_DELETE_IF_OBJECT(Variant m_variant) { #define PROJECT_CONFIG_FILE() GET_PROJECT_SETTINGS_DIR().path_join("limbo_ai.cfg") #define IS_RESOURCE_FILE(m_path) (m_path.begins_with("res://") && m_path.find("::") == -1) +#define RESOURCE_TYPE_HINT(m_type) vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, m_type) #ifdef TOOLS_ENABLED From 17a480ed19b1a6d5109fece4288782d07aae176e Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 15 Jan 2024 21:57:31 +0100 Subject: [PATCH 3/5] Utilize space better with BBParam property editor For types that need more space, the bottom editor will be used instead. In effect also for string parameters with @export_multiline. --- editor/editor_property_bb_param.cpp | 47 +++++++++++++++++++++++++---- editor/editor_property_bb_param.h | 2 ++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/editor/editor_property_bb_param.cpp b/editor/editor_property_bb_param.cpp index 2ce7eff..16c32a3 100644 --- a/editor/editor_property_bb_param.cpp +++ b/editor/editor_property_bb_param.cpp @@ -15,7 +15,6 @@ #include "editor_property_bb_param.h" -#include "core/variant/variant.h" #include "modules/limboai/blackboard/bb_param/bb_param.h" #include "modules/limboai/blackboard/bb_param/bb_variant.h" #include "modules/limboai/editor/mode_switch_button.h" @@ -23,9 +22,11 @@ #include "core/error/error_macros.h" #include "core/io/marshalls.h" #include "core/object/class_db.h" +#include "core/object/object.h" #include "core/object/ref_counted.h" #include "core/os/memory.h" #include "core/string/print_string.h" +#include "core/variant/variant.h" #include "editor/editor_inspector.h" #include "editor/editor_properties.h" #include "editor/editor_properties_array_dict.h" @@ -55,6 +56,8 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) { _remove_value_editor(); } + bool is_bottom = false; + switch (p_type) { case Variant::NIL: { value_editor = memnew(EditorPropertyNil); @@ -78,6 +81,7 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) { } else { value_editor = memnew(EditorPropertyText); } + is_bottom = (property_hint == PROPERTY_HINT_MULTILINE_TEXT); } break; case Variant::VECTOR2: { EditorPropertyVector2 *editor = memnew(EditorPropertyVector2); @@ -93,66 +97,79 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) { EditorPropertyRect2 *editor = memnew(EditorPropertyRect2); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::RECT2I: { EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i); editor->setup(-100000, 100000); value_editor = editor; + is_bottom = true; } break; case Variant::VECTOR3: { EditorPropertyVector3 *editor = memnew(EditorPropertyVector3); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::VECTOR3I: { EditorPropertyVector3i *editor = memnew(EditorPropertyVector3i); editor->setup(-100000, 100000); value_editor = editor; + is_bottom = true; } break; case Variant::VECTOR4: { EditorPropertyVector4 *editor = memnew(EditorPropertyVector4); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::VECTOR4I: { EditorPropertyVector4i *editor = memnew(EditorPropertyVector4i); editor->setup(-100000, 100000); value_editor = editor; + is_bottom = true; } break; case Variant::TRANSFORM2D: { EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::PLANE: { EditorPropertyPlane *editor = memnew(EditorPropertyPlane); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::QUATERNION: { EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::AABB: { EditorPropertyAABB *editor = memnew(EditorPropertyAABB); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::BASIS: { EditorPropertyBasis *editor = memnew(EditorPropertyBasis); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::TRANSFORM3D: { EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::PROJECTION: { EditorPropertyProjection *editor = memnew(EditorPropertyProjection); editor->setup(-100000, 100000, EDITOR_GET("interface/inspector/default_float_step"), true); value_editor = editor; + is_bottom = true; } break; case Variant::COLOR: { value_editor = memnew(EditorPropertyColor); @@ -161,6 +178,7 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) { EditorPropertyText *editor = memnew(EditorPropertyText); editor->set_string_name(true); value_editor = editor; + is_bottom = (property_hint == PROPERTY_HINT_MULTILINE_TEXT); } break; case Variant::NODE_PATH: { value_editor = memnew(EditorPropertyNodePath); @@ -176,9 +194,11 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) { EditorPropertyResource *editor = memnew(EditorPropertyResource); editor->setup(_get_edited_param().ptr(), SNAME("saved_value"), "Resource"); value_editor = editor; + is_bottom = true; } break; case Variant::DICTIONARY: { value_editor = memnew(EditorPropertyDictionary); + is_bottom = true; } break; case Variant::ARRAY: @@ -194,6 +214,7 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(p_type); value_editor = editor; + is_bottom = true; } break; default: { @@ -202,15 +223,25 @@ void EditorPropertyBBParam::_create_value_editor(Variant::Type p_type) { } } value_editor->set_name_split_ratio(0.0); - editor_hbox->add_child(value_editor); + value_editor->set_use_folding(is_using_folding()); + value_editor->set_selectable(false); value_editor->set_h_size_flags(SIZE_EXPAND_FILL); value_editor->set_meta(SNAME("_param_type"), p_type); value_editor->connect(SNAME("property_changed"), callable_mp(this, &EditorPropertyBBParam::_value_edited)); + if (is_bottom) { + bottom_container->add_child(value_editor); + set_bottom_editor(bottom_container); + bottom_container->show(); + } else { + set_bottom_editor(nullptr); + editor_hbox->add_child(value_editor); + bottom_container->hide(); + } } void EditorPropertyBBParam::_remove_value_editor() { if (value_editor) { - editor_hbox->remove_child(value_editor); + value_editor->get_parent()->remove_child(value_editor); value_editor->queue_free(); value_editor = nullptr; } @@ -245,15 +276,15 @@ void EditorPropertyBBParam::update_property() { variable_edit->set_text(param->get_variable()); variable_edit->set_editable(true); variable_edit->show(); - mode_button->set_mode(Mode::BIND_VAR, true); + mode_button->call_deferred(SNAME("set_mode"), Mode::BIND_VAR, true); type_choice->hide(); } else { - variable_edit->hide(); _create_value_editor(param->get_type()); + variable_edit->hide(); value_editor->show(); value_editor->set_object_and_property(param.ptr(), SNAME("saved_value")); - mode_button->set_mode(Mode::SPECIFY_VALUE, true); value_editor->update_property(); + mode_button->call_deferred(SNAME("set_mode"), Mode::SPECIFY_VALUE, true); type_choice->set_visible(is_variant_param); } @@ -308,6 +339,10 @@ EditorPropertyBBParam::EditorPropertyBBParam() { add_child(hbox); hbox->add_theme_constant_override(SNAME("separation"), 0); + bottom_container = memnew(MarginContainer); + bottom_container->set_theme_type_variation("MarginContainer4px"); + add_child(bottom_container); + mode_button = memnew(ModeSwitchButton); hbox->add_child(mode_button); mode_button->set_focus_mode(FOCUS_NONE); diff --git a/editor/editor_property_bb_param.h b/editor/editor_property_bb_param.h index e077a7d..6d64fe1 100644 --- a/editor/editor_property_bb_param.h +++ b/editor/editor_property_bb_param.h @@ -22,6 +22,7 @@ #include "modules/limboai/editor/mode_switch_button.h" #include "scene/gui/box_container.h" +#include "scene/gui/margin_container.h" #include "scene/gui/menu_button.h" class EditorPropertyBBParam : public EditorProperty { @@ -38,6 +39,7 @@ private: Mode mode = Mode::SPECIFY_VALUE; HBoxContainer *hbox = nullptr; + MarginContainer *bottom_container = nullptr; HBoxContainer *editor_hbox = nullptr; ModeSwitchButton *mode_button = nullptr; EditorProperty *value_editor = nullptr; From 1648728e1b315d9d700a0f9b4c74a26e1c7811c9 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 16 Jan 2024 10:46:42 +0100 Subject: [PATCH 4/5] CallMethod: Update unit tests --- blackboard/bb_param/bb_variant.cpp | 5 +++++ blackboard/bb_param/bb_variant.h | 1 + tests/test_call_method.h | 15 +++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/blackboard/bb_param/bb_variant.cpp b/blackboard/bb_param/bb_variant.cpp index cec0cf4..75379f8 100644 --- a/blackboard/bb_param/bb_variant.cpp +++ b/blackboard/bb_param/bb_variant.cpp @@ -39,5 +39,10 @@ void BBVariant::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, vtypes), "set_type", "get_type"); } +BBVariant::BBVariant(const Variant &p_value) { + set_type(p_value.get_type()); + set_saved_value(p_value); +} + BBVariant::BBVariant() { } diff --git a/blackboard/bb_param/bb_variant.h b/blackboard/bb_param/bb_variant.h index 5634206..8021a39 100644 --- a/blackboard/bb_param/bb_variant.h +++ b/blackboard/bb_param/bb_variant.h @@ -27,6 +27,7 @@ public: virtual Variant::Type get_type() const override; void set_type(Variant::Type p_type); + BBVariant(const Variant &p_value); BBVariant(); }; diff --git a/tests/test_call_method.h b/tests/test_call_method.h index dad3401..c2ccc9b 100644 --- a/tests/test_call_method.h +++ b/tests/test_call_method.h @@ -70,7 +70,7 @@ TEST_CASE("[Modules][LimboAI] BTCallMethod") { SUBCASE("Should fail with 0 arguments") { cm->set_include_delta(false); - cm->set_args(Array()); + cm->set_args(TypedArray()); ERR_PRINT_OFF; CHECK(cm->execute(0.01666) == BTTask::FAILURE); ERR_PRINT_ON; @@ -78,8 +78,8 @@ TEST_CASE("[Modules][LimboAI] BTCallMethod") { } SUBCASE("Should fail with too many arguments") { cm->set_include_delta(true); - Array args; - args.push_back(0.2); + TypedArray args; + args.push_back(memnew(BBVariant(0.2))); cm->set_args(args); ERR_PRINT_OFF; CHECK(cm->execute(0.01666) == BTTask::FAILURE); @@ -88,8 +88,8 @@ TEST_CASE("[Modules][LimboAI] BTCallMethod") { } SUBCASE("Should fail with a wrong type arg") { cm->set_include_delta(false); - Array args; - args.push_back("wrong_data"); + TypedArray args; + args.push_back(memnew(BBVariant("wrong data type"))); cm->set_args(args); ERR_PRINT_OFF; CHECK(cm->execute(0.01666) == BTTask::FAILURE); @@ -98,14 +98,13 @@ TEST_CASE("[Modules][LimboAI] BTCallMethod") { } SUBCASE("Should succeed with delta included") { cm->set_include_delta(true); - cm->set_args(Array()); CHECK(cm->execute(0.01666) == BTTask::SUCCESS); CHECK(callback_counter->num_callbacks == 1); } SUBCASE("Should succeed with one float arg") { cm->set_include_delta(false); - Array args; - args.push_back(0.2); + TypedArray args; + args.push_back(memnew(BBVariant(0.2))); cm->set_args(args); CHECK(cm->execute(0.01666) == BTTask::SUCCESS); CHECK(callback_counter->num_callbacks == 1); From 594097ae4caf562b97de1634264d971e4e0f7239 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 16 Jan 2024 11:18:18 +0100 Subject: [PATCH 5/5] Update class documentation and add rst update script --- doc/source/classes/class_behaviortree.rst | 4 +-- doc/source/classes/class_btcallmethod.rst | 43 ++++++++++++++++------- doc/source/classes/class_bttask.rst | 6 ++-- doc_classes/BTCallMethod.xml | 5 ++- doc_classes/BTTask.xml | 6 ++-- doc_classes/BehaviorTree.xml | 7 ++++ gdextension/update_rst.sh | 21 +++++++++++ 7 files changed, 70 insertions(+), 22 deletions(-) create mode 100755 gdextension/update_rst.sh diff --git a/doc/source/classes/class_behaviortree.rst b/doc/source/classes/class_behaviortree.rst index acd2ad9..e6fc70f 100644 --- a/doc/source/classes/class_behaviortree.rst +++ b/doc/source/classes/class_behaviortree.rst @@ -114,9 +114,7 @@ Makes a copy of the BehaviorTree resource. void **copy_other** **(** :ref:`BehaviorTree` p_other **)** -.. container:: contribute - - There is currently no description for this method. Please help us by :ref:`contributing one `! +Become a copy of another behavior tree. .. rst-class:: classref-item-separator diff --git a/doc/source/classes/class_btcallmethod.rst b/doc/source/classes/class_btcallmethod.rst index 2ebd334..231f27f 100644 --- a/doc/source/classes/class_btcallmethod.rst +++ b/doc/source/classes/class_btcallmethod.rst @@ -31,15 +31,17 @@ Properties .. table:: :widths: auto - +-----------------------------+---------------------------------------------------------------------------+-----------+ - | Array | :ref:`args` | ``[]`` | - +-----------------------------+---------------------------------------------------------------------------+-----------+ - | bool | :ref:`args_include_delta` | ``false`` | - +-----------------------------+---------------------------------------------------------------------------+-----------+ - | StringName | :ref:`method` | ``&""`` | - +-----------------------------+---------------------------------------------------------------------------+-----------+ - | :ref:`BBNode` | :ref:`node` | | - +-----------------------------+---------------------------------------------------------------------------+-----------+ + +-------------------------------------+---------------------------------------------------------------------------+-----------+ + | :ref:`BBVariant[]` | :ref:`args` | ``[]`` | + +-------------------------------------+---------------------------------------------------------------------------+-----------+ + | bool | :ref:`args_include_delta` | ``false`` | + +-------------------------------------+---------------------------------------------------------------------------+-----------+ + | StringName | :ref:`method` | ``&""`` | + +-------------------------------------+---------------------------------------------------------------------------+-----------+ + | :ref:`BBNode` | :ref:`node` | | + +-------------------------------------+---------------------------------------------------------------------------+-----------+ + | String | :ref:`result_var` | ``""`` | + +-------------------------------------+---------------------------------------------------------------------------+-----------+ .. rst-class:: classref-section-separator @@ -54,12 +56,12 @@ Property Descriptions .. rst-class:: classref-property -Array **args** = ``[]`` +:ref:`BBVariant[]` **args** = ``[]`` .. rst-class:: classref-property-setget -- void **set_args** **(** Array value **)** -- Array **get_args** **(** **)** +- void **set_args** **(** :ref:`BBVariant[]` value **)** +- :ref:`BBVariant[]` **get_args** **(** **)** The arguments to be passed when calling the method. @@ -114,6 +116,23 @@ The name of the method to be called. Specifies the ``Node`` or ``Object`` instance containing the method to be called. +.. rst-class:: classref-item-separator + +---- + +.. _class_BTCallMethod_property_result_var: + +.. rst-class:: classref-property + +String **result_var** = ``""`` + +.. rst-class:: classref-property-setget + +- void **set_result_var** **(** String value **)** +- String **get_result_var** **(** **)** + +if non-empty, assign the result of the method call to the blackboard variable specified by this property. + .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` diff --git a/doc/source/classes/class_bttask.rst b/doc/source/classes/class_bttask.rst index 53c42c7..ecd8bf6 100644 --- a/doc/source/classes/class_bttask.rst +++ b/doc/source/classes/class_bttask.rst @@ -64,7 +64,7 @@ Methods +-------------------------------+------------------------------------------------------------------------------------------------------------------------------+ | String | :ref:`_generate_name` **(** **)** |virtual| |const| | +-------------------------------+------------------------------------------------------------------------------------------------------------------------------+ - | PackedStringArray | :ref:`_get_configuration_warning` **(** **)** |virtual| |const| | + | PackedStringArray | :ref:`_get_configuration_warnings` **(** **)** |virtual| |const| | +-------------------------------+------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_setup` **(** **)** |virtual| | +-------------------------------+------------------------------------------------------------------------------------------------------------------------------+ @@ -249,11 +249,11 @@ Called to generate a display name for the task unless :ref:`custom_name - + The arguments to be passed when calling the method. @@ -22,5 +22,8 @@ Specifies the [Node] or [Object] instance containing the method to be called. + + if non-empty, assign the result of the method call to the blackboard variable specified by this property. + diff --git a/doc_classes/BTTask.xml b/doc_classes/BTTask.xml index 59dc1e3..07543e8 100644 --- a/doc_classes/BTTask.xml +++ b/doc_classes/BTTask.xml @@ -31,7 +31,7 @@ Called to generate a display name for the task unless [member custom_name] is set. See [method get_task_name]. - + The string returned by this method is shown as a warning message in the behavior tree editor. Any task script that overrides this method must include [code]@tool[/code] annotation at the top of the file. @@ -126,7 +126,7 @@ Returns the root task of the behavior tree. - + The string returned by this method is used to represent the task in the editor. @@ -169,7 +169,7 @@ Returns [code]null[/code] if this task has no parent or it is the last child in the parent's children list. - + diff --git a/doc_classes/BehaviorTree.xml b/doc_classes/BehaviorTree.xml index eb25025..958c4c5 100644 --- a/doc_classes/BehaviorTree.xml +++ b/doc_classes/BehaviorTree.xml @@ -21,6 +21,13 @@ Makes a copy of the BehaviorTree resource. + + + + + Become a copy of another behavior tree. + + diff --git a/gdextension/update_rst.sh b/gdextension/update_rst.sh new file mode 100755 index 0000000..018a552 --- /dev/null +++ b/gdextension/update_rst.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +usage () { echo -e "Usage: Call from the Godot source root to update LimboAI rst class documentation."; } +msg () { echo -e "$@"; } + +set -e + +if [ ! -d "${PWD}/modules/limboai" ]; then + usage + exit 1 +fi + +rm -rf /tmp/rst +./doc/tools/make_rst.py --output /tmp/rst doc/tools doc/classes/@GlobalScope.xml modules/limboai/doc_classes || /bin/true +msg Removing old rst class documentation... +rm ./modules/limboai/doc/source/classes/class_* +msg Copying new rst class documentation... +cp -r -f /tmp/rst/class_* modules/limboai/doc/source/classes/ +msg Cleaning up... +rm modules/limboai/doc/source/classes/class_@globalscope.rst +msg Done!