#include "GameStateManager.h"

GameStateManager::GameStateManager(void)
{
}

GameStateManager::~GameStateManager(void)
{
	while(!statesStack.empty())
		OutroState();
}

void GameStateManager::AddGameState(GameState *gameState)
{
	gameStates.push_back(gameState);
}

void GameStateManager::IntroState(wstring name)
{
	for(int i = 0; i < gameStates.size(); i++)
	{
		if(gameStates[i]->name == name)
		{
			statesStack.push(gameStates[i]);
			statesStack.top()->Initial();
			break;
		}
	}
}

void GameStateManager::OutroState()
{
	if(statesStack.size() > 0)
	{
		statesStack.top()->Destroy();
		statesStack.pop();
	}
}

void GameStateManager::Update(float dt)
{
	if(!statesStack.empty())
		statesStack.top()->Update(dt);
}

void GameStateManager::Draw(float dt)
{
	if(!statesStack.empty())
		statesStack.top()->Draw(dt);		
}