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

using namespace std;

const std::string PlayMusicCommand::_id = "playMusic";

PlayMusicCommand::PlayMusicCommand( std::string filename )
: _filename( filename )
{
	Level::instance()->setMusic( Mix_LoadMUS( _filename.c_str() ) );
}

PlayMusicCommand::PlayMusicCommand(List *command)
{
	command = command->rest();
	_filename = command->firstString();

	Level::instance()->setMusic( Mix_LoadMUS( _filename.c_str() ) );
}
void PlayMusicCommand::execute()
{
	Mix_FadeOutMusic(1000);
	Mix_FadeInMusic(Level::instance()->getMusic(), -1, 1000);
}

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

	return commandString;
}