#include "../Utils.h"
#include "Object.h"

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

	int Object::load(gge::resource::DataArray &dataArray)
	{
		int index = 0;
		std::vector<std::string> tileMap;

		ID   = dataArray.getString(index++);
		size = dataArray.getSize(index++);

		// remove blanks at the begining and the end of the string
		// get passability map of object(string) line by line
		for(int y = 0; y < size.Height; ++y)
		{
			tileMap.push_back(trimLeft(trimRight(dataArray.getString(index++))));
		}

		findNonPassablePoints(tileMap);

		// return index for later use
		return index;
	}

	void Object::findNonPassablePoints(const std::vector<std::string> &given_tileMap)
	{
		int y = 0;
		// iterate lines
		for(auto it1 = given_tileMap.begin(); it1 != given_tileMap.end(); ++it1)
		{
			int x = 0;
			std::string buffer = *it1;
			// iterate characters
			for(std::string::iterator it2 = buffer.begin(); it2 != buffer.end(); ++it2)
			{
				// if non passable
				if(*it2 == '0')
				{
					// add to the vector that holds non passable points
					nonPassablePoints.push_back(gge::utils::Point(x, y));
				}
				x++;
			}
			y++;
		}
	}

}
