From 21c65541bf8cda4b11a6913ea3d1da36d8ee638e Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 15 Aug 2023 17:05:30 +0200 Subject: [PATCH] Refactor BTTask.get_configuration_warnings() --- bt/actions/bt_action.cpp | 13 ++++------ bt/actions/bt_action.h | 2 +- bt/actions/bt_await_animation.cpp | 21 ++++++--------- bt/actions/bt_await_animation.h | 2 +- bt/actions/bt_call_method.cpp | 12 ++++----- bt/actions/bt_call_method.h | 2 +- bt/actions/bt_console_print.cpp | 11 +++----- bt/actions/bt_console_print.h | 2 +- bt/actions/bt_pause_animation.cpp | 17 +++++-------- bt/actions/bt_pause_animation.h | 2 +- bt/actions/bt_play_animation.cpp | 19 +++++--------- bt/actions/bt_play_animation.h | 2 +- bt/actions/bt_set_agent_property.cpp | 13 ++++------ bt/actions/bt_set_agent_property.h | 2 +- bt/actions/bt_set_var.cpp | 13 ++++------ bt/actions/bt_set_var.h | 2 +- bt/actions/bt_stop_animation.cpp | 17 +++++-------- bt/actions/bt_stop_animation.h | 2 +- bt/bt_task.cpp | 11 +++++--- bt/bt_task.h | 4 +-- bt/composites/bt_composite.cpp | 13 ++++------ bt/composites/bt_composite.h | 2 +- bt/conditions/bt_check_agent_property.cpp | 13 ++++------ bt/conditions/bt_check_agent_property.h | 4 +-- bt/conditions/bt_check_trigger.cpp | 9 +++++++ bt/conditions/bt_check_trigger.h | 2 ++ bt/conditions/bt_check_var.cpp | 13 ++++------ bt/conditions/bt_check_var.h | 5 +--- bt/conditions/bt_condition.cpp | 13 ++++------ bt/conditions/bt_condition.h | 2 +- bt/decorators/bt_cooldown.cpp | 31 +++++++++++++++++++++++ bt/decorators/bt_cooldown.h | 29 +++++++-------------- bt/decorators/bt_decorator.cpp | 11 +++----- bt/decorators/bt_decorator.h | 2 +- bt/decorators/bt_delay.cpp | 5 ++++ bt/decorators/bt_delay.h | 5 +--- bt/decorators/bt_for_each.cpp | 16 ++++++++++++ bt/decorators/bt_for_each.h | 11 +++----- bt/decorators/bt_probability.cpp | 5 +++- bt/decorators/bt_probability.h | 7 +---- bt/decorators/bt_run_limit.cpp | 5 ++++ bt/decorators/bt_run_limit.h | 7 +---- bt/decorators/bt_subtree.cpp | 19 +++++++------- bt/decorators/bt_subtree.h | 10 +++----- bt/decorators/bt_time_limit.cpp | 5 ++++ bt/decorators/bt_time_limit.h | 5 +--- editor/limbo_ai_editor_plugin.cpp | 14 +++++++--- 47 files changed, 217 insertions(+), 215 deletions(-) diff --git a/bt/actions/bt_action.cpp b/bt/actions/bt_action.cpp index 7a5541c..af5e6a2 100644 --- a/bt/actions/bt_action.cpp +++ b/bt/actions/bt_action.cpp @@ -11,13 +11,10 @@ #include "bt_action.h" -String BTAction::get_configuration_warning() const { - String warning = BTTask::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTAction::get_configuration_warnings() const { + PackedStringArray warnings = BTTask::get_configuration_warnings(); if (get_child_count() != 0) { - warning += "Action can't have child tasks.\n"; + warnings.append("Action can't have child tasks."); } - return warning; -} \ No newline at end of file + return warnings; +} diff --git a/bt/actions/bt_action.h b/bt/actions/bt_action.h index 7491f78..1bff720 100644 --- a/bt/actions/bt_action.h +++ b/bt/actions/bt_action.h @@ -20,7 +20,7 @@ class BTAction : public BTTask { GDCLASS(BTAction, BTTask); public: - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_ACTION_H \ No newline at end of file diff --git a/bt/actions/bt_await_animation.cpp b/bt/actions/bt_await_animation.cpp index 67873db..35a190a 100644 --- a/bt/actions/bt_await_animation.cpp +++ b/bt/actions/bt_await_animation.cpp @@ -33,29 +33,24 @@ void BTAwaitAnimation::set_max_time(double p_max_time) { //**** Task Implementation -String BTAwaitAnimation::get_configuration_warning() const { - String warning = BTAction::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } - +PackedStringArray BTAwaitAnimation::get_configuration_warnings() const { + PackedStringArray warnings = BTAction::get_configuration_warnings(); if (animation_player_param.is_null()) { - warning += "Animation Player parameter is not set.\n"; + warnings.append("Animation Player parameter is not set."); } else { if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) { - warning += "Path to AnimationPlayer node is not set.\n"; + warnings.append("Path to AnimationPlayer node is not set."); } else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) { - warning += "AnimationPlayer blackboard variable is not set.\n"; + warnings.append("AnimationPlayer blackboard variable is not set."); } } if (animation_name == StringName()) { - warning += "Animation Name is required in order to wait for the animation to finish.\n"; + warnings.append("Animation Name is required in order to wait for the animation to finish."); } if (max_time <= 0.0) { - warning += "Max time should be greater than 0.0.\n"; + warnings.append("Max time should be greater than 0.0."); } - - return warning; + return warnings; } String BTAwaitAnimation::_generate_name() const { diff --git a/bt/actions/bt_await_animation.h b/bt/actions/bt_await_animation.h index 7eb34eb..66012b8 100644 --- a/bt/actions/bt_await_animation.h +++ b/bt/actions/bt_await_animation.h @@ -46,7 +46,7 @@ public: void set_max_time(double p_max_time); double get_max_time() const { return max_time; } - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_AWAIT_ANIMATION \ No newline at end of file diff --git a/bt/actions/bt_call_method.cpp b/bt/actions/bt_call_method.cpp index 40d70fe..ae4fa5d 100644 --- a/bt/actions/bt_call_method.cpp +++ b/bt/actions/bt_call_method.cpp @@ -33,17 +33,17 @@ void BTCallMethod::set_args(Array p_args) { //**** Task Implementation -String BTCallMethod::get_configuration_warning() const { - String warnings = BTAction::get_configuration_warning(); +PackedStringArray BTCallMethod::get_configuration_warnings() const { + PackedStringArray warnings = BTAction::get_configuration_warnings(); if (method_name == StringName()) { - warnings += "Method Name is not set.\n"; + warnings.append("Method Name is not set."); } if (node_param.is_null()) { - warnings += "Node parameter is not set.\n"; + warnings.append("Node parameter is not set."); } else if (node_param->get_value_source() == BBParam::SAVED_VALUE && node_param->get_saved_value().is_zero()) { - warnings += "Path to node is not set.\n"; + warnings.append("Path to node is not set."); } else if (node_param->get_value_source() == BBParam::BLACKBOARD_VAR && node_param->get_variable() == StringName()) { - warnings += "Node blackboard variable is not set.\n"; + warnings.append("Node blackboard variable is not set."); } return warnings; } diff --git a/bt/actions/bt_call_method.h b/bt/actions/bt_call_method.h index e777d14..4d7eba6 100644 --- a/bt/actions/bt_call_method.h +++ b/bt/actions/bt_call_method.h @@ -40,7 +40,7 @@ public: void set_args(Array p_args); Array get_args() const { return args; } - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_CALL_METHOD \ No newline at end of file diff --git a/bt/actions/bt_console_print.cpp b/bt/actions/bt_console_print.cpp index 3bc90ae..6dbcd2a 100644 --- a/bt/actions/bt_console_print.cpp +++ b/bt/actions/bt_console_print.cpp @@ -66,15 +66,12 @@ int BTConsolePrint::_tick(double p_delta) { return SUCCESS; } -String BTConsolePrint::get_configuration_warning() const { - String warning = BTAction::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTConsolePrint::get_configuration_warnings() const { + PackedStringArray warnings = BTAction::get_configuration_warnings(); if (bb_format_parameters.size() > 5) { - warning += "ConsolePrint supports up to 5 format arguments.\n"; + warnings.append("ConsolePrint supports up to 5 format arguments."); } - return warning; + return warnings; } void BTConsolePrint::_bind_methods() { diff --git a/bt/actions/bt_console_print.h b/bt/actions/bt_console_print.h index c5f2ce7..98080e7 100644 --- a/bt/actions/bt_console_print.h +++ b/bt/actions/bt_console_print.h @@ -43,7 +43,7 @@ public: } PackedStringArray get_bb_format_parameters() const { return bb_format_parameters; } - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_CONSOLE_PRINT_H \ No newline at end of file diff --git a/bt/actions/bt_pause_animation.cpp b/bt/actions/bt_pause_animation.cpp index ee1b142..9a45a30 100644 --- a/bt/actions/bt_pause_animation.cpp +++ b/bt/actions/bt_pause_animation.cpp @@ -23,23 +23,18 @@ void BTPauseAnimation::set_animation_player(Ref p_animation_player) { //**** Task Implementation -String BTPauseAnimation::get_configuration_warning() const { - String warning = BTAction::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } - +PackedStringArray BTPauseAnimation::get_configuration_warnings() const { + PackedStringArray warnings = BTAction::get_configuration_warnings(); if (animation_player_param.is_null()) { - warning += "Animation Player parameter is not set.\n"; + warnings.append("Animation Player parameter is not set."); } else { if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) { - warning += "Path to AnimationPlayer node is not set.\n"; + warnings.append("Path to AnimationPlayer node is not set."); } else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) { - warning += "AnimationPlayer blackboard variable is not set.\n"; + warnings.append("AnimationPlayer blackboard variable is not set."); } } - - return warning; + return warnings; } String BTPauseAnimation::_generate_name() const { diff --git a/bt/actions/bt_pause_animation.h b/bt/actions/bt_pause_animation.h index a54a436..b355339 100644 --- a/bt/actions/bt_pause_animation.h +++ b/bt/actions/bt_pause_animation.h @@ -38,7 +38,7 @@ public: void set_animation_player(Ref p_animation_player); Ref get_animation_player() const { return animation_player_param; } - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_PAUSE_ANIMATION diff --git a/bt/actions/bt_play_animation.cpp b/bt/actions/bt_play_animation.cpp index c37e0d1..a37fe46 100644 --- a/bt/actions/bt_play_animation.cpp +++ b/bt/actions/bt_play_animation.cpp @@ -50,26 +50,21 @@ void BTPlayAnimation::set_from_end(bool p_from_end) { //**** Task Implementation -String BTPlayAnimation::get_configuration_warning() const { - String warning = BTAction::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } - +PackedStringArray BTPlayAnimation::get_configuration_warnings() const { + PackedStringArray warnings = BTAction::get_configuration_warnings(); if (animation_player_param.is_null()) { - warning += "Animation Player parameter is not set.\n"; + warnings.append("Animation Player parameter is not set."); } else { if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) { - warning += "Path to AnimationPlayer node is not set.\n"; + warnings.append("Path to AnimationPlayer node is not set."); } else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) { - warning += "AnimationPlayer blackboard variable is not set.\n"; + warnings.append("AnimationPlayer blackboard variable is not set."); } } if (animation_name == StringName() && await_completion > 0.0) { - warning += "Animation Name is required in order to wait for the animation to finish.\n"; + warnings.append("Animation Name is required in order to wait for the animation to finish."); } - - return warning; + return warnings; } String BTPlayAnimation::_generate_name() const { diff --git a/bt/actions/bt_play_animation.h b/bt/actions/bt_play_animation.h index eb25908..2dd1860 100644 --- a/bt/actions/bt_play_animation.h +++ b/bt/actions/bt_play_animation.h @@ -59,7 +59,7 @@ public: void set_from_end(bool p_from_end); bool get_from_end() const { return from_end; } - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_PLAY_ANIMATION \ No newline at end of file diff --git a/bt/actions/bt_set_agent_property.cpp b/bt/actions/bt_set_agent_property.cpp index f46c49f..5288c65 100644 --- a/bt/actions/bt_set_agent_property.cpp +++ b/bt/actions/bt_set_agent_property.cpp @@ -24,18 +24,15 @@ void BTSetAgentProperty::set_value(Ref p_value) { } } -String BTSetAgentProperty::get_configuration_warning() const { - String warning = BTAction::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTSetAgentProperty::get_configuration_warnings() const { + PackedStringArray warnings = BTAction::get_configuration_warnings(); if (property == StringName()) { - warning += "`property` should be assigned.\n"; + warnings.append("`property` should be assigned."); } if (!value.is_valid()) { - warning += "`value` should be assigned.\n"; + warnings.append("`value` should be assigned."); } - return warning; + return warnings; } String BTSetAgentProperty::_generate_name() const { diff --git a/bt/actions/bt_set_agent_property.h b/bt/actions/bt_set_agent_property.h index 503d1e2..b229e6d 100644 --- a/bt/actions/bt_set_agent_property.h +++ b/bt/actions/bt_set_agent_property.h @@ -33,7 +33,7 @@ protected: virtual int _tick(double p_delta) override; public: - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; void set_property(StringName p_prop); StringName get_property() const { return property; } diff --git a/bt/actions/bt_set_var.cpp b/bt/actions/bt_set_var.cpp index 561dc7e..f633f83 100644 --- a/bt/actions/bt_set_var.cpp +++ b/bt/actions/bt_set_var.cpp @@ -43,18 +43,15 @@ void BTSetVar::set_value(Ref p_value) { } } -String BTSetVar::get_configuration_warning() const { - String warning = BTAction::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTSetVar::get_configuration_warnings() const { + PackedStringArray warnings = BTAction::get_configuration_warnings(); if (variable.is_empty()) { - warning += "`variable` should be assigned.\n"; + warnings.append("`variable` should be assigned."); } if (!value.is_valid()) { - warning += "`value` should be assigned.\n"; + warnings.append("`value` should be assigned."); } - return warning; + return warnings; } void BTSetVar::_bind_methods() { diff --git a/bt/actions/bt_set_var.h b/bt/actions/bt_set_var.h index f2f679f..84c7c38 100644 --- a/bt/actions/bt_set_var.h +++ b/bt/actions/bt_set_var.h @@ -34,7 +34,7 @@ protected: virtual int _tick(double p_delta) override; public: - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; void set_variable(const String &p_variable); String get_variable() const { return variable; } diff --git a/bt/actions/bt_stop_animation.cpp b/bt/actions/bt_stop_animation.cpp index 60da2ec..636375f 100644 --- a/bt/actions/bt_stop_animation.cpp +++ b/bt/actions/bt_stop_animation.cpp @@ -33,23 +33,18 @@ void BTStopAnimation::set_keep_state(bool p_keep_state) { //**** Task Implementation -String BTStopAnimation::get_configuration_warning() const { - String warning = BTAction::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } - +PackedStringArray BTStopAnimation::get_configuration_warnings() const { + PackedStringArray warnings = BTAction::get_configuration_warnings(); if (animation_player_param.is_null()) { - warning += "Animation Player parameter is not set.\n"; + warnings.append("Animation Player parameter is not set."); } else { if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) { - warning += "Path to AnimationPlayer node is not set.\n"; + warnings.append("Path to AnimationPlayer node is not set."); } else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) { - warning += "AnimationPlayer blackboard variable is not set.\n"; + warnings.append("AnimationPlayer blackboard variable is not set."); } } - - return warning; + return warnings; } String BTStopAnimation::_generate_name() const { diff --git a/bt/actions/bt_stop_animation.h b/bt/actions/bt_stop_animation.h index 2f9b7cd..6a92f93 100644 --- a/bt/actions/bt_stop_animation.h +++ b/bt/actions/bt_stop_animation.h @@ -46,7 +46,7 @@ public: void set_keep_state(bool p_keep_state); bool get_keep_state() const { return keep_state; } - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_STOP_ANIMATION \ No newline at end of file diff --git a/bt/bt_task.cpp b/bt/bt_task.cpp index 6d4bea1..f3cc2fe 100644 --- a/bt/bt_task.cpp +++ b/bt/bt_task.cpp @@ -251,12 +251,15 @@ Ref BTTask::next_sibling() const { return Ref(); } -String BTTask::get_configuration_warning() const { - String warning = ""; +PackedStringArray BTTask::get_configuration_warnings() const { + PackedStringArray ret; - GDVIRTUAL_CALL(_get_configuration_warning, warning); + PackedStringArray warnings; + if (GDVIRTUAL_CALL(_get_configuration_warning, warnings)) { + ret.append_array(warnings); + } - return warning; + return ret; } void BTTask::print_tree(int p_initial_tabs) const { diff --git a/bt/bt_task.h b/bt/bt_task.h index a1e64a4..d21ae79 100644 --- a/bt/bt_task.h +++ b/bt/bt_task.h @@ -65,7 +65,7 @@ protected: GDVIRTUAL0(_enter); GDVIRTUAL0(_exit); GDVIRTUAL1R(int, _tick, double); - GDVIRTUAL0RC(String, _get_configuration_warning); + GDVIRTUAL0RC(PackedStringArray, _get_configuration_warning); public: virtual bool editor_can_reload_from_file() override { return false; } @@ -84,7 +84,7 @@ public: virtual Ref clone() const; virtual void initialize(Node *p_agent, const Ref &p_blackboard); - virtual String get_configuration_warning() const; + virtual PackedStringArray get_configuration_warnings() const; int execute(double p_delta); void cancel(); diff --git a/bt/composites/bt_composite.cpp b/bt/composites/bt_composite.cpp index a40af18..2fb35c9 100644 --- a/bt/composites/bt_composite.cpp +++ b/bt/composites/bt_composite.cpp @@ -11,13 +11,10 @@ #include "bt_composite.h" -String BTComposite::get_configuration_warning() const { - String warning = BTTask::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTComposite::get_configuration_warnings() const { + PackedStringArray warnings = BTTask::get_configuration_warnings(); if (get_child_count() < 1) { - warning += "Composite should have at least one child task.\n"; + warnings.append("Composite should have at least one child task."); } - return warning; -} \ No newline at end of file + return warnings; +} diff --git a/bt/composites/bt_composite.h b/bt/composites/bt_composite.h index 9025175..56beb13 100644 --- a/bt/composites/bt_composite.h +++ b/bt/composites/bt_composite.h @@ -20,7 +20,7 @@ class BTComposite : public BTTask { GDCLASS(BTComposite, BTTask); public: - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_COMPOSITE_H \ No newline at end of file diff --git a/bt/conditions/bt_check_agent_property.cpp b/bt/conditions/bt_check_agent_property.cpp index 0acb61c..ac219a1 100644 --- a/bt/conditions/bt_check_agent_property.cpp +++ b/bt/conditions/bt_check_agent_property.cpp @@ -33,18 +33,15 @@ void BTCheckAgentProperty::set_value(Ref p_value) { } } -String BTCheckAgentProperty::get_configuration_warning() const { - String warning = BTCondition::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTCheckAgentProperty::get_configuration_warnings() const { + PackedStringArray warnings = BTCondition::get_configuration_warnings(); if (property == StringName()) { - warning += "`property` should be assigned.\n"; + warnings.append("`property` should be assigned."); } if (!value.is_valid()) { - warning += "`value` should be assigned.\n"; + warnings.append("`value` should be assigned."); } - return warning; + return warnings; } String BTCheckAgentProperty::_generate_name() const { diff --git a/bt/conditions/bt_check_agent_property.h b/bt/conditions/bt_check_agent_property.h index 2c1f10d..e488f26 100644 --- a/bt/conditions/bt_check_agent_property.h +++ b/bt/conditions/bt_check_agent_property.h @@ -35,8 +35,6 @@ protected: virtual int _tick(double p_delta) override; public: - virtual String get_configuration_warning() const override; - void set_property(StringName p_prop); StringName get_property() const { return property; } @@ -45,6 +43,8 @@ public: void set_value(Ref p_value); Ref get_value() const { return value; } + + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_CHECK_AGENT_PROPERTY \ No newline at end of file diff --git a/bt/conditions/bt_check_trigger.cpp b/bt/conditions/bt_check_trigger.cpp index 517bd19..db7199d 100644 --- a/bt/conditions/bt_check_trigger.cpp +++ b/bt/conditions/bt_check_trigger.cpp @@ -11,6 +11,7 @@ #include "bt_check_trigger.h" +#include "bt_condition.h" #include "modules/limboai/util/limbo_utility.h" #include "core/variant/variant.h" @@ -20,6 +21,14 @@ void BTCheckTrigger::set_variable(String p_variable) { emit_changed(); } +PackedStringArray BTCheckTrigger::get_configuration_warnings() const { + PackedStringArray warnings = BTCondition::get_configuration_warnings(); + if (variable.is_empty()) { + warnings.append("Variable is not set."); + } + return warnings; +} + String BTCheckTrigger::_generate_name() const { if (variable.is_empty()) { return "CheckTrigger ???"; diff --git a/bt/conditions/bt_check_trigger.h b/bt/conditions/bt_check_trigger.h index aed4cc7..3064644 100644 --- a/bt/conditions/bt_check_trigger.h +++ b/bt/conditions/bt_check_trigger.h @@ -36,6 +36,8 @@ protected: public: void set_variable(String p_variable); String get_variable() const { return variable; } + + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_CHECK_TRIGGER \ No newline at end of file diff --git a/bt/conditions/bt_check_var.cpp b/bt/conditions/bt_check_var.cpp index 86c141b..4f2a120 100644 --- a/bt/conditions/bt_check_var.cpp +++ b/bt/conditions/bt_check_var.cpp @@ -33,18 +33,15 @@ void BTCheckVar::set_value(Ref p_value) { } } -String BTCheckVar::get_configuration_warning() const { - String warning = BTCondition::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTCheckVar::get_configuration_warnings() const { + PackedStringArray warnings = BTCondition::get_configuration_warnings(); if (variable.is_empty()) { - warning += "`variable` should be assigned.\n"; + warnings.append("`variable` should be assigned."); } if (!value.is_valid()) { - warning += "`value` should be assigned.\n"; + warnings.append("`value` should be assigned."); } - return warning; + return warnings; } String BTCheckVar::_generate_name() const { diff --git a/bt/conditions/bt_check_var.h b/bt/conditions/bt_check_var.h index 1268ea4..0a2c0fb 100644 --- a/bt/conditions/bt_check_var.h +++ b/bt/conditions/bt_check_var.h @@ -17,9 +17,6 @@ #include "modules/limboai/blackboard/bb_param/bb_variant.h" #include "modules/limboai/util/limbo_utility.h" -#include "core/object/class_db.h" -#include "core/object/object.h" - class BTCheckVar : public BTCondition { GDCLASS(BTCheckVar, BTCondition); @@ -35,7 +32,7 @@ protected: virtual int _tick(double p_delta) override; public: - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; void set_variable(String p_variable); String get_variable() const { return variable; } diff --git a/bt/conditions/bt_condition.cpp b/bt/conditions/bt_condition.cpp index a61f408..904f8ee 100644 --- a/bt/conditions/bt_condition.cpp +++ b/bt/conditions/bt_condition.cpp @@ -11,13 +11,10 @@ #include "bt_condition.h" -String BTCondition::get_configuration_warning() const { - String warning = BTTask::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTCondition::get_configuration_warnings() const { + PackedStringArray warnings = BTTask::get_configuration_warnings(); if (get_child_count() != 0) { - warning += "Condition task can't have child tasks.\n"; + warnings.append("Condition task can't have child tasks."); } - return warning; -} \ No newline at end of file + return warnings; +} diff --git a/bt/conditions/bt_condition.h b/bt/conditions/bt_condition.h index df071a0..fe8cc3b 100644 --- a/bt/conditions/bt_condition.h +++ b/bt/conditions/bt_condition.h @@ -20,7 +20,7 @@ class BTCondition : public BTTask { GDCLASS(BTCondition, BTTask); public: - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_CONDITION_H \ No newline at end of file diff --git a/bt/decorators/bt_cooldown.cpp b/bt/decorators/bt_cooldown.cpp index e84396c..77cd179 100644 --- a/bt/decorators/bt_cooldown.cpp +++ b/bt/decorators/bt_cooldown.cpp @@ -16,6 +16,35 @@ #include "core/variant/array.h" #include "scene/main/scene_tree.h" +//**** Setters / Getters + +void BTCooldown::set_duration(double p_value) { + duration = p_value; + emit_changed(); +} + +void BTCooldown::set_process_pause(bool p_value) { + process_pause = p_value; + emit_changed(); +} + +void BTCooldown::set_start_cooled(bool p_value) { + start_cooled = p_value; + emit_changed(); +} + +void BTCooldown::set_trigger_on_failure(bool p_value) { + trigger_on_failure = p_value; + emit_changed(); +} + +void BTCooldown::set_cooldown_state_var(String p_value) { + cooldown_state_var = p_value; + emit_changed(); +} + +//**** Task Implementation + String BTCooldown::_generate_name() const { return vformat("Cooldown %s sec", Math::snapped(duration, 0.001)); } @@ -57,6 +86,8 @@ void BTCooldown::_on_timeout() { timer.unref(); } +//**** Godot + void BTCooldown::_bind_methods() { ClassDB::bind_method(D_METHOD("set_duration", "p_value"), &BTCooldown::set_duration); ClassDB::bind_method(D_METHOD("get_duration"), &BTCooldown::get_duration); diff --git a/bt/decorators/bt_cooldown.h b/bt/decorators/bt_cooldown.h index dc06898..6695bdc 100644 --- a/bt/decorators/bt_cooldown.h +++ b/bt/decorators/bt_cooldown.h @@ -40,30 +40,19 @@ protected: virtual int _tick(double p_delta) override; public: - void set_duration(double p_value) { - duration = p_value; - emit_changed(); - } + void set_duration(double p_value); double get_duration() const { return duration; } - void set_process_pause(bool p_value) { - process_pause = p_value; - emit_changed(); - } + + void set_process_pause(bool p_value); bool get_process_pause() const { return process_pause; } - void set_start_cooled(bool p_value) { - start_cooled = p_value; - emit_changed(); - } + + void set_start_cooled(bool p_value); bool get_start_cooled() const { return start_cooled; } - void set_trigger_on_failure(bool p_value) { - trigger_on_failure = p_value; - emit_changed(); - } + + void set_trigger_on_failure(bool p_value); bool get_trigger_on_failure() const { return trigger_on_failure; } - void set_cooldown_state_var(String p_value) { - cooldown_state_var = p_value; - emit_changed(); - } + + void set_cooldown_state_var(String p_value); String get_cooldown_state_var() const { return cooldown_state_var; } }; diff --git a/bt/decorators/bt_decorator.cpp b/bt/decorators/bt_decorator.cpp index d8a8470..b887b6d 100644 --- a/bt/decorators/bt_decorator.cpp +++ b/bt/decorators/bt_decorator.cpp @@ -11,13 +11,10 @@ #include "bt_decorator.h" -String BTDecorator::get_configuration_warning() const { - String warning = BTTask::get_configuration_warning(); - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTDecorator::get_configuration_warnings() const { + PackedStringArray warnings = BTTask::get_configuration_warnings(); if (get_child_count() != 1) { - warning += "Decorator should have a single child task.\n"; + warnings.append("Decorator should have a single child task."); } - return warning; + return warnings; } diff --git a/bt/decorators/bt_decorator.h b/bt/decorators/bt_decorator.h index 30fd18a..aba047f 100644 --- a/bt/decorators/bt_decorator.h +++ b/bt/decorators/bt_decorator.h @@ -20,7 +20,7 @@ class BTDecorator : public BTTask { GDCLASS(BTDecorator, BTTask) public: - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_DECORATOR_H \ No newline at end of file diff --git a/bt/decorators/bt_delay.cpp b/bt/decorators/bt_delay.cpp index 4a6a958..99e43c6 100644 --- a/bt/decorators/bt_delay.cpp +++ b/bt/decorators/bt_delay.cpp @@ -18,6 +18,11 @@ #include "core/variant/array.h" #include "core/variant/variant.h" +void BTDelay::set_seconds(double p_value) { + seconds = p_value; + emit_changed(); +} + String BTDelay::_generate_name() const { return vformat("Delay %s sec", Math::snapped(seconds, 0.001)); } diff --git a/bt/decorators/bt_delay.h b/bt/decorators/bt_delay.h index 411d8d1..227a7fd 100644 --- a/bt/decorators/bt_delay.h +++ b/bt/decorators/bt_delay.h @@ -29,10 +29,7 @@ protected: virtual int _tick(double p_delta) override; public: - void set_seconds(double p_value) { - seconds = p_value; - emit_changed(); - } + void set_seconds(double p_value); double get_seconds() const { return seconds; } }; diff --git a/bt/decorators/bt_for_each.cpp b/bt/decorators/bt_for_each.cpp index 8ba1a55..e0fc28b 100644 --- a/bt/decorators/bt_for_each.cpp +++ b/bt/decorators/bt_for_each.cpp @@ -18,6 +18,20 @@ #include "core/error/error_macros.h" #include "core/variant/variant.h" +//**** Setters / Getters + +void BTForEach::set_array_var(String p_value) { + array_var = p_value; + emit_changed(); +} + +void BTForEach::set_save_var(String p_value) { + save_var = p_value; + emit_changed(); +} + +//**** Task Implementation + String BTForEach::_generate_name() const { return vformat("ForEach %s in %s", LimboUtility::get_singleton()->decorate_var(save_var), @@ -53,6 +67,8 @@ int BTForEach::_tick(double p_delta) { } } +//**** Godot + void BTForEach::_bind_methods() { ClassDB::bind_method(D_METHOD("set_array_var", "p_variable"), &BTForEach::set_array_var); ClassDB::bind_method(D_METHOD("get_array_var"), &BTForEach::get_array_var); diff --git a/bt/decorators/bt_for_each.h b/bt/decorators/bt_for_each.h index b83ffd1..a22cc01 100644 --- a/bt/decorators/bt_for_each.h +++ b/bt/decorators/bt_for_each.h @@ -33,15 +33,10 @@ protected: virtual int _tick(double p_delta) override; public: - void set_array_var(String p_value) { - array_var = p_value; - emit_changed(); - } + void set_array_var(String p_value); String get_array_var() const { return array_var; } - void set_save_var(String p_value) { - save_var = p_value; - emit_changed(); - } + + void set_save_var(String p_value); String get_save_var() const { return save_var; } }; diff --git a/bt/decorators/bt_probability.cpp b/bt/decorators/bt_probability.cpp index 1c14758..e3932fe 100644 --- a/bt/decorators/bt_probability.cpp +++ b/bt/decorators/bt_probability.cpp @@ -11,7 +11,10 @@ #include "bt_probability.h" -#include "core/object/object.h" +void BTProbability::set_run_chance(float p_value) { + run_chance = p_value; + emit_changed(); +} String BTProbability::_generate_name() const { return vformat("Probability %.1f%%", run_chance); diff --git a/bt/decorators/bt_probability.h b/bt/decorators/bt_probability.h index 05727ca..9727ef0 100644 --- a/bt/decorators/bt_probability.h +++ b/bt/decorators/bt_probability.h @@ -14,8 +14,6 @@ #include "bt_decorator.h" -#include "core/object/object.h" - class BTProbability : public BTDecorator { GDCLASS(BTProbability, BTDecorator); @@ -29,10 +27,7 @@ protected: virtual int _tick(double p_delta) override; public: - void set_run_chance(float p_value) { - run_chance = p_value; - emit_changed(); - } + void set_run_chance(float p_value); float get_run_chance() const { return run_chance; } }; diff --git a/bt/decorators/bt_run_limit.cpp b/bt/decorators/bt_run_limit.cpp index dfaa8c7..3805356 100644 --- a/bt/decorators/bt_run_limit.cpp +++ b/bt/decorators/bt_run_limit.cpp @@ -11,6 +11,11 @@ #include "bt_run_limit.h" +void BTRunLimit::set_run_limit(int p_value) { + run_limit = p_value; + emit_changed(); +} + String BTRunLimit::_generate_name() const { return vformat("RunLimit x%d", run_limit); } diff --git a/bt/decorators/bt_run_limit.h b/bt/decorators/bt_run_limit.h index 5ffebb9..f747252 100644 --- a/bt/decorators/bt_run_limit.h +++ b/bt/decorators/bt_run_limit.h @@ -14,8 +14,6 @@ #include "bt_decorator.h" -#include "core/object/object.h" - class BTRunLimit : public BTDecorator { GDCLASS(BTRunLimit, BTDecorator); @@ -30,10 +28,7 @@ protected: virtual int _tick(double p_delta) override; public: - void set_run_limit(int p_value) { - run_limit = p_value; - emit_changed(); - } + void set_run_limit(int p_value); int get_run_limit() const { return run_limit; } }; diff --git a/bt/decorators/bt_subtree.cpp b/bt/decorators/bt_subtree.cpp index 6ef5891..a6ce46b 100644 --- a/bt/decorators/bt_subtree.cpp +++ b/bt/decorators/bt_subtree.cpp @@ -20,10 +20,14 @@ #include "core/config/engine.h" #include "core/error/error_macros.h" -#include "core/object/object.h" #include "core/typedefs.h" #include "core/variant/variant.h" +void BTSubtree::set_subtree(const Ref &p_value) { + subtree = p_value; + emit_changed(); +} + String BTSubtree::_generate_name() const { String s; if (subtree.is_null()) { @@ -51,15 +55,12 @@ int BTSubtree::_tick(double p_delta) { return get_child(0)->execute(p_delta); } -String BTSubtree::get_configuration_warning() const { - String warning = BTTask::get_configuration_warning(); // BTDecorator skipped intentionally - if (!warning.is_empty()) { - warning += "\n"; - } +PackedStringArray BTSubtree::get_configuration_warnings() const { + PackedStringArray warnings = BTTask::get_configuration_warnings(); // ! BTDecorator skipped intentionally if (subtree.is_null()) { - warning += "Subtree needs to be assigned.\n"; + warnings.append("Subtree needs to be assigned."); } - return warning; + return warnings; } void BTSubtree::_bind_methods() { @@ -67,4 +68,4 @@ void BTSubtree::_bind_methods() { ClassDB::bind_method(D_METHOD("get_subtree"), &BTSubtree::get_subtree); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "subtree", PROPERTY_HINT_RESOURCE_TYPE, "BehaviorTree"), "set_subtree", "get_subtree"); -} \ No newline at end of file +} diff --git a/bt/decorators/bt_subtree.h b/bt/decorators/bt_subtree.h index 6f3db3f..edddc7e 100644 --- a/bt/decorators/bt_subtree.h +++ b/bt/decorators/bt_subtree.h @@ -13,9 +13,8 @@ #define BT_SUBTREE_H #include "bt_new_scope.h" -#include "modules/limboai/bt/behavior_tree.h" -#include "core/object/object.h" +#include "modules/limboai/bt/behavior_tree.h" class BTSubtree : public BTNewScope { GDCLASS(BTSubtree, BTNewScope); @@ -30,14 +29,11 @@ protected: virtual int _tick(double p_delta) override; public: - void set_subtree(const Ref &p_value) { - subtree = p_value; - emit_changed(); - } + void set_subtree(const Ref &p_value); Ref get_subtree() const { return subtree; } virtual void initialize(Node *p_agent, const Ref &p_blackboard) override; - virtual String get_configuration_warning() const override; + virtual PackedStringArray get_configuration_warnings() const override; }; #endif // BT_SUBTREE_H \ No newline at end of file diff --git a/bt/decorators/bt_time_limit.cpp b/bt/decorators/bt_time_limit.cpp index 32dbc1b..3212e65 100644 --- a/bt/decorators/bt_time_limit.cpp +++ b/bt/decorators/bt_time_limit.cpp @@ -13,6 +13,11 @@ #include "core/math/math_funcs.h" +void BTTimeLimit::set_time_limit(double p_value) { + time_limit = p_value; + emit_changed(); +} + String BTTimeLimit::_generate_name() const { return vformat("TimeLimit %s sec", Math::snapped(time_limit, 0.001)); } diff --git a/bt/decorators/bt_time_limit.h b/bt/decorators/bt_time_limit.h index 47140dc..730ffd5 100644 --- a/bt/decorators/bt_time_limit.h +++ b/bt/decorators/bt_time_limit.h @@ -29,10 +29,7 @@ protected: virtual int _tick(double p_delta) override; public: - void set_time_limit(double p_value) { - time_limit = p_value; - emit_changed(); - } + void set_time_limit(double p_value); double get_time_limit() const { return time_limit; } }; diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 86f7ba1..5b78261 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -107,9 +107,17 @@ void TaskTree::_update_item(TreeItem *p_item) { for (int i = 0; i < p_item->get_button_count(0); i++) { p_item->erase_button(0, i); } - String warning = task->get_configuration_warning(); - if (!warning.is_empty()) { - p_item->add_button(0, get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons")), 0, false, warning); + + PackedStringArray warnings = task->get_configuration_warnings(); + String warning_text; + for (int j = 0; j < warnings.size(); j++) { + if (j > 0) { + warning_text += "\n"; + } + warning_text += warnings[j]; + } + if (!warning_text.is_empty()) { + p_item->add_button(0, get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons")), 0, false, warning_text); } // TODO: Update probabilities.