class Fridge extends InteractiveDevice
{
	default m_controllerTypeName = 'FridgeController';
	private var m_animFeature : AnimFeature_SimpleDevice;
	private instanceeditable var m_factOnDoorOpened : CName;
	hint m_factOnDoorOpened = "Quest fact changes on fridge state: 1 - opened, 2 - closed";

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

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

	protected override function ResolveGameplayState()
	{
		super.ResolveGameplayState();
		UpdateDoorAnimState();
	}

	protected event OnOpenDoor( evt : ToggleOpenFridge )
	{
		UpdateDeviceState();
		UpdateDoorAnimState();
		UpdateFactDB();
	}

	private function UpdateDoorAnimState()
	{
		if( !( m_animFeature ) )
		{
			m_animFeature = new AnimFeature_SimpleDevice;
		}
		m_animFeature.isOpen = false;
		if( GetDevicePS().IsOpen() )
		{
			m_animFeature.isOpen = true;
		}
		AnimationControllerComponent.ApplyFeature( this, 'DeviceFridge', m_animFeature );
	}

	private function UpdateFactDB()
	{
		var factValue : Int32;
		factValue = 0;
		if( GetDevicePS().IsOpen() )
		{
			factValue = 1;
		}
		AddFact( GetGame(), m_factOnDoorOpened );
		SetFactValue( GetGame(), m_factOnDoorOpened, factValue );
	}

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

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

}

