Exemplo n.º 1
0
void MapLoader::load(const std::string &xmlFilename, ResourceHandler &handler) {
	XMLFile doc(xmlFilename);

	XMLElement *areaElement = doc.FirstChildElement("maps").FirstChildElement("area").ToElement();
	while(areaElement) {
		u16 area = areaElement->IntAttribute("id");

		XMLElement *mapElement = areaElement->FirstChildElement("map");
		while(mapElement) {
			std::string name = mapElement->Attribute("name");
			std::string tilesetName = mapElement->Attribute("tileset");

			u16 x = mapElement->IntAttribute("x");
			u16 y = mapElement->IntAttribute("y");

			Tileset &tileset = handler.get<Tileset>(tilesetName);

			loadMap(name, area, x, y, tileset, handler);

			mapElement = mapElement->NextSiblingElement("map");
		}

		areaElement = areaElement->NextSiblingElement("area");
	}
}
Exemplo n.º 2
0
void MapLoader::loadMap(const std::string &name, u16 area, u16 x, u16 y, Tileset &tileset, ResourceHandler &handler) {
	XMLFile doc("data/maps/" + name + ".tmx");

	XMLElement *mapElement = doc.FirstChildElement("map").ToElement();

	u16 width = mapElement->IntAttribute("width");
	u16 height = mapElement->IntAttribute("height");

	std::vector<u16> data;
	XMLElement *tileElement = mapElement->FirstChildElement("layer")->FirstChildElement("data")->FirstChildElement("tile");
	while(tileElement) {
		s16 tileID = tileElement->IntAttribute("gid") - 1;

		data.push_back((tileID >= 0) ? tileID : 0);

		tileElement = tileElement->NextSiblingElement("tile");
	}

	Map &map = handler.add<Map>(makeName(area, x, y), area, x, y, width, height, tileset, data);

	for(u16 tileY = 0 ; tileY < height ; tileY++) {
		for(u16 tileX = 0 ; tileX < width ; tileX++) {
			u16 tileID = map.getTile(tileX, tileY);

			if(tileset.info()[tileID] == TilesInfos::TileType::GrassTile) {
				map.scene().addObject(GrassFactory::create(tileX, tileY));
			}
			else if(tileset.info()[tileID] == TilesInfos::TileType::LowGrassTile) {
				map.scene().addObject(GrassFactory::create(tileX, tileY, true));
			}
		}
	}

	SceneObjectLoader::load(name, map.scene());
}
Exemplo n.º 3
0
void SpriteAnimationManager::init() {
	XMLFile doc("data/config/spriteAnimations.xml");
	
	XMLElement *animationElement = doc.FirstChildElement("spriteAnimations").FirstChildElement("animation").ToElement();
	while(animationElement) {
		std::string name = animationElement->Attribute("name");
		std::vector<SpriteAnimation> animation;
		
		XMLElement *framesElement = animationElement->FirstChildElement("frames");
		while(framesElement) {
			std::vector<u16> frames;
			u16 delay = framesElement->IntAttribute("delay");
			
			XMLElement *frameElement = framesElement->FirstChildElement("frame");
			while(frameElement) {
				frames.push_back(frameElement->IntAttribute("id"));
				
				frameElement = frameElement->NextSiblingElement("frame");
			}
			
			animation.push_back(SpriteAnimation(frames.size(), frames, delay));
			
			framesElement = framesElement->NextSiblingElement("frames");
		}
		
		spriteAnimations[name] = animation;
		
		animationElement = animationElement->NextSiblingElement("animation");
	}
}
Exemplo n.º 4
0
int CTransportConfig::Initialize(const char* confname)
{
    if (m_transports.size() <= 0)
    {
        XMLDocument doc;
        if (doc.LoadFile(confname) != XML_NO_ERROR)
        {
            throw CMudException("load xml transports config file failed");
        }
        
        XMLHandle docHandle(&doc);
        XMLHandle current_handle = docHandle.FirstChildElement("config").FirstChildElement("transports").FirstChild();
        XMLElement* elem = current_handle.ToElement();
        while (elem)
        {
            int id = elem->IntAttribute("id");
            m_transports[id].id = id;
            m_transports[id].name = elem->Attribute("name");
            m_transports[id].x = elem->IntAttribute("x");
            m_transports[id].y = elem->IntAttribute("y");
            m_transports[id].enabled = elem->BoolAttribute("enabled");

            STDOUT_DEBUG("id=%d, name=%s, x=%d, y=%d, enabled=%d", 
                    id, m_transports[id].name.c_str(), m_transports[id].x, m_transports[id].y, m_transports[id].enabled);
            elem = current_handle.NextSibling().ToElement();
        }
    }

    return 0;
}
Exemplo n.º 5
0
ensoft::tmx::Image loadImage(XMLElement *element)
{
    XMLElement *ximage = element->FirstChildElement("image");
    std::string format = getAttributeString(ximage, "format");
    std::string source = getAttributeString(ximage, "source");
    std::string trans = getAttributeString(ximage, "trans");
    int width = ximage->IntAttribute("width");
    int height = ximage->IntAttribute("height");

    return ensoft::tmx::Image{format, source, trans, width, height};
}
Exemplo n.º 6
0
void VisualComponent::init(XMLElement *xmlData)
{
	XMLElement *visibleElt = xmlData->FirstChildElement("Visible");
	// if no visibility if specified, default to true
	if (visibleElt == nullptr)
		visible = true;
	else
	{
		visible = visibleElt->BoolAttribute("value");
	}

	XMLElement *textureElt = xmlData->FirstChildElement("Texture");
	// if no texture is specified, set it to null
	if (textureElt == nullptr)
		texture = nullptr;
	else
	{
		string texID = textureElt->Attribute("id");
		texture = TextureManager::get()->getTexture(texID);
	}

	XMLElement *dimElt = xmlData->FirstChildElement("Dimensions");
	// if both are null, we have no dimension data
	if (dimElt == nullptr && textureElt == nullptr)
		throw BAD_DIMENSION_ERR;
	// if no dimensions are specified, take them from the texture
	else if (dimElt == nullptr)
	{
		width = texture->width;
		height = texture->height;
	}
	else
	{
		width = dimElt->DoubleAttribute("w");
		height = dimElt->DoubleAttribute("h");
	}


	XMLElement *colorElt = xmlData->FirstChildElement("Color");
	// if no color is specified, default to white
	if (colorElt == nullptr)
		colorData = bm::Color(255, 255, 255, 255);
	else
	{
		int r = colorElt->IntAttribute("r");
		int g = colorElt->IntAttribute("g");
		int b = colorElt->IntAttribute("b");
		int a = colorElt->IntAttribute("a");
		colorData = bm::Color(r, g, b, a);
	}
}
Exemplo n.º 7
0
void VisualComponent::init(XMLElement *componentElement)
{
	XMLElement* textureElement;
	const char* textureFileLocation;
	const char* fontFileLocation;
	std::ostringstream LabelString; 

	ComponentID = componentElement->IntAttribute("ComponentType");
	viewType = (ViewType)componentElement->IntAttribute("GameViewId");
	XMLElement* colorElement = componentElement->FirstChildElement("Color");
	//actorColor = new sf::Color(colorElement->IntAttribute("r"),colorElement->IntAttribute("g"),colorElement->IntAttribute("b"),colorElement->IntAttribute("a"));
	XMLElement* shapeElement = colorElement->NextSiblingElement("Structure");
	shapeID = shapeElement->IntAttribute("ShapeID");
	switch(shapeElement->IntAttribute("ShapeID"))
	{
		case 1://"Rectangle":
			actorShape = new ActorShape::Rectangle();
			((ActorShape::Rectangle*)actorShape)->setSize(shapeElement->FloatAttribute("Height"), shapeElement->FloatAttribute("Width"));
			((ActorShape::Rectangle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor);//(const sf::Color &)actorColor
			break;
		case 2://"Circle":
			actorShape = new ActorShape::Circle();
			((ActorShape::Circle*)actorShape)->setSize(shapeElement->FloatAttribute("Radious"));
			((ActorShape::Circle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor);
			break;
		case 3://"GRID MAP":
			actorShape = new ActorShape::GridMap();
			((ActorShape::GridMap*)actorShape)->setBlockSize(shapeElement->IntAttribute("BlockHeight"),shapeElement->IntAttribute("BlockWidth"));
			
			break;
		case 5://TextArea
			textureElement = shapeElement->NextSiblingElement("Texture");
			textureFileLocation = textureElement->Attribute("TextureFileName");
			actorShape = new ActorShape::GridMap();
			((ActorShape::GridMap*)actorShape)->LoadTexture(textureFileLocation);
			((ActorShape::GridMap*)actorShape)->setBlockSize(shapeElement->IntAttribute("BlockHeight"),shapeElement->IntAttribute("BlockWidth"));
			fontFileLocation = textureElement->Attribute("FontFileName");
			((ActorShape::GridMap*)actorShape)->LoadFont(fontFileLocation);
			//LabelString << textureElement->Attribute("Text");// put float into string buffer
			//((ActorShape::GridMap*)actorShape)->SetTextInBox(LabelString, 0, 0);
			break;
		default:
			actorShape = new ActorShape::Circle();
			((ActorShape::Circle*)actorShape)->setSize(10);
			((ActorShape::Circle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor);
			break;
	}
	isVisible = true;
}
Exemplo n.º 8
0
Level* DataManager::getLevel(string name)
{
    int gridSize = 8;

    XMLDocument doc;
    doc.LoadFile("data/levels.xml");

    XMLElement* element = doc.FirstChildElement("package")->FirstChildElement("levels")->FirstChildElement("level");
    int width = element->IntAttribute("width");
    int height = element->IntAttribute("height");
    //string name = element->Attribute("name");

    Level* level = new Level();
    level->width = width;
    level->height = height;
    level->name = name;

    stringstream ss;
    ss << hex << element->GetText();
    int i = 0;
    int j = 0;
    int value;
    while (ss >> value) {
        int x = i * gridSize;
        int y = j * gridSize;
        int type = getBits(value, 0, 5);
        switch (type) {
            case 0x01: level->objects.push_back(new Object(x, y, Object::Type::BRICK)); break;
            case 0x02: level->objects.push_back(new Object(x, y, Object::Type::KEY)); break;
            case 0x03: level->objects.push_back(new Object(x, y, Object::Type::CACTUS)); break;
            case 0x04: level->objects.push_back(new Object(x, y, Object::Type::TRAVELATOR_LEFT)); break;
            case 0x05: level->blagger = new Blagger(x, y); break;
            case 0x06: level->objects.push_back(new Object(x, y, Object::Type::CROSS)); break;
            case 0x07: level->objects.push_back(new Object(x, y, Object::Type::METAL_FLOOR)); break;
            case 0x08: level->objects.push_back(new Object(x, y, Object::Type::SINKING_FLOOR)); break;
            case 0x09: level->objects.push_back(new Object(x, y, Object::Type::TRAVELATOR_RIGHT)); break;
            case 0x0A: level->objects.push_back(new Object(x, y, Object::Type::WALL_TOP)); break;
            case 0x0B: level->objects.push_back(new Object(x, y, Object::Type::WALL_CENTER)); break;
            case 0x0C: level->objects.push_back(new Object(x, y, Object::Type::WALL_BOTTOM)); break;
        }
        i++;
        if (i >= width) {
            i = 0;
            j++;
        }
    }

    return level;
}
Exemplo n.º 9
0
void MapManager::initMaps() {
	XMLFile doc("data/config/maps.xml");
	
	XMLElement *areasElement = doc.FirstChildElement("maps").ToElement();
	XMLElement *areaElement = areasElement->FirstChildElement("area");
	u16 areaID = 0;
	while(areaElement) {
		XMLElement *mapElement = areaElement->FirstChildElement("map");
		std::vector<Map*> currentArea;
		while(mapElement) {
			std::stringstream mapFilename;
			u8 layers;
			u16 x, y, tilesetID;
			
			layers = mapElement->IntAttribute("layers");
			x = mapElement->IntAttribute("x");
			y = mapElement->IntAttribute("y");
			tilesetID = mapElement->IntAttribute("tilesetID");
			
			mapFilename << "data/maps/map" << areaID << "-" << x << "-" << y << ".tmx";
			
			currentArea.push_back(new Map(mapFilename.str().c_str(), x, y, areaID, layers, tilesetID));
			
			currentArea.back()->setBattleback(new Image(std::string(std::string("graphics/battlebacks/") + mapElement->Attribute("battleback") + ".jpg").c_str()));
			
			XMLElement *eventElement = mapElement->FirstChildElement("event");
			while(eventElement) {
				currentArea.back()->addEvent(EventManager::getEventByName(eventElement->Attribute("name")));
				
				eventElement = eventElement->NextSiblingElement("event");
			}
			
			mapElement = mapElement->NextSiblingElement("map");
		}
		
		maps.push_back(currentArea);
		
		areaID++;
		
		areaElement = areaElement->NextSiblingElement("area");
	}
	
	u16 startarea = areasElement->IntAttribute("startarea");
	u16 startx = areasElement->IntAttribute("startx");
	u16 starty = areasElement->IntAttribute("starty");
	
	currentMap = maps[startarea][MAP_POS(startarea, startx, starty)];
}
Exemplo n.º 10
0
void ItemManager::loadSkills() {
	XMLFile doc("data/config/skills.xml");
	
	XMLElement *skillElement = doc.FirstChildElement("skills").FirstChildElement("skill").ToElement();
	u8 id = 0;
	while(skillElement) {
		const char *animation;
		
		animation = skillElement->Attribute("animation");
		if(!animation) animation = "";
		
		skills.push_back(new Skill(
			std::string("Skill") + to_string(id),
			std::string("Skill") + to_string(id) + "Desc",
			std::string("graphics/skills/") + to_string(id) + ".png",
			AnimationManager::getAnimationByName(animation),
			skillElement->IntAttribute("damage"),
			skillElement->DoubleAttribute("hitRate")
		));
		
		skills.back()->setID(id);
		
		skillElement = skillElement->NextSiblingElement("skill");
		id++;
	}
}
Exemplo n.º 11
0
bool GraphDataStorageXML::load(const char* fullpath, GraphData& data, StageBaseData* baseData) {
    try {
        XMLDocument doc;
        XMLDocument *myDocument = &doc;
        
        if (! FileUtils::getInstance()->isFileExist(fullpath)) return false;
        
        auto Data = FileUtils::getInstance()->getDataFromFile(fullpath);
        if (myDocument->Parse((const char*)Data.getBytes(), Data.getSize())) return false;
        //if (myDocument->LoadFile(fullpath)) return false;
        
        static GraphData s_defGraphData = {
            10/*row*/,
            10/*column*/,
            5/*vertex_num*/,
            64/*box_heights*/,
            64/*box_widths*/,
            0/*diff_row_off_x*/,
            32/*offsert_x*/,
            32/*offsert_y*/
        };
        data = s_defGraphData;
        
        for (XMLElement* property = myDocument->FirstChildElement("property"); property; property = property->NextSiblingElement("property")) {
            data.cols  = property->IntAttribute("cols");
            data.rows  = property->IntAttribute("rows");
            
            if (baseData) {
                baseData->m_bonusNeedStar = 12;
                baseData->m_lbNeedScore = property->IntAttribute("score") * 5;
            }
        }
        for (XMLElement* property = myDocument->FirstChildElement("map"); property; property = property->NextSiblingElement()) {
            for (auto attribute = property->FirstAttribute(); attribute; attribute = attribute->Next()) {
                const char* name = attribute->Name();
                int row = 0, col = 0;
                sscanf(name, "a%d_%d", &row, &col);
                data.map[row][col] = GraphAttrib::make(NodeCategory::make(static_cast<enNodeColor>(attribute->IntValue()), CHESS_CATEGORY_NORM, 0));
            }
        }
    } catch (std::string& e) {
        cocos2d::log("%s\n", e.c_str());
        return false;
    }
    return true;
}
Exemplo n.º 12
0
int OliWeb::configXml()
{
    string msg = "Opening ";
    msg += OLIWEB_CONFIG;
    writeLog(msg);
    //writeLog("Parsing XML (tinyxml2)");
    //config.Parse(OLIWEB_CONFIG);
    //config.Parse("utf8test.xml");
    config.LoadFile(OLIWEB_CONFIG);
    //writeLog("Errorcode = " + toString(config.ErrorID()));

    //  Pick apart the XML for config options...
    XMLElement *root = config.RootElement();
    if ( root == NULL )
    {
        writeLog("Error parsing file - no root element found.");
        return -1;
    }

    //  Configuration Options
    XMLElement *parserElement = root->FirstChildElement("ConfigurationSettings");
    if (parserElement != NULL)
    {
        writeLog("Reading configuration parameters",false);
        XMLElement *configElement = parserElement->FirstChildElement();

        while (configElement != NULL)
        {
            string settingName = configElement->Name();
            string value = configElement->Attribute("value");

            writeLog(settingName + " = " + value,false);

            if ( settingName == "PortNumber")
                    portNumber = configElement->IntAttribute("value");
            else if ( settingName == "RootFileDirectory")
                    rootFileDirectory = value;
            else if ( settingName == "ScriptDirectory")
                    scriptDirectory = value;
            else if ( settingName == "DefaultFileName")
                    defaultFileName = value;
            else if ( settingName == "FileNotFoundPage")
                    fileNotFoundPage = value;
            else if ( settingName == "LogFile")
                    logFileName = value;
            else if ( settingName == "PhpEngine")
                    phpEngine = value;
            else if ( settingName == "PhpFlags")
                    phpFlags = value;
            else if ( settingName == "UtilDirectory")
                    utilDirectory = value;
            else    writeLog("Setting not recognized!!");

            configElement = configElement->NextSiblingElement();
        }
    }
    return 0; // Success
}
Exemplo n.º 13
0
void ItemManager::loadArmors() {
	XMLFile doc("data/config/armors.xml");
	
	XMLElement *armorElement = doc.FirstChildElement("armors").FirstChildElement("armor").ToElement();
	u8 id = 0;
	while(armorElement) {
		armors.push_back(new Armor(
			std::string("Armor") + to_string(id),
			std::string("Armor") + to_string(id) + "Desc",
			std::string("graphics/armors/") + to_string(id) + ".png",
			armorElement->IntAttribute("slot"),
			armorElement->IntAttribute("defense")
		));
		
		armors.back()->setID(id);
		
		armorElement = armorElement->NextSiblingElement("armor");
		id++;
	}
}
Exemplo n.º 14
0
void getNonPassableTiles(const char *filename, Tileset *tileset) {
	XMLFile doc(filename);
	
	XMLElement *nonPassableTilesElement = doc.FirstChildElement("map").FirstChildElement("layer").NextSiblingElement().ToElement();
	if(!nonPassableTilesElement) return;
	
	u16 size = nonPassableTilesElement->IntAttribute("width") * nonPassableTilesElement->IntAttribute("height");
	
	tileset->nonPassableLayer = new u16[size];
	
	XMLElement *tileElement = nonPassableTilesElement->FirstChildElement("data")->FirstChildElement("tile");
	
	for(u16 i = 0 ; i < size ; i++) {
		if(!tileElement) break;
		
		s16 tile = tileElement->IntAttribute("gid") - 1;
		
		if(tile == -1) tileset->nonPassableLayer[i] = 0;
		else tileset->nonPassableLayer[i] = tile;
		
		tileElement = tileElement->NextSiblingElement("tile");
	}
}
Exemplo n.º 15
0
XMLElement* CManagerModel::ParseMesh(XMLElement *XMLMesh,CModel* Model)
{
	// Parse a SINGLE Mesh
	// Parse XMLSources AND Triangles.

	CMesh Mesh;
	XMLElement *XMLSource = XMLMesh->FirstChildElement("source");
	XMLElement *Tri = XMLMesh->FirstChildElement("triangles");
	XMLElement *Input = Tri->FirstChildElement("input");
	//Mesh.mTriangleCount = Tri->IntAttribute("count");



	while (Input != NULL)
	{
		CSource Source;

		if (strcmp(Input->Attribute("semantic"),"VERTEX") == 0) 
		{
			Source.mID = XMLMesh->FirstChildElement("vertices")->FirstChildElement("input")->Attribute("source");
		}
		else
		{
			Source.mID		=	Input->Attribute("source");
		}

		Source.mType	=	(char*) Input->Attribute("semantic");
		Source.mOffset	=	Input->IntAttribute("offset");
		Source.mID		=	Source.mID.erase(0, 1); // Remove the pound symbol.


		// This is actually <p>, aka an index list.
		Mesh.mIndex  = gusVector_SplitString((char*)Tri->FirstChildElement("p")->GetText(),' ');


		ParseSource(SourceByID(XMLMesh,(char*)Source.mID.c_str()),&Mesh,&Source);
		Input = Input->NextSiblingElement("input");
	}




	// [Matrix setup]

	// Let's hope we've added everything needed in these loops.
	Model->AddMesh(Mesh);

	return XMLMesh->NextSiblingElement("mesh");

}
Exemplo n.º 16
0
Volume3d<float, float>::Attribute CGBFile<float, float>::load(const std::string& filename)
{
	tinyxml2::XMLDocument xml;
	xml.LoadFile(filename.c_str());

	XMLElement* root = xml.FirstChildElement("root");

	Volume3d<float, float>::Attribute attr;

	{
		XMLElement* res = root->FirstChildElement(resStr.c_str());
		attr.resx = res->IntAttribute("x");
		attr.resy = res->IntAttribute("y");
		attr.resz = res->IntAttribute("z");
	}

	XMLElement* res = root->FirstChildElement("origin");
	Vector3d<float> origin = XMLHelper::parse(*res);

	XMLElement* lengthElem = root->FirstChildElement("length");
	Vector3d<float> length = XMLHelper::parse(*lengthElem);

	Space3d<float> space(origin, length);
	attr.space = space;

	XMLElement* volumeElem = root->FirstChildElement("volume");
	XMLElement* imageElem = volumeElem->FirstChildElement("image");

	imageFileNames.clear();
	while (imageElem != nullptr) {
		imageFileNames.push_back(imageElem->Attribute("path"));
		imageElem = imageElem->NextSiblingElement("image");
	}


	return attr;
}
Exemplo n.º 17
0
void FileList::read() {
	XMLDocument doc;
	const string filepath = dir + "filelist";
	doc.LoadFile(filepath.c_str());
	XMLElement* filelist = doc.FirstChildElement();
	try { validateXML(filelist, filepath); }
	catch (NoFile) { return; }
	for (XMLElement* i = filelist->FirstChildElement(); i != NULL;
		 i = (XMLElement*) i->NextSibling()) {
		const string from = i->Attribute("from");
		const string to = i->Attribute("to");
		const Args::Action action =
			static_cast<Args::Action>(i->IntAttribute("action"));
		records.push_back(Record(from, to, action));
	}
}
Exemplo n.º 18
0
bool InventoryComponent::Init(XMLElement* node)
{
	if (node->QueryBoolAttribute("drop", &m_canDrop) != tinyxml2::XMLError::XML_SUCCESS)
		return false;
	if (node->QueryIntAttribute("maxsize", &m_maxSize) != tinyxml2::XMLError::XML_SUCCESS)
		return false;
	XMLElement* pItems = node->FirstChildElement("Items");
	XMLElement* pItem = pItems->FirstChildElement("Item");
	while (pItem)
	{
		if (!AddItem(pItem->Attribute("name"), pItem->IntAttribute("quantity")))
			return false;
		pItem = pItem->NextSiblingElement("Item");
	}
	return true;
}
Exemplo n.º 19
0
void ItemManager::loadWeapons() {
	XMLFile doc("data/config/weapons.xml");
	
	XMLElement *weaponElement = doc.FirstChildElement("weapons").FirstChildElement("weapon").ToElement();
	u8 id = 0;
	while(weaponElement) {
		weapons.push_back(new Weapon(
			std::string("Weapon") + to_string(id),
			std::string("Weapon") + to_string(id) + "Desc",
			std::string("graphics/weapons/") + to_string(id) + ".png",
			weaponElement->IntAttribute("damage"),
			weaponElement->DoubleAttribute("hitRate")
		));
		
		weapons.back()->setID(id);
		
		weaponElement = weaponElement->NextSiblingElement("weapon");
		id++;
	}
}
Exemplo n.º 20
0
void 
GameObject::LoadProperties( XMLElement & e )
{
  XMLElement * prop = e.FirstChildElement("Property");

  while ( prop ){
    g_Log << "Property id is: " << prop->Attribute("id") << "\n";
    if ( !prop->Attribute("id") ) throw AttributeMissingException("Property - No id attribute");
    if ( !prop->Attribute("type") ) throw AttributeMissingException("Property - No type attribute");
    if ( !prop->Attribute("value") ) throw AttributeMissingException("Property - No value attribute");
    string type = prop->Attribute("type");
    
    if ( type == "bool" )		AddProperty( prop->Attribute("id"), prop->BoolAttribute("value"));
    else if ( type == "int" )	AddProperty( prop->Attribute("id"), prop->IntAttribute("value"));
    else if ( type == "float" )	AddProperty( prop->Attribute("id"), prop->FloatAttribute("value"));
    else if ( type == "string" )	AddProperty( prop->Attribute("id"), prop->Attribute("value"));
    else throw InvalidAttributeException("Invalid attribute type defined!");
    prop = prop->NextSiblingElement("Property");
  }
}
Exemplo n.º 21
0
std::string SystemSettings::load(const K::File& file) {

	XMLDocument doc;
	doc.LoadFile( file.getAbsolutePath().c_str() );

	XMLElement* nRoot = doc.FirstChildElement("KSynth");
	if (nRoot == nullptr) {return "";}

	// list of all encountered problems;
	std::string problems;

	XMLElement* nSettings = nRoot->FirstChildElement("Settings");
	if (!nSettings) {return "missing node for 'Settings'\n";}

	// sound-sink
	XMLElement* nSink = nSettings->FirstChildElement("SoundSink");
	if (nSink) {
		std::string name = nSink->Attribute("name");
		SoundSinkHardware* ss = SoundSinks::get().getHardwareSinkByName(name);
		if (ss) {
			setSoundSink(ss);
		} else {
			problems += "could not find a SoundSink named '"+name+"'\n";
		}
	} else {
		problems += "no 'SoundSink' given\n";
	}

	// refresh interval
	XMLElement* nGui = nSettings->FirstChildElement("GUI");
	if (nGui) {
		XMLElement* nGuiRefresh = nGui->FirstChildElement("Refresh");
		if (nGuiRefresh) {
			setGuiRefreshInterval(nGuiRefresh->IntAttribute("ms"));
		}
	}

	return problems;

}
Exemplo n.º 22
0
GSV* gsv_parse(char* xmlString)
{
#ifdef GSV_DEBUG
	printf("gsv_parse(%p)\n",xmlString);
	printf("XML = %s\n",xmlString);
#endif
	XMLDocument doc;
	doc.Parse(xmlString);
	
	GSV* gsvHandle = (GSV*) malloc(sizeof(GSV));
	if(gsvHandle == NULL)
		return NULL;
	
	*gsvHandle = GSVDefault;
	
	XMLElement* panoramaElement = doc.FirstChildElement("panorama");
	XMLElement* dataPropertiesElement = panoramaElement->FirstChildElement("data_properties");
	
	int error = dataPropertiesElement->QueryIntAttribute("image_width",&gsvHandle->dataProperties.imageWidth);
	GSV_WARNING("image_width",error);
	error = dataPropertiesElement->QueryIntAttribute("image_height",&gsvHandle->dataProperties.imageHeight);
	GSV_WARNING("image_height",error);
	error = dataPropertiesElement->QueryIntAttribute("tile_width",&gsvHandle->dataProperties.tileWidth);
	GSV_WARNING("tile_width",error);
	error = dataPropertiesElement->QueryIntAttribute("tile_height",&gsvHandle->dataProperties.tileHeight);
	GSV_WARNING("tile_height",error);
	
	char year[5];
	memset(year,'\0',sizeof(year)*sizeof(char));
	char month[3];
	memset(month,'\0',sizeof(month)*sizeof(char));
	const char* imageDate = dataPropertiesElement->Attribute("image_date");
	memcpy(year,imageDate,4*sizeof(char));
	memcpy(month,&imageDate[5],2*sizeof(char));
	struct tm imageDateTm = { 0, 0, 0, 1, atoi(month)-1, atoi(year)-1900, 0, 0, -1 };
	gsvHandle->dataProperties.imageDate = mktime(&imageDateTm);
	
	memcpy(gsvHandle->dataProperties.panoramaId,dataPropertiesElement->Attribute("pano_id"),GSV_PANORAMA_ID_LENGTH);
	error = dataPropertiesElement->QueryIntAttribute("num_zoom_levels",&gsvHandle->dataProperties.numZoomLevels);
	GSV_WARNING("num_zoom_levels",error);
	error = dataPropertiesElement->QueryDoubleAttribute("lat",&gsvHandle->dataProperties.latitude);
	GSV_WARNING("lat",error);
	error = dataPropertiesElement->QueryDoubleAttribute("lng",&gsvHandle->dataProperties.longitude);
	GSV_WARNING("lng",error);
	error = dataPropertiesElement->QueryDoubleAttribute("original_lat",&gsvHandle->dataProperties.longitude);
	GSV_WARNING("original_lat",error);
	error = dataPropertiesElement->QueryDoubleAttribute("original_lng",&gsvHandle->dataProperties.longitude);
	GSV_WARNING("original_lng",error);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("copyright")->GetText(),&gsvHandle->dataProperties.copyright);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("text")->GetText(),&gsvHandle->dataProperties.text);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("street_range")->GetText(),&gsvHandle->dataProperties.streetRange);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("region")->GetText(),&gsvHandle->dataProperties.region);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("country")->GetText(),&gsvHandle->dataProperties.country);
	
	XMLElement* projectionPropertiesElement = panoramaElement->FirstChildElement("projection_properties");
	gsv_copy_string(projectionPropertiesElement->Attribute("projection_type"),&gsvHandle->projectionProperties.projectionType);
	gsvHandle->projectionProperties.panoramaYaw = projectionPropertiesElement->DoubleAttribute("pano_yaw_deg");
	gsvHandle->projectionProperties.tiltYaw = projectionPropertiesElement->DoubleAttribute("tilt_yaw_deg");
	gsvHandle->projectionProperties.tiltYaw = projectionPropertiesElement->DoubleAttribute("tilt_pitch_deg");
	
	XMLElement* annotationProperties = panoramaElement->FirstChildElement("annotation_properties");
	XMLElement* linkElement = annotationProperties->FirstChildElement("link");
	
	while(linkElement != NULL)
	{
		gsvHandle->annotationProperties.links = (gsvLink*) realloc(gsvHandle->annotationProperties.links,(gsvHandle->annotationProperties.numLinks+1)*sizeof(gsvLink));
		gsvLink* link = &gsvHandle->annotationProperties.links[gsvHandle->annotationProperties.numLinks];
		
		error = linkElement->QueryDoubleAttribute("yaw_deg",&link->yaw);
		GSV_WARNING("yaw_deg",error);
		
		memcpy(link->panoramaId,linkElement->Attribute("pano_id"),GSV_PANORAMA_ID_LENGTH);
		
		const char* road_argb = linkElement->Attribute("road_argb");
		*((unsigned int*)&link->roadColour) = (unsigned int)strtoul(&road_argb[2],NULL,16);
		link->scene = linkElement->IntAttribute("scene");
		
		XMLElement* linkTextElement = linkElement->FirstChildElement("link_text");
		gsv_copy_string(linkTextElement->GetText(),&link->text);
		
		gsvHandle->annotationProperties.numLinks++;
		
		XMLNode* siblingNode = linkElement->NextSibling();
		if(siblingNode == NULL)
			break;
		linkElement = siblingNode->ToElement();
	}
	
	return gsvHandle;
}
Exemplo n.º 23
0
std::unique_ptr<ensoft::tmx::Map> ensoft::tmx::TmxLoader::loadMap(std::string filename)
{
	Logger logger("TMX Loader");
	logger.log("Loading " + filename);
    XMLDocument doc;
    XMLError error = doc.LoadFile(filename.c_str());
    std::unique_ptr<ensoft::tmx::Map> map;

    if (error != XMLError::XML_NO_ERROR)
    {
		logger.error("Error code: " + std::to_string(error));
    }
    else
    {
        // start parsing the TMX map
        XMLElement *xmap = doc.FirstChildElement("map");
        
        map = std::make_unique<ensoft::tmx::Map>(loadProperties(xmap));
        map->version = xmap->Attribute("version");
        map->orientation = xmap->Attribute("orientation");
        map->width = xmap->IntAttribute("width");
        map->height = xmap->IntAttribute("height");
        map->tilewidth = xmap->IntAttribute("tilewidth");
        map->tileheight = xmap->IntAttribute("tileheight");
        map->renderorder = xmap->Attribute("renderorder");
        map->properties = loadProperties(xmap);

        // load all the tilesets
        XMLElement *xtileset = xmap->FirstChildElement("tileset");
        while (xtileset)
        {
            auto tileSet = std::make_unique<ensoft::tmx::TileSet>(loadProperties(xtileset));
            tileSet->firstgid = xtileset->IntAttribute("firstgid");
            tileSet->source = getAttributeString(xtileset, "source");
            tileSet->name = getAttributeString(xtileset, "name");
            tileSet->tilewidth = xtileset->IntAttribute("tilewidth");
            tileSet->tileheight = xtileset->IntAttribute("tileheight");
            tileSet->spacing = xtileset->IntAttribute("spacing");
            tileSet->margin = xtileset->IntAttribute("margin");

            // get the tiles for this tileset
            XMLElement *xtile = xtileset->FirstChildElement("tile");
            while (xtile)
            {
                auto tile = make_unique<ensoft::tmx::Tile>(loadProperties(xtile));
                tile->id = xtile->IntAttribute("id");
                tile->terrain = getAttributeString(xtile, "terrain");
                tile->probability = xtile->FloatAttribute("probability");
                tile->image = loadImage(xtile);

                // keep track of all tiles and their global IDs
                int tileGid = tileSet->firstgid + tile->id;
                map->allTiles[tileGid] = tile.get();
                std::cout << "[TMX Loader] Added: " << tile->image.source << " GID: " << tileGid << " Tileset: " << tileSet->name << std::endl;

                tileSet->tiles.push_back(std::move(tile));
                xtile = xtile->NextSiblingElement("tile");
            }

            map->tilesets.push_back(std::move(tileSet));
            // try to find another tileset
            xtileset = xtileset->NextSiblingElement("tileset");
        }

        XMLElement *xlayer = xmap->FirstChildElement("layer");
        while (xlayer)
        {
            auto layer = std::make_shared<ensoft::tmx::Layer>(loadProperties(xlayer));
            layer->name = xlayer->Attribute("name");
            layer->x = xlayer->IntAttribute("x");
            layer->y = xlayer->IntAttribute("y");
            layer->width = xlayer->IntAttribute("width");
            layer->height = xlayer->IntAttribute("height");
            layer->opacity = xlayer->FloatAttribute("opacity");
            layer->visible = xlayer->BoolAttribute("visible");

            // load the data element
            XMLElement *xdata = xlayer->FirstChildElement("data");
            if (xdata)
            {
                string data = trim_copy(xdata->GetText());
                loadData(*layer, map.get(), data);
            }
            
            map->layers.push_back(layer);
            xlayer = xlayer->NextSiblingElement("layer");
        }

        XMLElement *ximagelayer = xmap->FirstChildElement("imagelayer");
        while (ximagelayer)
        {
            auto imageLayer = std::make_unique<ensoft::tmx::ImageLayer>(loadProperties(ximagelayer));
            imageLayer->name = ximagelayer->Attribute("name");
            imageLayer->x = ximagelayer->IntAttribute("x");
            imageLayer->y = ximagelayer->IntAttribute("y");
            imageLayer->width = ximagelayer->IntAttribute("width");
            imageLayer->height = ximagelayer->IntAttribute("height");
            imageLayer->opacity = ximagelayer->FloatAttribute("opacity");
            imageLayer->visible = ximagelayer->BoolAttribute("visible");

            imageLayer->image = loadImage(ximagelayer);
            map->imageLayers.push_back(std::move(imageLayer));

            ximagelayer = ximagelayer->NextSiblingElement("imagelayer");
        }

        XMLElement *xobjectgroup = xmap->FirstChildElement("objectgroup");
        while (xobjectgroup)
        {
            auto objectGroup = std::make_unique<ensoft::tmx::ObjectGroup>(loadProperties(xobjectgroup));
            objectGroup->name = xobjectgroup->Attribute("name");
            objectGroup->x = xobjectgroup->IntAttribute("x");
            objectGroup->y = xobjectgroup->IntAttribute("y");
            objectGroup->width = xobjectgroup->IntAttribute("width");
            objectGroup->height = xobjectgroup->IntAttribute("height");
            objectGroup->opacity = xobjectgroup->FloatAttribute("opacity");
            objectGroup->visible = xobjectgroup->BoolAttribute("visible");

            //grab the objects
            XMLElement *xobject = xobjectgroup->FirstChildElement("object");
            while (xobject)
            {
                auto object = std::make_unique<ensoft::tmx::Object>(loadProperties(xobject));
                object->id = xobject->Attribute("id");
                object->name = getAttributeString(xobject, "name");
                object->type = getAttributeString(xobject, "type");
                object->x = xobject->IntAttribute("x");
                object->y = xobject->IntAttribute("y");
                object->width = xobject->IntAttribute("witdth");
                object->height = xobject->IntAttribute("height");
                object->gid = xobject->IntAttribute("gid");
                object->visible = xobject->BoolAttribute("visible");
                objectGroup->objects.push_back(std::move(object));

                xobject = xobject->NextSiblingElement("object");
            }
            map->objectGroups.push_back(std::move(objectGroup));
            xobjectgroup = xobjectgroup->NextSiblingElement("objectgroup");
        }
    }

    return std::move(map); 
}
Exemplo n.º 24
0
Map *MapParser::loadMap(string mapName, string mapPropertiesPath) {
	XMLDocument doc;

	cout << "Loading map..." << endl;

	doc.LoadFile(mapName.c_str());

	cout << "Map loaded..." << endl;

	XMLElement *el = doc.FirstChildElement("map");

	// Dimensões do mapa e dos tile
	int tx = el->IntAttribute("width");
	int ty = el->IntAttribute("height");
	int tw = el->IntAttribute("tilewidth");
	int th = el->IntAttribute("tileheight");

	el = el->FirstChildElement("tileset")->FirstChildElement("image");

	int tilesetWidth = el->IntAttribute("width");
	int tilesetHeight = el->IntAttribute("height");

	el = el->Parent()->Parent()->ToElement();

	cout << "Tileset properties loaded..." << endl;

	queue<char *> lines;

	int nlayer = 0;

	for (XMLElement *e = el->FirstChildElement("layer"); e != NULL; e = e->NextSiblingElement("layer") )
		nlayer++;

	string property;
	string value;

	string name;

	cout << "Properties..." << endl;

	// Carrega propriedades definidas pelo usuário, se existir alguma
	if ( el->FirstChildElement("properties") != NULL ) {
		el = el->FirstChildElement("properties");

		for (XMLElement *e = el->FirstChildElement("property"); e != NULL; e = e->NextSiblingElement("property") )  {
			property = e->Attribute("name");
			value = e->Attribute("value");

			if ( property.compare("name") == 0 ) {
				name = value;
			}
		}

		el = el->Parent()->ToElement();
	}

	// matriz usada para armazena o valor dos tiles
	int ***matrixMap;

	matrixMap = new int**[nlayer];

	for (int i=0; i < nlayer; i++) {
		matrixMap[i] = new int*[ty];

		for (int j=0; j < ty; j++) {
			matrixMap[i][j] = new int[tx];
		}
	}

	int layer = 0;

	cout << "Matrix created..." << endl;

	// Carrega cada camada do mapa
	for ( XMLElement *e = el->FirstChildElement("layer"); e != NULL; e = e->NextSiblingElement("layer") )  {
		property = e->FirstChildElement("data")->Attribute("encoding");

		cout << "Matrix created..." << endl;

		// Se for 'Comma-Separated Values'
		if ( property.compare("csv") == 0 ) {
//			map->setName(value);

			cout << "Layer " << layer << endl;

			char *mapTiles = (char *)e->FirstChildElement("data")->GetText();

			cout << "Layer " << layer << endl;

			char *line = strtok(mapTiles, "\n");

			// Itera sobre cada linha
			while ( line != NULL ) {
				lines.push(line);

				line = strtok(NULL, "\n");
			}


			char *tokens = NULL;
			int intToken;

			int mline = 0;

			while ( !lines.empty() ) {
				line = lines.front();

				tokens = strtok(line, ",");

				int mcol = 0;

				// Itera sobre cada valor do tile, de cada linha
				while ( tokens != NULL ) {
					intToken = atoi(tokens);

					if ( intToken > 0 )
						intToken--;

					matrixMap[layer][mline][mcol++] = intToken;

					cout << intToken << ", ";

					tokens = strtok(NULL, ",");
				}

				lines.pop();
				mline++;
			}
		}

		cout << endl;

		layer++;
	}

	cout << "Before loading properties..." << endl;

	Tileset *tileset = new Tileset(tilesetWidth, tilesetHeight, tw, th);
	loadMapProperties(tileset, mapPropertiesPath);

	// CRIA MAPA
	Map *map = new Map(tileset, tx, ty, nlayer);

	map->setName(name);
	map->setMapMatrix(matrixMap);

	cout << "Map loaded..." << endl;

	return map;
}
Exemplo n.º 25
0
bool ScEclipseTheme::Load(const char* themeName)
{
    using namespace tinyxml2;

    XMLDocument xmlDocument;
    XMLError result = xmlDocument.LoadFile(themeName);
    if (result != XML_SUCCESS)
        return false;

    XMLElement* rootElement = xmlDocument.RootElement();
    if (!rootElement)
        return false;

    XMLElement* colorTheme = xmlDocument.FirstChildElement("colorTheme");

    const char* name = colorTheme->Attribute("name");
    if (name == nullptr)
        return false;

    //strcpy(m_themeName, name);

    m_themeId = (unsigned int)colorTheme->IntAttribute("id");
    if (m_themeId == 0)
        return false;

    bool success = true;

    success &= LoadColour(m_searchResultIndication, "searchResultIndication", colorTheme);
    success &= LoadColour(m_filteredSearchResultIndication, "filteredSearchResultIndication", colorTheme);
    success &= LoadColour(m_occurrenceIndication, "occurrenceIndication", colorTheme);
    success &= LoadColour(m_writeOccurrenceIndication, "writeOccurrenceIndication", colorTheme);
    success &= LoadColour(m_findScope, "findScope", colorTheme);
    success &= LoadColour(m_sourceHoverBackground, "sourceHoverBackground", colorTheme);
    success &= LoadColour(m_singleLineComment, "singleLineComment", colorTheme);
    success &= LoadColour(m_multiLineComment, "multiLineComment", colorTheme);
    success &= LoadColour(m_commentTaskTag, "commentTaskTag", colorTheme);
    success &= LoadColour(m_javadoc, "javadoc", colorTheme);
    success &= LoadColour(m_javadocLink, "javadocLink", colorTheme);
    success &= LoadColour(m_javadocTag, "javadocTag", colorTheme);
    success &= LoadColour(m_javadocKeyword, "javadocKeyword", colorTheme);
    success &= LoadColour(m_class, "class", colorTheme);
    success &= LoadColour(m_interface, "interface", colorTheme);
    success &= LoadColour(m_method, "method", colorTheme);
    success &= LoadColour(m_methodDeclaration, "methodDeclaration", colorTheme);
    success &= LoadColour(m_bracket, "bracket", colorTheme);
    success &= LoadColour(m_number, "number", colorTheme);
    success &= LoadColour(m_string, "string", colorTheme);
    success &= LoadColour(m_operator, "operator", colorTheme);
    success &= LoadColour(m_keyword, "keyword", colorTheme);
    success &= LoadColour(m_annotation, "annotation", colorTheme);
    success &= LoadColour(m_staticMethod, "staticMethod", colorTheme);
    success &= LoadColour(m_localVariable, "localVariable", colorTheme);
    success &= LoadColour(m_localVariableDeclaration, "localVariableDeclaration", colorTheme);
    success &= LoadColour(m_field, "field", colorTheme);
    success &= LoadColour(m_staticField, "staticField", colorTheme);
    success &= LoadColour(m_staticFinalField, "staticFinalField", colorTheme);
    success &= LoadColour(m_deprecatedMember, "deprecatedMember", colorTheme);
    success &= LoadColour(m_background, "background", colorTheme);
    success &= LoadColour(m_currentLine, "currentLine", colorTheme);
    success &= LoadColour(m_foreground, "foreground", colorTheme);
    success &= LoadColour(m_lineNumber, "lineNumber", colorTheme);
    success &= LoadColour(m_selectionBackground, "selectionBackground", colorTheme);
    success &= LoadColour(m_selectionForeground, "selectionForeground", colorTheme);

    return success;
}
Exemplo n.º 26
0
void MapParser::loadMapProperties(Tileset *tileset, string filename) {
	XMLDocument doc;
	queue<char *> lines;
	int currentTile = 0;
	int *tilesetProperties;
	string property;

	doc.LoadFile(filename.c_str());

	cout << "Loading map properties..." << endl;

	XMLElement *header = doc.FirstChildElement("tileset");

	if ( header == NULL ) {
		cerr << "Error to read " << filename << endl;
		return;
	}

	int width = header->IntAttribute("width");
	int height = header->IntAttribute("height");

	XMLElement *properties = header->FirstChildElement("properties");

	int walkable = properties->IntAttribute("walkable");
	int block = properties->IntAttribute("block");
	int passBelow = properties->IntAttribute("passbelow");

	tileset->setProperties(walkable, block, passBelow);

	tilesetProperties = new int[width*height];


	// Carrega cada camada do mapa
	XMLElement *data = header->FirstChildElement("data");
	property = data->Attribute("encoding");


	// Se for 'Comma-Separated Values'
	if ( property.compare("csv") == 0 ) {
		char *mapTiles = (char *)data->GetText();

		char *line = strtok(mapTiles, "\n");

		// Itera sobre cada linha
		while ( line != NULL ) {
			lines.push(line);

//			cout << line << endl;
			line = strtok(NULL, "\n");
		}

		char *tokens = NULL;

		int mline = 0;

		while ( !lines.empty() ) {
			line = lines.front();

			tokens = strtok(line, ",");

			int mcol = 0;

			// Itera sobre cada valor do tile, de cada linha
			while ( tokens != NULL ) {
				tilesetProperties[currentTile++] = atoi(tokens);

				mcol++;
				tokens = strtok(NULL, ",");
			}

			lines.pop();
			mline++;
		}
	}

	tileset->setTilesetProperties(tilesetProperties);

	cout << "Map properties loaded..." << endl;
}
Exemplo n.º 27
0
void Level::loadMap(std::string mapName, Graphics &graphics) {
	//Parse the .tmx file
	XMLDocument doc;
	std::stringstream ss;
	ss << "content/maps/" << mapName << ".tmx"; //Pass in Map1; content/maps/Map1.tmx
	doc.LoadFile(ss.str().c_str());

	XMLElement* mapNode = doc.FirstChildElement("map");

	//Get the width and the height of the whole map and store it in _size
	int width, height;
	mapNode->QueryIntAttribute("width", &width);
	mapNode->QueryIntAttribute("height", &height);
	this->_size = Vector2(width, height);

	//Get the width and the height of an individual tile and store it in _tileSize
	int tileWidth, tileHeight;
	mapNode->QueryIntAttribute("tilewidth", &tileWidth);
	mapNode->QueryIntAttribute("tileheight", &tileHeight);
	this->_tileSize = Vector2(tileWidth, tileHeight);

	//Load the tilesets
	XMLElement* pTileset = mapNode->FirstChildElement("tileset");
	if (pTileset != NULL) {
		while (pTileset) {
			int firstgid;
			const char* source = pTileset->FirstChildElement("image")->Attribute("source");
			std::string path = source;
			path.replace(0, 2, "content");
			pTileset->QueryIntAttribute("firstgid", &firstgid);
			SDL_Texture* tex = SDL_CreateTextureFromSurface(graphics.getRenderer(),
					graphics.loadImage(path));
			this->_tilesets.push_back(Tileset(tex, firstgid));

			// Get all the animations for that tileset
			XMLElement* pTileA = pTileset->FirstChildElement("tile");
			if (pTileA != NULL) {
				while (pTileA) {
					AnimatedTileInfo ati;
					ati.StartTileId = pTileA->IntAttribute("id") + firstgid;
					ati.TilesetsFirstGid = firstgid;
					XMLElement* pAnimation = pTileA->FirstChildElement("animation");
					if (pAnimation != NULL) {
						while (pAnimation) {
							XMLElement* pFrame = pAnimation->FirstChildElement("frame");
							if (pFrame != NULL) {
								while (pFrame) {
									ati.TileIds.push_back(pFrame->IntAttribute("tileid") + firstgid);
									ati.Duration = pFrame->IntAttribute("duration");
									pFrame = pFrame->NextSiblingElement("frame");
								}
							}
							pAnimation = pAnimation->NextSiblingElement("animation");
						}
					}
					this->_animatedTileInfos.push_back(ati);
					pTileA = pTileA->NextSiblingElement("tile");
				}
			}


			pTileset = pTileset->NextSiblingElement("tileset");
		}
	}

	//Loading the layers
	XMLElement* pLayer = mapNode->FirstChildElement("layer");
	if (pLayer != NULL) {
		while (pLayer) {
			//Loading the data element
			XMLElement* pData = pLayer->FirstChildElement("data");
			if (pData != NULL) {
				while (pData) {
					//Loading the tile element
					XMLElement* pTile = pData->FirstChildElement("tile");
					if (pTile != NULL) {
						int tileCounter = 0;
						while (pTile) {
							//Build each individual tile here
							//If gid is 0, no tile should be drawn. Continue loop.
							if (pTile->IntAttribute("gid") == 0) {
								tileCounter++;
								if (pTile->NextSiblingElement("tile")) {
									pTile = pTile->NextSiblingElement("tile");
									continue;
								}
								else {
									break;
								}
							}

							//Get the tileset for this specific gid
							int gid = pTile->IntAttribute("gid");
							Tileset tls;
							int closest = 0;
							for (int i = 0; i < this->_tilesets.size(); i++) {
								if (this->_tilesets[i].FirstGid <= gid) {
									if (this->_tilesets[i].FirstGid > closest) {
										closest = this->_tilesets[i].FirstGid;
										tls = this->_tilesets.at(i);
									}
								}
							}

							if (tls.FirstGid == -1) {
								//No tileset was found for this gid
								tileCounter++;
								if (pTile->NextSiblingElement("tile")) {
									pTile = pTile->NextSiblingElement("tile");
									continue;
								}
								else {
									break;
								}
							}

							//Get the position of the tile in the level
							int xx = 0;
							int yy = 0;
							xx = tileCounter % width;
							xx *= tileWidth;
							yy += tileHeight * (tileCounter / width);
							Vector2 finalTilePosition = Vector2(xx, yy);

							//Calculate the position of the tile in the tileset
							Vector2 finalTilesetPosition =
								this->getTilesetPosition(tls, gid, tileWidth, tileHeight);

							//Build the actual tile and add it to the level's tile list
							bool isAnimatedTile = false;
							AnimatedTileInfo ati;
							for (int i = 0; i < this->_animatedTileInfos.size(); i++) {
								if (this->_animatedTileInfos.at(i).StartTileId == gid) {
									ati = this->_animatedTileInfos.at(i);
									isAnimatedTile = true;
									break;
								}
							}
							if (isAnimatedTile == true) {
								std::vector<Vector2> tilesetPositions;
								for (int i = 0; i < ati.TileIds.size(); i++) {
									tilesetPositions.push_back(this->getTilesetPosition(
												tls, ati.TileIds.at(i), tileWidth, tileHeight));
								}
									AnimatedTile tile(tilesetPositions, ati.Duration,
											tls.Texture, Vector2(tileWidth, tileHeight),
											finalTilePosition);
									this->_animatedTileList.push_back(tile);
							}
							else {
								Tile tile(tls.Texture,
										Vector2(tileWidth, tileHeight),
										finalTilesetPosition, finalTilePosition);
								this->_tileList.push_back(tile);
							}
							tileCounter++;
							pTile = pTile->NextSiblingElement("tile");
						}
					}
					pData = pData->NextSiblingElement("data");
				}
			}
			pLayer = pLayer->NextSiblingElement("layer");
		}
	}

	// Parse out the collisions
	XMLElement* pObjectGroup = mapNode->FirstChildElement("objectgroup");
	if (pObjectGroup != NULL) {
		while (pObjectGroup) {
			const char* name = pObjectGroup->Attribute("name");
			std::stringstream ss;
			ss << name;
			if (ss.str() == "collisions") {
				XMLElement* pObject = pObjectGroup->FirstChildElement("object");
				if (pObject != NULL) {
					while (pObject) {
						float x, y, width, height;
						x = pObject->FloatAttribute("x");
						y = pObject->FloatAttribute("y");
						width = pObject->FloatAttribute("width");
						height = pObject->FloatAttribute("height");
						this->_collisionRects.push_back(Rectangle(
								std::ceil(x) * globals::SPRITE_SCALE,
								std::ceil(y) * globals::SPRITE_SCALE,
								std::ceil(width) * globals::SPRITE_SCALE,
								std::ceil(height) * globals::SPRITE_SCALE
						));

						pObject = pObject->NextSiblingElement("object");
					}
				}
			}

			// Other object groups go here with an else if (ss.str() == "whatever")

			else if (ss.str() == "slopes") {
				XMLElement* pObject = pObjectGroup->FirstChildElement("object");
				if (pObject != NULL) {
					while (pObject) {
						std::vector<Vector2> points;
						Vector2 p1;
						p1 = Vector2(std::ceil(pObject->FloatAttribute("x")),
								std::ceil(pObject->FloatAttribute("y")));
						XMLElement* pPolyline = pObject->FirstChildElement("polyline");
						if (pPolyline != NULL) {
							std::vector<std::string> pairs;
							const char* pointString = pPolyline->Attribute("points");

							std::stringstream ss;
							ss << pointString;
							Utils::split(ss.str(), pairs, ' ');
							// Now we have each of the pairs. Loop through the list of pairs and
							// split them into Vector2s. Then store them in points vector.
							for (int i = 0; i < pairs.size(); i++) {
								std::vector<std::string> ps;
								Utils::split(pairs.at(i), ps, ',');
								points.push_back(Vector2(
											std::stoi(ps.at(0)), std::stoi(ps.at(1))));
							}
						}

						for (int i = 0; i < points.size(); i += 2) {
							this->_slopes.push_back(Slope(
										Vector2(
											(p1.x + points.at(i < 2 ? i : i - 1).x) * globals::SPRITE_SCALE,
											(p1.y + points.at(i < 2 ? i : i - 1).y) * globals::SPRITE_SCALE),
										Vector2(
											(p1.x + points.at(i < 2 ? i + 1 : i).x) * globals::SPRITE_SCALE,
											(p1.y + points.at(i < 2 ? i + 1 : i).y) * globals::SPRITE_SCALE)
											)
							);
						}

						pObject = pObject->NextSiblingElement("object");
					}
				}
			}

			else if (ss.str() == "spawn points") {
				XMLElement* pObject = pObjectGroup->FirstChildElement("object");
				if (pObject != NULL) {
					while (pObject) {
						float x = pObject->FloatAttribute("x");
						float y = pObject->FloatAttribute("y");
						const char* name = pObject->Attribute("name");
						std::stringstream ss;
						ss << name;
						if (ss.str() == "player") {
							this->_spawnPoint = Vector2(std::ceil(x) * globals::SPRITE_SCALE,
									std::ceil(y) * globals::SPRITE_SCALE);
						}

						pObject = pObject->NextSiblingElement("object");
					}
				}
			}

			// Parse doors if they exist
			else if (ss.str() == "doors") {
				XMLElement* pObject = pObjectGroup->FirstChildElement("object");
				if (pObject != NULL) {
					while (pObject) {
						float x = pObject->FloatAttribute("x");
						float y = pObject->FloatAttribute("y");
						float w = pObject->FloatAttribute("width");
						float h = pObject->FloatAttribute("height");
						Rectangle rect = Rectangle(x, y, w, h);

						XMLElement* pProperties = pObject->FirstChildElement("properties");
						if (pProperties != NULL) {
							while (pProperties) {
								XMLElement* pProperty = pProperties->FirstChildElement("property");
								if (pProperty != NULL) {
									while (pProperty) {
										const char* name = pProperty->Attribute("name");
										std::stringstream ss;
										ss << name;
										if (ss.str() == "destination") {
											const char* value = pProperty->Attribute("value");
											std::stringstream ss2;
											ss2 << value;
											Door door = Door(rect, ss2.str());
											this->_doorList.push_back(door);
										}
										pProperty = pProperty->NextSiblingElement("property");
									}
								}
								pProperties = pProperties->NextSiblingElement("properties");
							}
						}

						pObject = pObject->NextSiblingElement("object");
					}
				}
			}

			pObjectGroup = pObjectGroup->NextSiblingElement("objectgroup");
		}
	}
}
Exemplo n.º 28
0
void Level::loadMap(std::string mapName, Graphics &graphics) {
	//Parse the .tmx file
	XMLDocument doc;
	std::stringstream ss;
	ss << "maps/" << mapName << ".tmx"; //Pass in Map 1, we get maps/Map 1.tmx
	doc.LoadFile(ss.str().c_str());

	XMLElement* mapNode = doc.FirstChildElement("map");

	//Get the width and the height of the whole map and store it in _size
	int width, height;
	mapNode->QueryIntAttribute("width", &width);
	mapNode->QueryIntAttribute("height", &height);
	this->_size = Vector2(width, height);

	//Get the width and the height of the tiles and store it in _tileSize
	int tileWidth, tileHeight;
	mapNode->QueryIntAttribute("tilewidth", &tileWidth);
	mapNode->QueryIntAttribute("tileheight", &tileHeight);
	this->_tileSize = Vector2(tileWidth, tileHeight);

	//Loading the tilesets
	XMLElement* pTileset = mapNode->FirstChildElement("tileset");
	if (pTileset != NULL) {
		while (pTileset) {
			int firstgid;
			const char* source = pTileset->FirstChildElement("image")->Attribute("source");
			char* path;
			std::stringstream ss;
			ss << source;
			pTileset->QueryIntAttribute("firstgid", &firstgid);
			SDL_Texture* tex = SDL_CreateTextureFromSurface(graphics.getRenderer(), graphics.loadImage(ss.str()));
			this->_tilesets.push_back(Tileset(tex, firstgid));

			pTileset = pTileset->NextSiblingElement("tileset");
		}
	}

	//Loading the layers
	XMLElement* pLayer = mapNode->FirstChildElement("layer");
	if (pLayer != NULL) {
		while (pLayer) {
			//Loading the data element
			XMLElement* pData = pLayer->FirstChildElement("data");
			if (pData != NULL) {
				while (pData) {
					//Loading the tile element
					XMLElement* pTile = pData->FirstChildElement("tile");
					if (pTile != NULL) {
						int tileCounter = 0;
						while (pTile) {
							//Build each individual tile here
							//If gid is 0, no tile should be drawn. Continue loop
							if (pTile->IntAttribute("gid") == 0) {
								tileCounter++;
								if (pTile->NextSiblingElement("tile")) {
									pTile = pTile->NextSiblingElement("tile");
									continue;
								}
								else {
									break;
								}
							}

							//Get the tileset for this specific gid
							int gid = pTile->IntAttribute("gid");
							Tileset tls;
							for (int i = 0; i < this->_tilesets.size(); i++) {
								if (this->_tilesets[i].FirstGid <= gid) {
									//This is the tileset we want
									tls = this->_tilesets.at(i);
									break;
								}
							}

							if (tls.FirstGid == -1) {
								//No tileset was found for this gid
								tileCounter++;
								if (pTile->NextSiblingElement("tile")) {
									pTile = pTile->NextSiblingElement("tile");
									continue;
								}
								else {
									break;
								}
							}

							//Get the position of the tile in the level
							int xx = 0;
							int yy = 0;
							xx = tileCounter % width;
							xx *= tileWidth;
							yy += tileHeight * (tileCounter / width);
							Vector2 finalTilePosition = Vector2(xx, yy);

							//Calculate the position of the tile in the tileset
							int tilesetWidth, tilesetHeight;
							SDL_QueryTexture(tls.Texture, NULL, NULL, &tilesetWidth, &tilesetHeight);
							int tsxx = gid % (tilesetWidth / tileWidth) - 1;
							tsxx *= tileWidth;
							int tsyy = 0;
							int amt = (gid / (tilesetWidth / tileWidth));
							tsyy = tileHeight * amt;
							Vector2 finalTilesetPosition = Vector2(tsxx, tsyy);

							//Build the actual tile and add it to the level's tile list
							Tile tile(tls.Texture, Vector2(tileWidth, tileHeight),
									finalTilesetPosition, finalTilePosition);
							this->_tileList.push_back(tile);
							tileCounter++;

							pTile = pTile->NextSiblingElement("tile");
						}
					}

					pData = pData->NextSiblingElement("data");
				}
			}

			pLayer = pLayer->NextSiblingElement("layer");
		}
	}

	//Parse out the collisions
	XMLElement* pObjectGroup = mapNode->FirstChildElement("objectgroup");
	if (pObjectGroup != NULL) {
		while (pObjectGroup) {
			const char* name = pObjectGroup->Attribute("name");
			std::stringstream ss;
			ss << name;
			if (ss.str() == "collisions") {
				XMLElement* pObject = pObjectGroup->FirstChildElement("object");
				if (pObject != NULL) {
					while (pObject) {
						float x, y, width, height;
						x = pObject->FloatAttribute("x");
						y = pObject->FloatAttribute("y");
						width = pObject->FloatAttribute("width");
						height = pObject->FloatAttribute("height");
						this->_collisionRects.push_back(Rectangle(
								std::ceil(x) * globals::SPRITE_SCALE,
								std::ceil(y) * globals::SPRITE_SCALE,
								std::ceil(width) * globals::SPRITE_SCALE,
								std::ceil(height) * globals::SPRITE_SCALE
						));

						pObject = pObject->NextSiblingElement("object");
					}
				}
			}
			//Other objectgroups go here with an else if (ss.str() == "whatever")
			else if (ss.str() == "slopes") {
				XMLElement* pObject = pObjectGroup->FirstChildElement("object");
				if (pObject != NULL) {
					while (pObject) {
						std::vector<Vector2> points;
						Vector2 p1;
						p1 = Vector2(std::ceil(pObject->FloatAttribute("x")), std::ceil(pObject->FloatAttribute("y")));

						XMLElement* pPolyline = pObject->FirstChildElement("polyline");
						if (pPolyline != NULL) {
							std::vector<std::string> pairs;
							const char* pointString = pPolyline->Attribute("points");

							std::stringstream ss;
							ss << pointString;
							Utils::split(ss.str(), pairs, ' ');
							//Now we have each of the pairs. Loop through the list of pairs
							//and split them into Vector2s and then store them in our points vector
							for (int i = 0; i < pairs.size(); i++) {
								std::vector<std::string> ps;
								Utils::split(pairs.at(i), ps, ',');
								points.push_back(Vector2(std::stoi(ps.at(0)), std::stoi(ps.at(1))));
							}
						}

						for (int i = 0; i < points.size(); i += 2) {
							this->_slopes.push_back(Slope(
									Vector2((p1.x + points.at(i < 2 ? i : i - 1).x) * globals::SPRITE_SCALE,
											(p1.y + points.at(i < 2 ? i : i - 1).y) * globals::SPRITE_SCALE),
									Vector2((p1.x + points.at(i < 2 ? i + 1 : i).x) * globals::SPRITE_SCALE,
											(p1.y + points.at(i < 2 ? i + 1 : i).y) * globals::SPRITE_SCALE)
							));
						}

						pObject = pObject->NextSiblingElement("object");
					}
				}
			}
			else if (ss.str() == "spawn points") {
				XMLElement* pObject = pObjectGroup->FirstChildElement("object");
				if (pObject != NULL) {
					while (pObject) {
						float x = pObject->FloatAttribute("x");
						float y = pObject->FloatAttribute("y");
						const char* name = pObject->Attribute("name");
						std::stringstream ss;
						ss << name;
						if (ss.str() == "player") {
							this->_spawnPoint = Vector2(std::ceil(x) * globals::SPRITE_SCALE,
									std::ceil(y) * globals::SPRITE_SCALE);
						}

						pObject = pObject->NextSiblingElement("object");
					}
				}
			}

			pObjectGroup = pObjectGroup->NextSiblingElement("objectgroup");
		}
	}
}
Exemplo n.º 29
0
int Configure::load(const string& xmlpath)
{
    if (m_doc.LoadFile(xmlpath.c_str()) != XML_NO_ERROR) {
        g_sysLog.e("{Configure} can't load xml %s\n", xmlpath.c_str());
        return ERR_LDCFG;
    }

    XMLElement* rootElement = m_doc.RootElement();
    if (rootElement == NULL) {
        g_sysLog.e("{Configure} can't get root element %s\n", xmlpath.c_str());
        return ERR_LDCFG;    
    } else {
        bool reset = rootElement->IntAttribute("reset");
        if (reset)
            return ERR_LDCFG;

        int ver = rootElement->IntAttribute("version");
        if (ver != CONF_VERSION)
            return ERR_LDCFG; // Recreate configure.xml
    }

    XMLElement* tempElement = rootElement->FirstChildElement("srclan");
    if (tempElement && tempElement->GetText()) {
        m_srcLan = tempElement->GetText();
    }

    tempElement = rootElement->FirstChildElement("detlan");
    if (tempElement && tempElement->GetText()) {
        m_detLan = tempElement->GetText();
    }

    // Loading dictionary 
    vector<string> dictFiles;
    scanDictDir(dictFiles);

    XMLElement* dictsElement = rootElement->FirstChildElement("dict");
    XMLElement* dictElement = dictsElement->FirstChildElement();
    while (dictElement) {
        struct DictNode dict;
        const char* textE;
        int pos;

        if (dictElement->FirstChildElement("path")) {
            if ((textE = dictElement->FirstChildElement("path")->GetText()) != NULL)
                dict.path = textE;
        }

        if ((pos = findDict(dict.path, dictFiles)) == -1 ) {
            dictsElement->DeleteChild(dictElement);
            dictElement = dictElement->NextSiblingElement();
            continue;
        }
        dictFiles[pos] = "";

        dict.en = dictElement->BoolAttribute("en");
        if (dictElement->Attribute("open"))
            dict.open   = string(dictElement->Attribute("open"));

        if (dictElement->FirstChildElement("srclan")) {
            if ((textE = dictElement->FirstChildElement("srclan")->GetText()) != NULL)
                dict.srclan = textE;
        }
        if (dictElement->FirstChildElement("detlan")) {
	    if ((textE = dictElement->FirstChildElement("detlan")->GetText()) != NULL)
                dict.detlan = textE;
        }

        if (dictElement->FirstChildElement("name")) {
            if ((textE = dictElement->FirstChildElement("name")->GetText()) != NULL)
                dict.name = textE;
        }

        if (dictElement->FirstChildElement("summary")) {
            if ((textE = dictElement->FirstChildElement("summary")->GetText()) != NULL)
	        dict.summary = textE;
        }
        m_dictNodes.push_back(dict);
        dictElement = dictElement->NextSiblingElement();
    }

    vector<string>::iterator iter = dictFiles.begin();
    for (; iter != dictFiles.end(); iter++) {
        if (*iter != "") {
            struct DictNode d;
            d.en = true;
            d.path = *iter;
            d.name = boost::filesystem::path(d.path).filename().string();
            //printf("%s\n",d.name.c_str());
            m_dictNodes.push_back(d);
        }
    }
    // Loading dictionary -- end

    tempElement = rootElement->FirstChildElement(XML_TAG_CWS);
    if (tempElement) {
        m_cws.bselection  = tempElement->BoolAttribute("selection");
        m_cws.bclipboard  = tempElement->BoolAttribute("clipboard");
        m_cws.bmouse      = tempElement->BoolAttribute("mouse");
        m_cws.benable     = tempElement->BoolAttribute("enable"); 
        m_cws.shortcutKey = tempElement->IntAttribute("shortcutkey");
        m_cws.autoCloseEn = tempElement->BoolAttribute("AutoCloseEnable");
        m_cws.autoCloseInv= tempElement->IntAttribute("AutoCloseInterval");
    } else {
        m_cws.benable    = false;
        m_cws.bselection = true;
        m_cws.bmouse     = false;
        m_cws.bclipboard = false;
        m_cws.shortcutKey = 'g'-'a';
        m_cws.autoCloseEn  = true;
        m_cws.autoCloseInv = 1000*10;

        XMLElement* e = m_doc.NewElement(XML_TAG_CWS);
        e->SetAttribute("selection",        m_cws.bselection);
        e->SetAttribute("clipboard",        m_cws.bclipboard);
        e->SetAttribute("mouse",            m_cws.bmouse);
        e->SetAttribute("enable",           m_cws.benable);
        e->SetAttribute("shortcutkey",      m_cws.shortcutKey);
        e->SetAttribute("AutoCloseEnable",  m_cws.autoCloseEn);
        e->SetAttribute("AutoCloseInterval",m_cws.autoCloseInv);

        rootElement->InsertEndChild(e);
    }

    tempElement = rootElement->FirstChildElement(XML_TAG_SETTING);
    if (tempElement) {
        m_setting.uilanID     = tempElement->IntAttribute("uilan");
        m_setting.fontsize    = tempElement->IntAttribute("fontsize");
        m_setting.font        = util::XMLUtil::Attribute(tempElement, "font", "");
        m_setting.bsystemTray = tempElement->BoolAttribute("systemtray");
    } else {
        m_setting.uilanID = UILAN_NONE;
        m_setting.fontsize = 10;
        m_setting.font = "";
        m_setting.bsystemTray = true;

        XMLElement* e = m_doc.NewElement(XML_TAG_SETTING);
        e->SetAttribute("uilan", m_setting.uilanID);
        e->SetAttribute("fontsize", m_setting.fontsize);

        rootElement->InsertEndChild(e);
    }

    m_doc.SaveFile(xmlpath.c_str());
    return 0;
}
Exemplo n.º 30
0
void Level::loadMap(std::string mapName, Graphics &graphics) {
	//Parse the .tmx file
	XMLDocument doc;
	std::stringstream ss;
	ss << "content/maps/" << mapName << ".tmx"; //"Map 1" = content/maps/Map 1.tmx
	doc.LoadFile(ss.str().c_str());

	XMLElement* mapNode = doc.FirstChildElement("map");

	//Get the width and the height of the whole map and store it in _size
	int height,width;
	mapNode->QueryIntAttribute("width", &width);
	mapNode->QueryIntAttribute("height",&height);
	this->_size = Vector2(width,height);

	//Get the width and the height of the tiles and store it in _tileSize
	int tileWidth, tileHeight;
	mapNode->QueryIntAttribute("tilewidth", &tileWidth);
	mapNode->QueryIntAttribute("tileheight",&tileHeight);
	this->_tileSize = Vector2(tileWidth,tileHeight);

	//load tilesets
	XMLElement* pTileset = mapNode->FirstChildElement("tileset");
	if(pTileset != NULL) {
		while(pTileset) {
			int firstgid;
			const char* source = pTileset->FirstChildElement("image")->Attribute("source");
			std::string path(source);
			path = path.substr(3,path.length());
			std::stringstream ss;
			ss << "content/" << path;
			pTileset->QueryIntAttribute("firstgid", &firstgid);
			SDL_Texture* tex = SDL_CreateTextureFromSurface(graphics.getRenderer(), graphics.loadImage(ss.str()));
			this->_tilesets.push_back(Tileset(tex, firstgid));
			pTileset = pTileset->NextSiblingElement("tileset");
		}
	}

	//Loading the layers
	XMLElement* pLayer = mapNode->FirstChildElement("layer");
	if(pLayer != NULL) {
		while(pLayer) {
			//Loading the data element
			XMLElement* pData = pLayer->FirstChildElement("data");
			if(pData != NULL) {
				while(pData){
					//Loading the tile element
					XMLElement* pTile = pData->FirstChildElement("tile");
					if(pTile != NULL) {
						int tileCounter = 0;
						while(pTile){
							//Build each individual tile here
							//if gid is 0, no tile should be drawn. Continue loop
							if(pTile->IntAttribute("gid") == 0){
								tileCounter++;
								if(pTile->NextSiblingElement("tile")){
									pTile = pTile->NextSiblingElement("tile");
									continue;
								} else {
									break;
								}
							}

							//Get the tileset for this specific gid
							int gid = pTile->IntAttribute("gid");
							Tileset tls;
							for(int i = 0; i < this->_tilesets.size(); i++) {
								if(this->_tilesets[i].FirstGid <= gid) {
									//This is the tileset we want
									tls = this->_tilesets.at(i);
									break;
								}
							}
							if(tls.FirstGid == -1) {
								//No tileset was found for this gid
								tileCounter++;
								if(pTile->NextSiblingElement("tile")) {
									pTile = pTile->NextSiblingElement("tile");
									continue;
								}
								else{
									break;
								}
							}

							//Get the position of the tile in the level
							int xx = 0;
							int yy = 0;
							xx = tileCounter % width;
							xx = xx * tileWidth;
							yy = yy + (tileHeight * (tileCounter/width));
							Vector2 finalTilePosition = Vector2(xx,yy);

							//Calculate the position of the tile in the tileset
							int tilesetWidth, tilesetHeight;
							SDL_QueryTexture(tls.Texture, NULL, NULL, &tilesetWidth, &tilesetHeight);
							int tsxx = gid % (tilesetWidth / tileWidth) - 1;
							tsxx = tsxx * tileWidth;
							int tsyy = 0;
							int amt = (gid / (tilesetWidth / tileWidth));
							tsyy = tileHeight * amt;
							Vector2 finalTilesetPosition = Vector2(tsxx, tsyy);

							//Build the actual tile and add it to the level's tile list
							Tile tile(tls.Texture, Vector2(tileWidth, tileHeight),
									finalTilesetPosition, finalTilePosition);
							this->_tileList.push_back(tile);
							tileCounter++;

							pTile = pTile->NextSiblingElement("tile");
						}
					}

					pData = pData->NextSiblingElement("data");
				}
			}
			pLayer = pLayer->NextSiblingElement("layer");
		}
	}

	//Parse out the collisions
	XMLElement* pObjectGroup = mapNode->FirstChildElement("objectgroup");
	if(pObjectGroup != NULL){
		while(pObjectGroup) {
			const char* name = pObjectGroup->Attribute("name");
			std::stringstream ss;
			ss << name;
			if(ss.str() == "collisions") {
				XMLElement* pObject = pObjectGroup->FirstChildElement("object");
				if(pObject != NULL){
					while(pObject) {
						float x, y, width, height;
						x = pObject->FloatAttribute("x");
						y = pObject->FloatAttribute("y");
						width = pObject->FloatAttribute("width");
						height = pObject->FloatAttribute("height");
						this->_collisionRects.push_back(Rectangle(
								std::ceil(x) * globals::SPRITE_SCALE,
								std::ceil(y) * globals::SPRITE_SCALE,
								std::ceil(width) * globals::SPRITE_SCALE,
								std::ceil(height) * globals::SPRITE_SCALE
						));

						pObject = pObject->NextSiblingElement("object");
					}
				}
			}else if(ss.str() == "spawn points") {
				XMLElement* pObject = pObjectGroup->FirstChildElement("object");
				if(pObject != NULL) {
					while(pObject) {
						float x = pObject->FloatAttribute("x");
						float y = pObject->FloatAttribute("y");
						const char* name = pObject->Attribute("name");
						std::stringstream ss;
						ss << name;
						if(ss.str() == "player") {
							this->_spawnPoint = Vector2(std::ceil(x) * globals::SPRITE_SCALE, std::ceil(y) * globals::SPRITE_SCALE);
						}

						pObject = pObject->NextSiblingElement("object");
					}
				}
			}
			//Other objectgroups go here with an else if (ss.str() == "whatevs son") {

			pObjectGroup = pObjectGroup->NextSiblingElement("objectgroup");
		}
	}
}