class CrossingLight extends TrafficLight
{
	default m_controllerTypeName = 'CrossingLightController';
	protected var m_audioLightIsGreen : Bool;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		super.OnRequestComponents( ri );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		super.OnTakeControl( ri );
		m_controller = ( ( CrossingLightController )( EntityResolveComponentsInterface.GetComponent( ri, 'controller' ) ) );
	}

	private const override function GetController() : CrossingLightController
	{
		return ( ( CrossingLightController )( m_controller ) );
	}

	public const override function GetDevicePS() : CrossingLightControllerPS
	{
		return GetController().GetPS();
	}

	protected override function CommenceChangeToRed()
	{
		HandleRedLight( true );
		StartBlinking();
	}

	protected override function CommenceChangeToGreen()
	{
		StartBlinking();
		HandleRedLight( true );
	}

	protected override function CompleteLightChangeSequence()
	{
		StopBlinking();
		if( m_lightState == worldTrafficLightColor.RED )
		{
			HandleRedLight( true );
			PlayTrafficNotificationSound( worldTrafficLightColor.RED );
		}
		else if( m_lightState == worldTrafficLightColor.GREEN )
		{
			HandleGreenLight( true );
			PlayTrafficNotificationSound( worldTrafficLightColor.GREEN );
		}
	}

	protected function PlayTrafficNotificationSound( status : worldTrafficLightColor )
	{
		if( status == worldTrafficLightColor.RED && m_audioLightIsGreen )
		{
			PlaySoundEvent( this, GetDevicePS().GetRedSFX() );
			m_audioLightIsGreen = false;
		}
		else if( status == worldTrafficLightColor.GREEN && !( m_audioLightIsGreen ) )
		{
			PlaySoundEvent( this, GetDevicePS().GetGreenSFX() );
			m_audioLightIsGreen = true;
		}
	}

	private function StartBlinking()
	{
		var evt : ChangeCurveEvent;
		evt = new ChangeCurveEvent;
		evt.time = 1.0;
		evt.curve = 'blink_01';
		evt.loop = true;
		QueueEvent( evt );
	}

	private function StopBlinking()
	{
		var evt : ChangeCurveEvent;
		evt = new ChangeCurveEvent;
		evt.time = 1.0;
		evt.curve = '';
		evt.loop = false;
		QueueEvent( evt );
	}

}

