class JukeboxBigGameController extends DeviceInkGameControllerBase
{
	private var m_onTogglePlayListener : CallbackHandle;

	protected override function RegisterBlackboardCallbacks( blackboard : IBlackboard )
	{
		super.RegisterBlackboardCallbacks( blackboard );
		if( blackboard )
		{
			m_onTogglePlayListener = blackboard.RegisterListenerBool( GetOwner().GetBlackboardDef().IsPlaying, this, 'OnTogglePlay' );
		}
	}

	protected override function UnRegisterBlackboardCallbacks( blackboard : IBlackboard )
	{
		super.UnRegisterBlackboardCallbacks( blackboard );
		if( blackboard )
		{
			blackboard.UnregisterListenerBool( GetOwner().GetBlackboardDef().IsPlaying, m_onTogglePlayListener );
		}
	}

	protected event OnTogglePlay( value : Bool )
	{
		ResolveAnimState( value );
	}

	public override function Refresh( state : EDeviceStatus )
	{
		if( state == EDeviceStatus.ON )
		{
			ResolveAnimState( GetBlackboard().GetBool( GetOwner().GetBlackboardDef().IsPlaying ) );
		}
		super.Refresh( state );
	}

	protected function ResolveAnimState( isPlaying : Bool )
	{
		if( isPlaying )
		{
			TriggerAnimationByName( 'bar1', EInkAnimationPlaybackOption.PLAY );
		}
		else
		{
			TriggerAnimationByName( 'bar1', EInkAnimationPlaybackOption.STOP );
			TriggerAnimationByName( 'bar1', EInkAnimationPlaybackOption.PLAY, , CreatePlaybackOverrideData() );
		}
	}

	private function CreatePlaybackOverrideData() : PlaybackOptionsUpdateData
	{
		var playbackOptionsOverrideData : PlaybackOptionsUpdateData;
		playbackOptionsOverrideData = new PlaybackOptionsUpdateData;
		playbackOptionsOverrideData.m_playbackOptions.fromMarker = 'loop_end';
		playbackOptionsOverrideData.m_playbackOptions.toMarker = 'pause_end';
		playbackOptionsOverrideData.m_playbackOptions.loopInfinite = false;
		playbackOptionsOverrideData.m_playbackOptions.loopType = inkanimLoopType.None;
		return playbackOptionsOverrideData;
	}

	protected override function GetOwner() : Jukebox
	{
		return ( ( Jukebox )( GetOwnerEntity() ) );
	}

}

