2022-08-28 12:49:02 +00:00
|
|
|
/* bt_repeat.cpp */
|
|
|
|
|
|
|
|
#include "bt_repeat.h"
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/object/object.h"
|
|
|
|
#include "core/variant/variant.h"
|
2022-08-28 12:49:02 +00:00
|
|
|
|
|
|
|
String BTRepeat::_generate_name() const {
|
|
|
|
return vformat("Repeat x%s", times);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BTRepeat::_enter() {
|
2022-12-17 10:47:10 +00:00
|
|
|
cur_iteration = 1;
|
2022-08-28 12:49:02 +00:00
|
|
|
}
|
|
|
|
|
2023-04-10 08:08:11 +00:00
|
|
|
int BTRepeat::_tick(double p_delta) {
|
2022-09-21 10:37:19 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
|
2022-08-28 12:49:02 +00:00
|
|
|
int status = get_child(0)->execute(p_delta);
|
|
|
|
if (status == RUNNING) {
|
|
|
|
return RUNNING;
|
|
|
|
} else if (status == FAILURE && abort_on_failure) {
|
|
|
|
return FAILURE;
|
2022-12-17 10:47:10 +00:00
|
|
|
} else if (cur_iteration >= times) {
|
2022-08-28 12:49:02 +00:00
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
2022-12-17 10:47:10 +00:00
|
|
|
cur_iteration += 1;
|
2022-08-28 12:49:02 +00:00
|
|
|
return RUNNING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BTRepeat::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_times", "p_value"), &BTRepeat::set_times);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_times"), &BTRepeat::get_times);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_abort_on_failure", "p_value"), &BTRepeat::set_abort_on_failure);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_abort_on_failure"), &BTRepeat::get_abort_on_failure);
|
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "times", PROPERTY_HINT_RANGE, "1,65535"), "set_times", "get_times");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "abort_on_failure"), "set_abort_on_failure", "get_abort_on_failure");
|
|
|
|
}
|