You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Add set_custom_interpolator() to PropertyTweener
This commit is contained in:
@@ -531,6 +531,11 @@ Ref<PropertyTweener> PropertyTweener::set_ease(Tween::EaseType p_ease) {
|
||||
return this;
|
||||
}
|
||||
|
||||
Ref<PropertyTweener> PropertyTweener::set_custom_interpolator(const Callable &p_method) {
|
||||
custom_method = p_method;
|
||||
return this;
|
||||
}
|
||||
|
||||
Ref<PropertyTweener> PropertyTweener::set_delay(double p_delay) {
|
||||
delay = p_delay;
|
||||
return this;
|
||||
@@ -581,7 +586,23 @@ bool PropertyTweener::step(double &r_delta) {
|
||||
|
||||
double time = MIN(elapsed_time - delay, duration);
|
||||
if (time < duration) {
|
||||
target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type));
|
||||
if (custom_method.is_valid()) {
|
||||
const Variant t = tween->interpolate_variant(0.0, 1.0, time, duration, trans_type, ease_type);
|
||||
const Variant *argptr = &t;
|
||||
|
||||
Variant result;
|
||||
Callable::CallError ce;
|
||||
custom_method.callp(&argptr, 1, result, ce);
|
||||
if (ce.error != Callable::CallError::CALL_OK) {
|
||||
ERR_FAIL_V_MSG(false, "Error calling custom method from PropertyTweener: " + Variant::get_callable_error_text(custom_method, &argptr, 1, ce) + ".");
|
||||
} else if (result.get_type() != Variant::FLOAT) {
|
||||
ERR_FAIL_V_MSG(false, vformat("Wrong return type in PropertyTweener custom method. Expected float, got %s.", Variant::get_type_name(result.get_type())));
|
||||
}
|
||||
|
||||
target_instance->set_indexed(property, Animation::interpolate_variant(initial_val, final_val, result));
|
||||
} else {
|
||||
target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type));
|
||||
}
|
||||
r_delta = 0;
|
||||
return true;
|
||||
} else {
|
||||
@@ -609,6 +630,7 @@ void PropertyTweener::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("as_relative"), &PropertyTweener::as_relative);
|
||||
ClassDB::bind_method(D_METHOD("set_trans", "trans"), &PropertyTweener::set_trans);
|
||||
ClassDB::bind_method(D_METHOD("set_ease", "ease"), &PropertyTweener::set_ease);
|
||||
ClassDB::bind_method(D_METHOD("set_custom_interpolator", "interpolator_method"), &PropertyTweener::set_custom_interpolator);
|
||||
ClassDB::bind_method(D_METHOD("set_delay", "delay"), &PropertyTweener::set_delay);
|
||||
}
|
||||
|
||||
@@ -685,7 +707,7 @@ bool CallbackTweener::step(double &r_delta) {
|
||||
Callable::CallError ce;
|
||||
callback.callp(nullptr, 0, result, ce);
|
||||
if (ce.error != Callable::CallError::CALL_OK) {
|
||||
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;
|
||||
@@ -765,7 +787,7 @@ bool MethodTweener::step(double &r_delta) {
|
||||
Callable::CallError ce;
|
||||
callback.callp(argptr, 1, result, ce);
|
||||
if (ce.error != Callable::CallError::CALL_OK) {
|
||||
ERR_FAIL_V_MSG(false, "Error calling method from MethodTweener: " + Variant::get_callable_error_text(callback, argptr, 1, ce));
|
||||
ERR_FAIL_V_MSG(false, "Error calling method from MethodTweener: " + Variant::get_callable_error_text(callback, argptr, 1, ce) + ".");
|
||||
}
|
||||
|
||||
if (time < duration) {
|
||||
|
||||
Reference in New Issue
Block a user