Add internal _finish() method to Tweener

This commit is contained in:
kobewi 2024-08-15 08:41:51 +02:00
parent 33c30b9e63
commit 761d988d47
2 changed files with 10 additions and 8 deletions

View File

@ -61,6 +61,11 @@ Ref<Tween> Tweener::_get_tween() {
return Ref<Tween>(ObjectDB::get_instance(tween_id)); return Ref<Tween>(ObjectDB::get_instance(tween_id));
} }
void Tweener::_finish() {
finished = true;
emit_signal(SceneStringName(finished));
}
void Tweener::_bind_methods() { void Tweener::_bind_methods() {
ADD_SIGNAL(MethodInfo("finished")); ADD_SIGNAL(MethodInfo("finished"));
} }
@ -612,9 +617,8 @@ bool PropertyTweener::step(double &r_delta) {
return true; return true;
} else { } else {
target_instance->set_indexed(property, final_val); target_instance->set_indexed(property, final_val);
finished = true;
r_delta = elapsed_time - delay - duration; r_delta = elapsed_time - delay - duration;
emit_signal(SceneStringName(finished)); _finish();
return false; return false;
} }
} }
@ -672,9 +676,8 @@ bool IntervalTweener::step(double &r_delta) {
r_delta = 0; r_delta = 0;
return true; return true;
} else { } else {
finished = true;
r_delta = elapsed_time - duration; r_delta = elapsed_time - duration;
emit_signal(SceneStringName(finished)); _finish();
return false; return false;
} }
} }
@ -715,9 +718,8 @@ bool CallbackTweener::step(double &r_delta) {
ERR_FAIL_V_MSG(false, "Error calling method from CallbackTweener: " + Variant::get_callable_error_text(callback, nullptr, 0, ce) + "."); ERR_FAIL_V_MSG(false, "Error calling method from CallbackTweener: " + Variant::get_callable_error_text(callback, nullptr, 0, ce) + ".");
} }
finished = true;
r_delta = elapsed_time - delay; r_delta = elapsed_time - delay;
emit_signal(SceneStringName(finished)); _finish();
return false; return false;
} }
@ -801,9 +803,8 @@ bool MethodTweener::step(double &r_delta) {
r_delta = 0; r_delta = 0;
return true; return true;
} else { } else {
finished = true;
r_delta = elapsed_time - delay - duration; r_delta = elapsed_time - delay - duration;
emit_signal(SceneStringName(finished)); _finish();
return false; return false;
} }
} }

View File

@ -50,6 +50,7 @@ protected:
static void _bind_methods(); static void _bind_methods();
Ref<Tween> _get_tween(); Ref<Tween> _get_tween();
void _finish();
double elapsed_time = 0; double elapsed_time = 0;
bool finished = false; bool finished = false;