class animationPlayer extends inkLogicController
{
	editable var animName : CName;
	editable var loopType : inkanimLoopType;
	default loopType = inkanimLoopType.Cycle;
	editable var delay : Float;
	default delay = 0.f;
	editable var playInfinite : Bool;
	default playInfinite = true;
	editable var loopsAmount : Uint32;
	default loopsAmount = 1;
	editable var playReversed : Bool;
	default playReversed = false;
	editable var animTarget : inkWidgetRef;
	editable var autoPlay : Bool;
	default autoPlay = true;
	editable var dependsOnTimeDilation : Bool;
	default dependsOnTimeDilation = false;
	private var m_anim : inkAnimProxy;

	protected event OnInitialize()
	{
		if( autoPlay )
		{
			Play();
		}
	}

	public function PlayOrPause( flag : Bool )
	{
		if( flag )
		{
			Play();
		}
		else
		{
			Pause();
		}
	}

	public function PlayOrStop( flag : Bool )
	{
		if( flag )
		{
			Play();
		}
		else
		{
			Stop();
		}
	}

	public function Play()
	{
		if( m_anim == NULL )
		{
			m_anim = CreateAndPlayAnimation();
		}
		else
		{
			m_anim.Resume();
		}
	}

	public function Pause()
	{
		if( m_anim != NULL )
		{
			m_anim.Pause();
		}
	}

	public function Stop()
	{
		if( m_anim != NULL )
		{
			m_anim.Stop();
			m_anim = NULL;
		}
	}

	private function CreateAndPlayAnimation() : inkAnimProxy
	{
		var widgetSet : inkWidgetsSet;
		var options : inkAnimOptions;
		options.loopType = loopType;
		options.executionDelay = delay;
		options.loopInfinite = playInfinite;
		options.loopCounter = loopsAmount;
		options.playReversed = playReversed;
		options.dependsOnTimeDilation = dependsOnTimeDilation;
		widgetSet = SelectWidgets( inkWidgetRef.Get( animTarget ) );
		if( inkWidgetRef.Get( animTarget ) != NULL )
		{
			return PlayLibraryAnimationOnTargets( animName, widgetSet, options );
		}
		else
		{
			return PlayLibraryAnimation( animName, options );
		}
	}

}

