<commit_before>#include <UtH/Engine/TMX/Object.hpp>

#include <tinyxml2.h>

#include <cstdlib>
#include <sstream>

using namespace uth;
using namespace TMX;

Object::Object(tinyxml2::XMLElement* objectElement)
{
    parseObject(objectElement);
}

Object::~Object()
{ }


// Public

const pmath::Rect& Object::GetRectangle() const
{
	return m_rectangle;
}

const std::vector<pmath::Vec2>& Object::GetPoints() const
{
	return m_points;
}

const pmath::Vec2 Object::GetPosition() const
{
	return pmath::Vec2(m_rectangle.position.x, m_rectangle.position.y);
}

std::string Object::GetProperty(const std::string& name) const
{
	auto prop = m_properties.find(name);
	if(prop != m_properties.end())
		return prop->second;

	return std::string();
}

const std::string& Object::GetName() const
{
	return m_name;
}

const std::string& Object::GetType() const
{
	return m_typeString;
}

// Private

void Object::parseObject(tinyxml2::XMLElement* element)
{
    // Parse properties
	m_name = element->Attribute("name");
	m_typeString = element->Attribute("type");

    auto properties = element->FirstChildElement("properties");
    if(properties != 0)
    {
        parseProperties(properties);
    }

    // Parse actual object
	m_rectangle.position.x = element->FloatAttribute("x");
	m_rectangle.position.y = element->FloatAttribute("y");

	// There are only 3 possibilities here but use else if for future compability
	if(element->UnsignedAttribute("width") != 0)
	{
		// Rectangle
		m_type = RECTANGLE;
		m_rectangle.size.x = element->FloatAttribute("width");
		m_rectangle.size.y = element->FloatAttribute("height");

		m_points.push_back(pmath::Vec2(m_rectangle.position.x, m_rectangle.position.y));
		m_points.push_back(pmath::Vec2(m_rectangle.position.x, m_rectangle.position.y-m_rectangle.size.y));
		m_points.push_back(pmath::Vec2(m_rectangle.position.x+m_rectangle.size.x, m_rectangle.position.y-m_rectangle.size.y));
		m_points.push_back(pmath::Vec2(m_rectangle.position.x+m_rectangle.size.x, m_rectangle.position.y));
	}
	else if(element->FirstChildElement("polygon") != 0)
	{<commit_msg>Fixed Tiled map loading with maps with objects without names or types<commit_after>#include <UtH/Engine/TMX/Object.hpp>

#include <tinyxml2.h>

#include <cstdlib>
#include <sstream>

using namespace uth;
using namespace TMX;

Object::Object(tinyxml2::XMLElement* objectElement)
{
    parseObject(objectElement);
}

Object::~Object()
{ }


// Public

const pmath::Rect& Object::GetRectangle() const
{
	return m_rectangle;
}

const std::vector<pmath::Vec2>& Object::GetPoints() const
{
	return m_points;
}

const pmath::Vec2 Object::GetPosition() const
{
	return pmath::Vec2(m_rectangle.position.x, m_rectangle.position.y);
}

std::string Object::GetProperty(const std::string& name) const
{
	auto prop = m_properties.find(name);
	if(prop != m_properties.end())
		return prop->second;

	return std::string();
}

const std::string& Object::GetName() const
{
	return m_name;
}

const std::string& Object::GetType() const
{
	return m_typeString;
}

// Private

void Object::parseObject(tinyxml2::XMLElement* element)
{
    // Parse properties
	const char* name = element->Attribute("name");
	if (name)
		m_name = name;
	const char* type = element->Attribute("type");
	if (type)
		m_typeString = type;

    auto properties = element->FirstChildElement("properties");
    if(properties != 0)
    {
        parseProperties(properties);
    }

    // Parse actual object
	m_rectangle.position.x = element->FloatAttribute("x");
	m_rectangle.position.y = element->FloatAttribute("y");

	// There are only 3 possibilities here but use else if for future compability
	if(element->UnsignedAttribute("width") != 0)
	{
		// Rectangle
		m_type = RECTANGLE;
		m_rectangle.size.x = element->FloatAttribute("width");
		m_rectangle.size.y = element->FloatAttribute("height");

		m_points.push_back(pmath::Vec2(m_rectangle.position.x, m_rectangle.position.y));
		m_points.push_back(pmath::Vec2(m_rectangle.position.x, m_rectangle.position.y-m_rectangle.size.y));
		m_points.push_back(pmath::Vec2(m_rectangle.position.x+m_rectangle.size.x, m_rectangle.position.y-m_rectangle.size.y));
		m_points.push_back(pmath::Vec2(m_rectangle.position.x+m_rectangle.size.x, m_rectangle.position.y));
	}
	else if(element->FirstChildElement("polygon") != 0)
	{
{'fraction_non_alphanumeric': 0.14888682745825602, 'fraction_numerical': 0.006493506493506494, 'mean_word_length': 5.3613569321533925, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1847401', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1500, 'n_words': 263}