void TileLayer::Parse(const TiXmlNode *layerNode) { ParseLayer(layerNode); // Allocate memory for reading the tiles. tile_map = new MapTile[GetWidth() * GetHeight()]; const TiXmlNode *dataNode = layerNode->FirstChild("data"); const TiXmlElement *dataElem = dataNode->ToElement(); const char *encodingStr = dataElem->Attribute("encoding"); const char *compressionStr = dataElem->Attribute("compression"); // Check for encoding. if (encodingStr) { if (!strcmp(encodingStr, "base64")) { encoding = TMX_ENCODING_BASE64; } else if (!strcmp(encodingStr, "csv")) { encoding = TMX_ENCODING_CSV; } } // Check for compression. if (compressionStr) { if (!strcmp(compressionStr, "gzip")) { compression = TMX_COMPRESSION_GZIP; } else if (!strcmp(compressionStr, "zlib")) { compression = TMX_COMPRESSION_ZLIB; } } // Decode. switch (encoding) { case TMX_ENCODING_XML: ParseXML(dataNode); break; case TMX_ENCODING_BASE64: ParseBase64(dataElem->GetText()); break; case TMX_ENCODING_CSV: ParseCSV(dataElem->GetText()); break; } }
void Layer::Parse(const TiXmlNode *layerNode) { const TiXmlElement *layerElem = layerNode->ToElement(); // Read the attributes. name = layerElem->Attribute("name"); layerElem->Attribute("width", &width); layerElem->Attribute("height", &height); const char *opacityStr = layerElem->Attribute("opacity"); if (opacityStr) { opacity = (float)atof(opacityStr); } const char *visibleStr = layerElem->Attribute("visible"); if (visibleStr) { visible = atoi(visibleStr) != 0; // to prevent visual c++ from complaining.. } // Read the properties. const TiXmlNode *propertiesNode = layerNode->FirstChild("properties"); if (propertiesNode) { properties.Parse(propertiesNode); } // Allocate memory for reading the tiles. tile_map = new MapTile[width * height]; const TiXmlNode *dataNode = layerNode->FirstChild("data"); const TiXmlElement *dataElem = dataNode->ToElement(); const char *encodingStr = dataElem->Attribute("encoding"); const char *compressionStr = dataElem->Attribute("compression"); // Check for encoding. if (encodingStr) { if (!strcmp(encodingStr, "base64")) { encoding = TMX_ENCODING_BASE64; } else if (!strcmp(encodingStr, "csv")) { encoding = TMX_ENCODING_CSV; } } // Check for compression. if (compressionStr) { if (!strcmp(compressionStr, "gzip")) { compression = TMX_COMPRESSION_GZIP; } else if (!strcmp(compressionStr, "zlib")) { compression = TMX_COMPRESSION_ZLIB; } } // Decode. switch (encoding) { case TMX_ENCODING_XML: ParseXML(dataNode); break; case TMX_ENCODING_BASE64: ParseBase64(dataElem->GetText()); break; case TMX_ENCODING_CSV: ParseCSV(dataElem->GetText()); break; } }
void TileLayer::Parse(const tinyxml2::XMLNode *tileLayerNode) { const tinyxml2::XMLElement *tileLayerElem = tileLayerNode->ToElement(); // Read the attributes. name = tileLayerElem->Attribute("name"); tileLayerElem->QueryIntAttribute("x", &x); tileLayerElem->QueryIntAttribute("y", &y); tileLayerElem->QueryFloatAttribute("opacity", &opacity); tileLayerElem->QueryBoolAttribute("visible", &visible); // Read the properties. const tinyxml2::XMLNode *propertiesNode = tileLayerNode->FirstChildElement("properties"); if (propertiesNode) { properties.Parse(propertiesNode); } // Allocate memory for reading the tiles. tile_map = new MapTile[width * height]; //const tinyxml2::XMLNode *dataNode = tileLayerNode->FirstChildElement("data"); const tinyxml2::XMLElement *dataElem = tileLayerNode->FirstChildElement("data"); const char *encodingStr = dataElem->Attribute("encoding"); const char *compressionStr = dataElem->Attribute("compression"); // Check for encoding. if (encodingStr) { if (!strcmp(encodingStr, "base64")) { encoding = TMX_ENCODING_BASE64; } else if (!strcmp(encodingStr, "csv")) { encoding = TMX_ENCODING_CSV; } } // Check for compression. if (compressionStr) { if (!strcmp(compressionStr, "gzip")) { compression = TMX_COMPRESSION_GZIP; } else if (!strcmp(compressionStr, "zlib")) { compression = TMX_COMPRESSION_ZLIB; } } // Decode. switch (encoding) { case TMX_ENCODING_XML: ParseXML(dataElem); break; case TMX_ENCODING_BASE64: ParseBase64(dataElem->GetText()); break; case TMX_ENCODING_CSV: ParseCSV(dataElem->GetText()); break; } }