summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-04-27 17:17:39 +0300
committerAndrei Karas <akaras@inbox.ru>2014-04-27 17:17:39 +0300
commit4776d255f4bc25178f1123d03488ad01996e7a7e (patch)
tree833204279373efe173678f0be884bdee6a7610c2 /src
parent370612270d09fe557c13b97119b259b5c2eb4b45 (diff)
downloadmanaverse-4776d255f4bc25178f1123d03488ad01996e7a7e.tar.gz
manaverse-4776d255f4bc25178f1123d03488ad01996e7a7e.tar.bz2
manaverse-4776d255f4bc25178f1123d03488ad01996e7a7e.tar.xz
manaverse-4776d255f4bc25178f1123d03488ad01996e7a7e.zip
Add support for <animation> tag in map files.
Diffstat (limited to 'src')
-rw-r--r--src/resources/mapreader.cpp92
1 files 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<std::string, int> 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<std::string, int> 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<std::string, int>::const_iterator iFrame
- = tileProperties.find("animation-frame" + iStr);
- const std::map<std::string, int>::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<std::string, int>::const_iterator iFrame
+ = tileProperties.find("animation-frame" + iStr);
+ const std::map<std::string, int>::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);
}
}