package speiger.src.coreengine.ui.gui.animation.actions;

import speiger.src.collections.objects.functions.consumer.ObjectFloatConsumer;
import speiger.src.collections.objects.functions.function.ToFloatFunction;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.easing.IEasing;
import speiger.src.coreengine.ui.gui.animation.GuiAnimation.Target;
import speiger.src.coreengine.ui.gui.animation.IAction;

public class EasedAction implements IAction {
	float duration;
	float targetValue;
	IEasing function;
	
	public EasedAction(float duration, float targetValue, IEasing function) {
		this.duration = duration;
		this.targetValue = targetValue;
		this.function = function;
	}
	
	@Override
	public float duration() { return duration; }
	@Override
	public void apply(Target target, ToFloatFunction<Target> getter, ObjectFloatConsumer<Target> setter, float progress) {
		setter.accept(target, MathUtils.lerp(getter.applyAsFloat(target), targetValue, (float)function.ease(progress, duration)));
	}
}
