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

using namespace std;

const std::string PlaySoundCommand::_id = "playSound";

PlaySoundCommand::PlaySoundCommand( std::string filename )
: _filename( filename )
{
	Level::instance()->loadSound( _filename );
}

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

	Level::instance()->loadSound( _filename );
}
void PlaySoundCommand::execute()
{
	// Play sound on next available channel
	Mix_PlayChannel(-1, Level::instance()->getSound( _filename ), 0 );
}

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

	return commandString;
}
