#include "Object.h"
#include "Person.h"
#include "Player.h"
#include "Parser.h"
#include "Enemy.h"
#include "EventPoint.h"
#include "CutScene.h"
#include "Door.h"

Object::Object()
:_depth( 0 ), _collidable( true ), _solid( true)
{
	
}

Object::Object(List* objInfo, int x, int y)
:_depth( 0 ), _collidable( true ), _solid( true)
{
	_box.w = 32;
	_box.h = 32;
	_box.x = x;
	_box.y = y;

	while( !objInfo->empty())
	{
		List * current = objInfo->firstList();
		if(current->firstString() == "id")
			_id = current->rest()->firstString();
		else if(current->firstString() == "size") {
			_box.w = current->rest()->firstInt();
			_box.h = current->rest()->rest()->firstInt();
		}

		objInfo = objInfo->rest();
	}
}

Object* Object::loadObject(std::string filename, int x , int y )
{
	List* objInfo = Parser::parse(filename);

	Object* returnme;
	
	

	//all derived classes from object should be represented below
	//with the possible exception of tile
	if(objInfo ->firstString() == "person")
		returnme = new Person(objInfo->rest(), x, y);

	else if(objInfo ->firstString() == "player")
		returnme = new Player(objInfo->rest(), x, y);

	else if(objInfo ->firstString() == "enemy")
		returnme = new Enemy(objInfo->rest(), x, y);

	else if(objInfo ->firstString() == "eventpoint")
		returnme = new EventPoint(objInfo->rest(), x, y);

	else if(objInfo ->firstString() == "cutscene")
		returnme = new CutScene(objInfo->rest(), x, y);

	else if(objInfo ->firstString() == "door")
		returnme = new Door(objInfo->rest(), x, y);

	delete objInfo;
	return returnme;

}