Don't count BTComment tasks for configuration warnings

This commit is contained in:
Serhii Snitsaruk 2023-08-19 12:19:58 +02:00
parent 17c72b7378
commit 0ae2b6869a
7 changed files with 19 additions and 5 deletions

View File

@ -13,7 +13,7 @@
PackedStringArray BTAction::get_configuration_warnings() const {
PackedStringArray warnings = BTTask::get_configuration_warnings();
if (get_child_count() != 0) {
if (get_child_count_excluding_comments() != 0) {
warnings.append("Action can't have child tasks.");
}
return warnings;

View File

@ -13,7 +13,7 @@
PackedStringArray BTComposite::get_configuration_warnings() const {
PackedStringArray warnings = BTTask::get_configuration_warnings();
if (get_child_count() < 1) {
if (get_child_count_excluding_comments() < 1) {
warnings.append("Composite should have at least one child task.");
}
return warnings;

View File

@ -13,7 +13,7 @@
PackedStringArray BTCondition::get_configuration_warnings() const {
PackedStringArray warnings = BTTask::get_configuration_warnings();
if (get_child_count() != 0) {
if (get_child_count_excluding_comments() != 0) {
warnings.append("Condition task can't have child tasks.");
}
return warnings;

View File

@ -13,7 +13,7 @@
PackedStringArray BTDecorator::get_configuration_warnings() const {
PackedStringArray warnings = BTTask::get_configuration_warnings();
if (get_child_count() != 1) {
if (get_child_count_excluding_comments() != 1) {
warnings.append("Decorator should have a single child task.");
}
return warnings;

View File

@ -11,6 +11,7 @@
#include "bt_task.h"
#include "bt_comment.h"
#include "modules/limboai/blackboard/blackboard.h"
#include "modules/limboai/util/limbo_string_names.h"
#include "modules/limboai/util/limbo_utility.h"
@ -198,6 +199,16 @@ int BTTask::get_child_count() const {
return data.children.size();
}
int BTTask::get_child_count_excluding_comments() const {
int count = 0;
for (int i = 0; i < data.children.size(); i++) {
if (!data.children[i]->is_class_ptr(BTComment::get_class_ptr_static())) {
count += 1;
}
}
return count;
}
void BTTask::add_child(Ref<BTTask> p_child) {
ERR_FAIL_COND_MSG(p_child->get_parent().is_valid(), "p_child already has a parent!");
p_child->data.parent = this;
@ -291,6 +302,7 @@ void BTTask::_bind_methods() {
ClassDB::bind_method(D_METHOD("execute", "p_delta"), &BTTask::execute);
ClassDB::bind_method(D_METHOD("get_child", "p_idx"), &BTTask::get_child);
ClassDB::bind_method(D_METHOD("get_child_count"), &BTTask::get_child_count);
ClassDB::bind_method(D_METHOD("get_child_count_excluding_comments"), &BTTask::get_child_count_excluding_comments);
ClassDB::bind_method(D_METHOD("add_child", "p_child"), &BTTask::add_child);
ClassDB::bind_method(D_METHOD("add_child_at_index", "p_child", "p_idx"), &BTTask::add_child_at_index);
ClassDB::bind_method(D_METHOD("remove_child", "p_child"), &BTTask::remove_child);

View File

@ -93,6 +93,7 @@ public:
Ref<BTTask> get_child(int p_idx) const;
int get_child_count() const;
int get_child_count_excluding_comments() const;
void add_child(Ref<BTTask> p_child);
void add_child_at_index(Ref<BTTask> p_child, int p_idx);
void remove_child(Ref<BTTask> p_child);

View File

@ -15,6 +15,7 @@
#include "modules/limboai/bt/behavior_tree.h"
#include "modules/limboai/bt/tasks/bt_action.h"
#include "modules/limboai/bt/tasks/bt_comment.h"
#include "modules/limboai/bt/tasks/bt_task.h"
#include "modules/limboai/bt/tasks/composites/bt_parallel.h"
#include "modules/limboai/bt/tasks/composites/bt_selector.h"
@ -94,7 +95,7 @@ void TaskTree::_update_item(TreeItem *p_item) {
Ref<BTTask> task = p_item->get_metadata(0);
ERR_FAIL_COND_MSG(!task.is_valid(), "Invalid task reference in metadata.");
p_item->set_text(0, task->get_task_name());
if (task->is_class("BTComment")) {
if (task->is_class_ptr(BTComment::get_class_ptr_static())) {
p_item->set_custom_font(0, (get_theme_font(SNAME("doc_italic"), SNAME("EditorFonts"))));
p_item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
} else if (task->get_custom_name().is_empty()) {