using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class AppearMechanic : MonoBehaviour {

	#region Private Variables
	private List <SpotlightControl> _spotlights;
	private List <FigureControl> _figures;

	[SerializeField]
	private TriggerAnimation _largeFigure;

	private GameObject _room;
	#endregion


	#region Events
	void Start () {

		_room = GameObject.FindGameObjectWithTag ("Room");

	}
	#endregion


	#region Methods
	public void Check (Color c) {
		
		if (c == new Color (0f, 0f, 0f, 0f)) {
			
			DisableSpotlights ();
			_largeFigure.Trigger ();


		} else if (c == new Color (1f, 1f, 1f, 0.3f)) {

			DisableSpotlights ();

			_figures = new List <FigureControl> (GameObject.FindObjectsOfType <FigureControl> ());
			foreach (FigureControl figure in _figures)
				figure.PutAway ();

		}
		
	}


	void DisableSpotlights () {

		_spotlights = new List <SpotlightControl> (GameObject.FindObjectsOfType <SpotlightControl> ());
		foreach (SpotlightControl spotlight in _spotlights)
			spotlight.Disable ();

		Invoke ("KillRoom", 10f);
		
	}


	void KillRoom () {

		GameObject.FindObjectOfType <ActiveCamera> ().Reset ();
		Destroy (_room.gameObject);

	}
	#endregion
	
}
