class HighlightConnectionsRequest extends ScriptableSystemRequest
{
	var shouldHighlight : Bool;
	var isTriggeredByMasterDevice : Bool;
	var highlightTargets : array< NodeRef >;
	var requestingDevice : EntityID;
}

class DeviceConnectionsHighlightSystem extends ScriptableSystem
{
	private var m_highlightedDeviceID : EntityID;
	private var m_highlightedConnectionsIDs : array< EntityID >;

	private function OnHighlightConnectionsRequest( request : HighlightConnectionsRequest )
	{
		var highlightComponentEvent : HighlightConnectionComponentEvent;
		var targetID : EntityID;
		var i : Int32;
		if( !( request.isTriggeredByMasterDevice ) )
		{
			TurnOffAllHighlights();
			m_highlightedDeviceID = request.requestingDevice;
		}
		highlightComponentEvent = new HighlightConnectionComponentEvent;
		highlightComponentEvent.IsHighlightON = request.shouldHighlight;
		for( i = 0; i < request.highlightTargets.Size(); i += 1 )
		{
			targetID = ( ( EntityID )( ResolveNodeRefWithEntityID( request.highlightTargets[ i ], request.requestingDevice ) ) );
			m_highlightedConnectionsIDs.PushBack( targetID );
			GameInstance.GetPersistencySystem( GetGameInstance() ).QueueEntityEvent( targetID, highlightComponentEvent );
		}
	}

	private function TurnOffAllHighlights()
	{
		var i : Int32;
		var highlightComponentEvent : HighlightConnectionComponentEvent;
		highlightComponentEvent = new HighlightConnectionComponentEvent;
		highlightComponentEvent.IsHighlightON = false;
		for( i = 0; i < m_highlightedConnectionsIDs.Size(); i += 1 )
		{
			GameInstance.GetPersistencySystem( GetGameInstance() ).QueueEntityEvent( m_highlightedConnectionsIDs[ i ], highlightComponentEvent );
		}
		m_highlightedConnectionsIDs.Clear();
		m_highlightedDeviceID = ( ( EntityID )( GlobalNodeID.GetRoot() ) );
	}

}

