package speiger.src.coreengine.rendering.guiOld.helper.animations;

import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap;
import speiger.src.collections.objects.utils.maps.Object2ObjectMaps;
import speiger.src.coreengine.math.value.ConstantValue;
import speiger.src.coreengine.math.value.IValue;
import speiger.src.coreengine.rendering.guiOld.helper.animations.Animation.AnimationListener;

public class AnimationInstance
{
	Object2ObjectMap<AnimationTarget, IValue> values;
	float totalProgress;
	boolean reverse;
	AnimationListener listener;
	float progress = 0F;
	
	public AnimationInstance(Object2ObjectMap<AnimationTarget, IValue> values, float totalProgress, boolean reverse, AnimationListener listener)
	{
		this.values = values;
		this.totalProgress = totalProgress;
		this.reverse = reverse;
		this.listener = listener;
	}
	
	public void update(Animator animator, float particalTime)
	{
		progress += particalTime;
		for(Object2ObjectMap.Entry<AnimationTarget, IValue> entry : Object2ObjectMaps.fastIterable(values))
		{
			entry.getKey().apply(animator, entry.getValue().update(particalTime));
		}
	}
	
	public float getCurrentProgress(AnimationTarget target)
	{
		return values.getOrDefault(target, ConstantValue.ZERO).get();
	}
	
	public boolean isDone()
	{
		return reverse && progress >= totalProgress;
	}
	
	public AnimationListener getListener()
	{
		return listener;
	}

	public boolean isReverse()
	{
		return reverse;
	}
}