2022-08-28 11:56:43 +00:00
|
|
|
/* bt_delay.cpp */
|
|
|
|
|
|
|
|
#include "bt_delay.h"
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/error/error_macros.h"
|
2023-04-10 05:54:02 +00:00
|
|
|
#include "core/math/math_funcs.h"
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/object/class_db.h"
|
|
|
|
#include "core/object/object.h"
|
|
|
|
#include "core/variant/array.h"
|
|
|
|
#include "core/variant/variant.h"
|
2022-08-28 11:56:43 +00:00
|
|
|
|
|
|
|
String BTDelay::_generate_name() const {
|
2023-04-10 05:54:02 +00:00
|
|
|
return vformat("Delay %s sec", Math::snapped(seconds, 0.001));
|
2022-08-28 11:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BTDelay::_enter() {
|
|
|
|
time_passed = 0.0;
|
|
|
|
}
|
|
|
|
|
2023-04-10 08:08:11 +00:00
|
|
|
int BTDelay::_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 11:56:43 +00:00
|
|
|
time_passed += p_delta;
|
|
|
|
if (time_passed <= seconds) {
|
|
|
|
return RUNNING;
|
|
|
|
}
|
|
|
|
return get_child(0)->execute(p_delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BTDelay::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_seconds", "p_value"), &BTDelay::set_seconds);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_seconds"), &BTDelay::get_seconds);
|
2022-12-15 07:26:52 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "seconds"), "set_seconds", "get_seconds");
|
2022-08-28 11:56:43 +00:00
|
|
|
}
|