2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* bt_delay.cpp
|
|
|
|
* =============================================================================
|
|
|
|
* Copyright 2021-2023 Serhii Snitsaruk
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2022-08-28 11:56:43 +00:00
|
|
|
|
|
|
|
#include "bt_delay.h"
|
2023-07-20 16:35:36 +00:00
|
|
|
|
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
|
|
|
|
2023-08-15 15:05:30 +00:00
|
|
|
void BTDelay::set_seconds(double p_value) {
|
|
|
|
seconds = p_value;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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.");
|
2023-04-14 08:16:26 +00:00
|
|
|
if (get_elapsed_time() <= seconds) {
|
2022-08-28 11:56:43 +00:00
|
|
|
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
|
|
|
}
|