Refactor BTTask.get_configuration_warnings()

This commit is contained in:
Serhii Snitsaruk 2023-08-15 17:05:30 +02:00
parent b1aae71f5f
commit 21c65541bf
47 changed files with 217 additions and 215 deletions

View File

@ -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;
}
return warnings;
}

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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() {

View File

@ -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

View File

@ -23,23 +23,18 @@ void BTPauseAnimation::set_animation_player(Ref<BBNode> 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 {

View File

@ -38,7 +38,7 @@ public:
void set_animation_player(Ref<BBNode> p_animation_player);
Ref<BBNode> 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

View File

@ -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 {

View File

@ -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

View File

@ -24,18 +24,15 @@ void BTSetAgentProperty::set_value(Ref<BBVariant> 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 {

View File

@ -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; }

View File

@ -43,18 +43,15 @@ void BTSetVar::set_value(Ref<BBVariant> 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() {

View File

@ -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; }

View File

@ -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 {

View File

@ -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

View File

@ -251,12 +251,15 @@ Ref<BTTask> BTTask::next_sibling() const {
return Ref<BTTask>();
}
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 {

View File

@ -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<BTTask> clone() const;
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard);
virtual String get_configuration_warning() const;
virtual PackedStringArray get_configuration_warnings() const;
int execute(double p_delta);
void cancel();

View File

@ -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;
}
return warnings;
}

View File

@ -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

View File

@ -33,18 +33,15 @@ void BTCheckAgentProperty::set_value(Ref<BBVariant> 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 {

View File

@ -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<BBVariant> p_value);
Ref<BBVariant> get_value() const { return value; }
virtual PackedStringArray get_configuration_warnings() const override;
};
#endif // BT_CHECK_AGENT_PROPERTY

View File

@ -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 ???";

View File

@ -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

View File

@ -33,18 +33,15 @@ void BTCheckVar::set_value(Ref<BBVariant> 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 {

View File

@ -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; }

View File

@ -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;
}
return warnings;
}

View File

@ -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

View File

@ -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);

View File

@ -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; }
};

View File

@ -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;
}

View File

@ -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

View File

@ -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));
}

View File

@ -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; }
};

View File

@ -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);

View File

@ -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; }
};

View File

@ -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);

View File

@ -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; }
};

View File

@ -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);
}

View File

@ -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; }
};

View File

@ -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<BehaviorTree> &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");
}
}

View File

@ -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<BehaviorTree> &p_value) {
subtree = p_value;
emit_changed();
}
void set_subtree(const Ref<BehaviorTree> &p_value);
Ref<BehaviorTree> get_subtree() const { return subtree; }
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) override;
virtual String get_configuration_warning() const override;
virtual PackedStringArray get_configuration_warnings() const override;
};
#endif // BT_SUBTREE_H

View File

@ -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));
}

View File

@ -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; }
};

View File

@ -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.