#include <algorithm>

#include "Control.h"
#include "Screen.h"

using namespace std;

vector< Object* > Control::_controllers;

SDLKey Control::upKey = SDLK_UP;
SDLKey Control::downKey = SDLK_DOWN;
SDLKey Control::leftKey = SDLK_LEFT;
SDLKey Control::rightKey = SDLK_RIGHT;
SDLKey Control::shoot1Key = SDLK_LCTRL;
SDLKey Control::shoot2Key = SDLK_RCTRL;
SDLKey Control::altShoot1Key = SDLK_LALT;
SDLKey Control::altShoot2Key = SDLK_RALT;
SDLKey Control::jumpKey = SDLK_SPACE;
SDLKey Control::skipKey = SDLK_SPACE;
SDLKey Control::quitKey = SDLK_ESCAPE;
SDLKey Control::menuUpKey = SDLK_UP;
SDLKey Control::menuDownKey = SDLK_DOWN;
SDLKey Control::selectKey = SDLK_SPACE;

void Control::update()
{
	/*
	for( vector< Object* >::iterator i = _controllers.begin(); i != _controllers.end(); i++ )
	{
		(*i)->control();
	}*/
	for(size_t i = 0; i < _controllers.size(); i++)
 		_controllers[i]->control();
}

void Control::registerController(Object * o)
{
	_controllers.push_back( o );
}

void Control::detachController( Object* o )
{
	// It's possible that the controller is registered multiple times, so
	// remove all instances
	_controllers.erase( 
		remove( _controllers.begin(), _controllers.end(), o ), 
		_controllers.end() ); 
}

void Control::detachAllControllers()
{
	_controllers.clear();
}

/*void Control::setKeys(std::string filename)
{
	List * keyInfo = Parser::parse(filename);

	keyInfo = keyInfo->rest();
	while(!keyInfo->empty())
	{
		List * current = menuInfo->firstList();
		menuInfo = menuInfo->rest();

		if(current->firstString() == "up")
		{
			current = current->rest();
			_options.push_back(new Menu(current->firstString()));
		}
		
		delete current;
	}
}*/

