#include "Command.h"
#include "Control.h"
#include "List.h"
#include "Level.h"
#include "Object.h"

using namespace std;

const std::string SetControlCommand::_id = "setControl";

SetControlCommand::SetControlCommand(Object *object)
:_object(object)
{

}

SetControlCommand::SetControlCommand(List *command)
{
	command = command->rest();
	_object = Level::instance()->getObject(command->firstString());
}

void SetControlCommand::execute()
{
	Control::detachAllControllers();
	Control::registerController(_object);
}

std::string SetControlCommand::getString()
{
	List *command = new List();
	command->snoc(new Atom(_id));
	command->snoc(new Atom(_object->id()));
	string commandString = command->getString();
	delete command;

	return commandString;
}