class SimpleSwitch extends InteractiveMasterDevice
{
	default m_deviceState = EDeviceStatus.ON;
	default m_controllerTypeName = 'SimpleSwitchController';
	protected instanceeditable var m_animationType : EAnimationType;
	protected instanceeditable var m_animationSpeed : Float;
	default m_animationSpeed = 1.0;

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

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

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

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

	protected override function TurnOnDevice()
	{
		super.TurnOnDevice();
		SetDiodeAppearance( true );
		PlayAnimation( 'ToggleOn' );
	}

	protected override function TurnOffDevice()
	{
		super.TurnOffDevice();
		SetDiodeAppearance( false );
		PlayAnimation( 'ToggleOn' );
	}

	private function SetDiodeAppearance( on : Bool )
	{
		var lightSettings : ScriptLightSettings;
		var evt : ChangeLightEvent;
		evt = new ChangeLightEvent;
		if( on )
		{
			lightSettings.color = Color( 25, 135, 0, 255 );
		}
		else
		{
			lightSettings.color = Color( 130, 0, 0, 0 );
		}
		lightSettings.strength = 1.0;
		evt.settings = lightSettings;
		QueueEvent( evt );
	}

	private function PlayAnimation( id : CName )
	{
		var playEvent : gameTransformAnimationPlayEvent;
		if( m_animationType == EAnimationType.REGULAR )
		{
		}
		else if( m_animationType == EAnimationType.TRANSFORM )
		{
			playEvent = new gameTransformAnimationPlayEvent;
			playEvent.animationName = id;
			playEvent.looping = false;
			playEvent.timesPlayed = 1;
			if( GetDevicePS().IsON() )
			{
				playEvent.timeScale = m_animationSpeed;
			}
			else if( GetDevicePS().IsOFF() )
			{
				playEvent.timeScale = m_animationSpeed * -1.0;
			}
			QueueEvent( playEvent );
		}
	}

	protected function TurnOnLights()
	{
		var evt : ToggleLightEvent;
		evt = new ToggleLightEvent;
		evt.toggle = true;
		QueueEvent( evt );
	}

	public const override function DeterminGameplayRole() : EGameplayRole
	{
		return EGameplayRole.ControlOtherDevice;
	}

}

