#include "Tile.h"

namespace assets
{
	std::map<std::string, TileInfo*> TileInfo::list;

	void TileInfo::load(gge::resource::Folder &folder)
	{
		int index = 0;

		// get DataArray containing tile info at second index of the folder
		gge::resource::DataArray &dataArray = folder.Get<gge::resource::DataArray>(0);

		ID				 = dataArray.getString(index++);
		movementModifier = dataArray.getFloat(index++);
		isWalkable		 = dataArray.getInt(index++)!=0;

		// a tile folder contains a DataArray and a number of folders
		// that are containing actual graphic files for each tile type 
		// and info associated with these graphic files
		// fallowing loop gets all folders one by one and pushes them into
		// a Tile vector

		assets::Tile temp;
		for(int i = 1; i < folder.GetCount(); ++i)
		{
			gge::resource::Folder &tileFolder = folder.Get<gge::resource::Folder>(i);
			temp.load(tileFolder);
			temp.parent = this;
			tiles.push_back(temp);
		}
	}

	Tile::Tile(): forceNotWalkable(false), graphic(NULL) {}
	void Tile::load(gge::resource::Folder &folder)
	{
		int index = 0;

		// fallowing DataArray contains forceNotWalkable info
		gge::resource::DataArray &dataArray = folder.Get<gge::resource::DataArray>(index++);

		forceNotWalkable = dataArray.getInt(0)!=0;
		graphic			 = &folder.Get<gge::animation::RectangularGraphic2DAnimationProvider>(index++);
	}

}