using UnityEngine;
using System.Collections;

public enum SCENE_TYPE { MAIN_MENU, GAME };

public class GameManager : MonoBehaviour
{
	private static GameManager _instance;
	public static GameManager shared { get{ return _instance; } }
	
	private Hashtable _sceneList = new Hashtable();
	private Scene _currentScene;
	private SCENE_TYPE _currentSceneType;
	
	public Scene GetCurrentScene() { return _currentScene; }
	public SCENE_TYPE GetCurrentSceneType() { return _currentSceneType; }
	
	void Awake()
	{
		_instance = this;
		
		_sceneList.Add(SCENE_TYPE.MAIN_MENU, gameObject.AddComponent<MainMenuScene>());
		_sceneList.Add(SCENE_TYPE.GAME, gameObject.AddComponent<GameScene>());
		
		//Screen.showCursor = false;
	}
	
	void Start()
	{
		StartCoroutine(DelayStartingScene());
	}
	
	IEnumerator DelayStartingScene()
	{
		yield return new WaitForSeconds(0.1f);
		SetScene(SCENE_TYPE.GAME);
	}
	
	void Update()
	{
		if(_currentScene)
			_currentScene.UpdateScene();
	}
	
	public void SetScene(SCENE_TYPE sceneType)
	{
		if((Scene)_sceneList[sceneType])
		{
			if(_currentScene)
				_currentScene.deactivate();	
			
			_currentScene = (Scene)_sceneList[sceneType];	
			_currentSceneType = sceneType;
			_currentScene.activate();
		}
		else
		{
			Debug.LogError("No scene named " + sceneType + " exists!");
		}
	}
}
