From 4776d255f4bc25178f1123d03488ad01996e7a7e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 27 Apr 2014 17:17:39 +0300 Subject: Add support for tag in map files. --- src/resources/mapreader.cpp | 92 +++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index baabbeaec..e16d1d850 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -926,54 +926,80 @@ Tileset *MapReader::readTileset(XmlNodePtr node, } else if (xmlNameEqual(childNode, "tile")) { + bool haveAnimation(false); + for_each_xml_child_node(tileNode, childNode) { - if (!xmlNameEqual(tileNode, "properties")) + const bool isProps = xmlNameEqual(tileNode, "properties"); + const bool isAnim = xmlNameEqual(tileNode, "animation"); + if (!isProps && !isAnim) continue; const int tileGID = firstGid + XML::getProperty( childNode, "id", 0); - // read tile properties to a map for simpler handling - std::map tileProperties; - for_each_xml_child_node(propertyNode, tileNode) + Animation *ani = new Animation; + + if (isProps) { - if (!xmlNameEqual(propertyNode, "property")) - continue; - const std::string name = XML::getProperty( - propertyNode, "name", ""); - const int value = XML::getProperty( - propertyNode, "value", 0); - if (!name.empty()) + // read tile properties to a map for simpler handling + std::map tileProperties; + for_each_xml_child_node(propertyNode, tileNode) { - tileProperties[name] = value; - logger->log("Tile Prop of %d \"%s\" = \"%d\"", - tileGID, name.c_str(), value); + if (!xmlNameEqual(propertyNode, "property")) + continue; + + haveAnimation = true; + const std::string name = XML::getProperty( + propertyNode, "name", ""); + const int value = XML::getProperty( + propertyNode, "value", 0); + if (!name.empty()) + { + tileProperties[name] = value; + logger->log("Tile Prop of %d \"%s\" = \"%d\"", + tileGID, name.c_str(), value); + } } - } - // create animation - if (!set || !config.getBoolValue("playMapAnimations")) - continue; + // create animation + if (!set || !config.getBoolValue("playMapAnimations")) + continue; - Animation *ani = new Animation; - for (int i = 0; ; i++) - { - const std::string iStr(toString(i)); - const std::map::const_iterator iFrame - = tileProperties.find("animation-frame" + iStr); - const std::map::const_iterator iDelay - = tileProperties.find("animation-delay" + iStr); - // possible need add random attribute? - if (iFrame != tileProperties.end() - && iDelay != tileProperties.end()) + for (int i = 0; ; i++) { - ani->addFrame(set->get(iFrame->second), - iDelay->second, 0, 0, 100); + const std::string iStr(toString(i)); + const std::map::const_iterator iFrame + = tileProperties.find("animation-frame" + iStr); + const std::map::const_iterator iDelay + = tileProperties.find("animation-delay" + iStr); + // possible need add random attribute? + if (iFrame != tileProperties.end() + && iDelay != tileProperties.end()) + { + ani->addFrame(set->get(iFrame->second), + iDelay->second, 0, 0, 100); + } + else + { + break; + } } - else + + } + else if (isAnim && !haveAnimation) + { + for_each_xml_child_node(frameNode, tileNode) { - break; + if (!xmlNameEqual(frameNode, "frame")) + continue; + + const int tileId = XML::getProperty( + frameNode, "tileid", 0); + const int duration = XML::getProperty( + frameNode, "duration", 0) / 10; + + ani->addFrame(set->get(tileId), duration, 0, 0, 100); } } -- cgit v1.2.3-60-g2f50