Beispiel #1
0
	void Tileset::ParseElement(const TiXmlElement *tilesetElem)
	{
		// Read all the attributes into local variables.
		tilesetElem->Attribute("tilewidth", &tile_width);
		tilesetElem->Attribute("tileheight", &tile_height);
		tilesetElem->Attribute("margin", &margin);
		tilesetElem->Attribute("spacing", &spacing);

        char const *rawName = tilesetElem->Attribute("name");
		name = (rawName == NULL) ? "" : rawName;

		// Parse the image.
		const TiXmlNode *imageNode = tilesetElem->FirstChild("image");
		
		if (imageNode) 
		{
			image = new Image();
			image->Parse(imageNode);
		}

		// Iterate through all of the tile elements and parse each.
		const TiXmlNode *tileNode = tilesetElem->FirstChild("tile");
		while (tileNode)
		{
			// Allocate a new tile and parse it.
			Tile *tile = new Tile();
			tile->Parse(tileNode);

			// Add the tile to the collection.
			tiles.push_back(tile);

			tileNode = tilesetElem->IterateChildren("tile", tileNode);
		}
	}
Beispiel #2
0
    void Tileset::Parse(const tinyxml2::XMLNode *tilesetNode) 
    {
        const tinyxml2::XMLElement *tilesetElem = tilesetNode->ToElement();

        // Read all the attributes into local variables.
        first_gid = tilesetElem->IntAttribute("firstgid");
        tile_width = tilesetElem->IntAttribute("tilewidth");
        tile_height = tilesetElem->IntAttribute("tileheight");
        margin = tilesetElem->IntAttribute("margin");
        spacing = tilesetElem->IntAttribute("spacing");

        name = tilesetElem->Attribute("name");

        // Parse the image.
        const tinyxml2::XMLNode *imageNode = tilesetNode->FirstChildElement("image");
        
        if (imageNode) 
        {
            image = new Image();
            image->Parse(imageNode);
        }

        // Populate the tile list
        int tileCount = (image->GetWidth() / tile_width) * (image->GetHeight() / tile_height);

        int tId = tiles.size();
        while (tId < tileCount)
        {
            Tile* tile = new Tile(tId);
            tiles.push_back(tile);
            tId++;
        }


        // Iterate through all of the tile elements and parse each.
        const tinyxml2::XMLNode *tileNode = tilesetNode->FirstChildElement("tile");
        while (tileNode)
        {
            // Parse it to get the tile id.
            Tile tile;
            tile.Parse(tileNode);

            // Using the ID in the temporary tile get the real tile and parse for real.
            tiles[tile.GetId()]->Parse(tileNode);

            //tileNode = tilesetNode->IterateChildren("tile", tileNode); FIXME MAYBE
            tileNode = tileNode->NextSiblingElement("tile");
        }

        
        // Parse the properties if any.
        const tinyxml2::XMLNode *propertiesNode = tilesetNode->FirstChildElement("properties");
        
        if (propertiesNode) 
        {
            properties.Parse(propertiesNode);
        }
    }
Beispiel #3
0
	void Tileset::Parse(const TiXmlNode *tilesetNode) 
	{
		const TiXmlElement *tilesetElem = tilesetNode->ToElement();

		// Read all the attributes into local variables.
		tilesetElem->Attribute("firstgid", &first_gid);
		tilesetElem->Attribute("tilewidth", &tile_width);
		tilesetElem->Attribute("tileheight", &tile_height);
		tilesetElem->Attribute("margin", &margin);
		tilesetElem->Attribute("spacing", &spacing);

		name = tilesetElem->Attribute("name");

		// Parse the image.
		const TiXmlNode *imageNode = tilesetNode->FirstChild("image");
		
		if (imageNode) 
		{
			image = new Image();
			image->Parse(imageNode);
		}

		// Iterate through all of the tile elements and parse each.
		const TiXmlNode *tileNode = tilesetNode->FirstChild("tile");
		while (tileNode)
		{
			// Allocate a new tile and parse it.
			Tile *tile = new Tile();
			tile->Parse(tileNode);

			// Add the tile to the collection.
			tiles.push_back(tile);

			tileNode = tilesetNode->IterateChildren("tile", tileNode);
		}
		
		// Parse the properties if any.
		const TiXmlNode *propertiesNode = tilesetNode->FirstChild("properties");
		
		if (propertiesNode) 
		{
			properties.Parse(propertiesNode);
		}
	}
Beispiel #4
0
    void Tileset::Parse(const tinyxml2::XMLNode *tilesetNode, const std::string& file_path)
    {
        const tinyxml2::XMLElement *tilesetElem = tilesetNode->ToElement();

        // Read all the attributes into local variables.

        // The firstgid and source attribute are kept in the TMX map,
        // since they are map specific.
        first_gid = tilesetElem->IntAttribute("firstgid");

        // If the <tileset> node contains a 'source' tag,
        // the tileset config should be loaded from an external
        // TSX (Tile Set XML) file. That file has the same structure
        // as the <tileset> element in the TMX map.
        const char* source_name = tilesetElem->Attribute("source");
        tinyxml2::XMLDocument tileset_doc;
        if ( source_name )
        {
            std::string fileName = file_path + source_name;
            tileset_doc.LoadFile( fileName.c_str() );

            if ( tileset_doc.ErrorID() != 0)
            {
                fprintf(stderr, "failed to load tileset file '%s'\n", fileName.c_str());
                return;
            }

            // Update node and element references to the new node
            tilesetNode = tileset_doc.FirstChildElement("tileset");
            tilesetElem = tilesetNode->ToElement();
        }

        tile_width = tilesetElem->IntAttribute("tilewidth");
        tile_height = tilesetElem->IntAttribute("tileheight");
        margin = tilesetElem->IntAttribute("margin");
        spacing = tilesetElem->IntAttribute("spacing");
        name = tilesetElem->Attribute("name");

        // Parse the tile offset, if it exists.
        const tinyxml2::XMLNode *tileOffsetNode = tilesetNode->FirstChildElement("tileoffset");
        if (tileOffsetNode)
        {
            tileOffset = new TileOffset();
            tileOffset->Parse(tileOffsetNode);
        }

        // Parse the terrain types if any.
        const tinyxml2::XMLNode *terrainTypesNode = tilesetNode->FirstChildElement("terraintypes");
        if (terrainTypesNode) 
        {
            TerrainArray terrainArray;
            terrainArray.Parse(&terrainTypes, terrainTypesNode);
        }

        // Parse the image.
        const tinyxml2::XMLNode *imageNode = tilesetNode->FirstChildElement("image");
        if (imageNode) 
        {
            image = new Image();
            image->Parse(imageNode);
        }

        // Iterate through all of the tile elements and parse each.
        const tinyxml2::XMLNode *tileNode = tilesetNode->FirstChildElement("tile");
        for (int tId = 0; tileNode; ++tId)
        {
            Tile* tile = new Tile(tId);
            tile->Parse(tileNode);
            tiles.push_back(tile);

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

        // Parse the properties if any.
        const tinyxml2::XMLNode *propertiesNode = tilesetNode->FirstChildElement("properties");
        if (propertiesNode)
        {
            properties.Parse(propertiesNode);
        }
    }
Beispiel #5
0
	void Tileset::Parse(const TiXmlNode *tilesetNode) 
	{
		const TiXmlElement *tilesetElem = tilesetNode->ToElement();

		// Read all the attributes into local variables.
		tilesetElem->Attribute("firstgid", &first_gid);
		tilesetElem->Attribute("tilewidth", &tile_width);
		tilesetElem->Attribute("tileheight", &tile_height);
		tilesetElem->Attribute("margin", &margin);
		tilesetElem->Attribute("spacing", &spacing);

		name = tilesetElem->Attribute("name");

		// IGNACIO CEA
		// Parser the offset
		const TiXmlNode *offsetNode = tilesetNode->FirstChild("tileoffset");

		if (offsetNode)
		{
			const TiXmlElement *offsetElement = offsetNode->ToElement();
			offsetElement->Attribute("x", &x_offset);
			offsetElement->Attribute("y", &y_offset);
		}
		// IGNACIO CEA

		// Parse the image.
		const TiXmlNode *imageNode = tilesetNode->FirstChild("image");
		
		if (imageNode) 
		{
			image = new Image();
			image->Parse(imageNode);
		}

        // Populate the tile list
        int tileCount = (image->GetWidth() / tile_width) * (image->GetHeight() / tile_height);

        int tId = tiles.size();
        while (tId < tileCount)
        {
            Tile* tile = new Tile(tId);
            tiles.push_back(tile);
            tId++;
        }


        // Iterate through all of the tile elements and parse each.
        const TiXmlNode *tileNode = tilesetNode->FirstChild("tile");
        while (tileNode)
		{
            // Parse it to get the tile id.
            Tile tile;
            tile.Parse(tileNode);

            // Using the ID in the temporary tile get the real tile and parse for real.
            tiles[tile.GetId()]->Parse(tileNode);

            tileNode = tilesetNode->IterateChildren("tile", tileNode);
		}

		
		// Parse the properties if any.
		const TiXmlNode *propertiesNode = tilesetNode->FirstChild("properties");
		
		if (propertiesNode) 
		{
			properties.Parse(propertiesNode);
		}
	}