diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-18 18:20:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-18 18:23:44 +0300 |
commit | a3ad4ab670c7fa776375f569e9fe9d7fbe227245 (patch) | |
tree | 53ff5ff6a5947af648125b7626229b3ca423aba4 | |
parent | cca1dbbcba03e5c50e92096503b612fba5b399a2 (diff) | |
download | manaplus-a3ad4ab670c7fa776375f569e9fe9d7fbe227245.tar.gz manaplus-a3ad4ab670c7fa776375f569e9fe9d7fbe227245.tar.bz2 manaplus-a3ad4ab670c7fa776375f569e9fe9d7fbe227245.tar.xz manaplus-a3ad4ab670c7fa776375f569e9fe9d7fbe227245.zip |
Change a bit horses.xml format.
-rw-r--r-- | src/resources/db/horsedb.cpp | 68 |
1 files changed, 52 insertions, 16 deletions
diff --git a/src/resources/db/horsedb.cpp b/src/resources/db/horsedb.cpp index e01ebe27c..41754bd77 100644 --- a/src/resources/db/horsedb.cpp +++ b/src/resources/db/horsedb.cpp @@ -37,6 +37,19 @@ namespace bool mLoaded = false; } +#define loadSprite(name) \ + currentInfo->name = AnimatedSprite::load( \ + paths.getStringValue("sprites").append(std::string( \ + reinterpret_cast<const char*>( \ + spriteNode->xmlChildrenNode->content))), \ + XML::getProperty(spriteNode, "variant", 0)) + +static void loadDownSprites(XmlNodePtrConst parentNode, + HorseInfo *currentInfo); + +static void loadUpSprites(XmlNodePtrConst parentNode, + HorseInfo *currentInfo); + void HorseDB::load() { if (mLoaded) @@ -115,27 +128,50 @@ void HorseDB::loadXmlFile(const std::string &fileName) if (!spriteNode->xmlChildrenNode) continue; - if (xmlNameEqual(spriteNode, "downSprite")) - { - currentInfo->downSprite = AnimatedSprite::load( - paths.getStringValue("sprites").append(std::string( - reinterpret_cast<const char*>( - spriteNode->xmlChildrenNode->content))), - XML::getProperty(spriteNode, "variant", 0)); - } - else if (xmlNameEqual(spriteNode, "upSprite")) - { - currentInfo->upSprite = AnimatedSprite::load( - paths.getStringValue("sprites").append(std::string( - reinterpret_cast<const char*>( - spriteNode->xmlChildrenNode->content))), - XML::getProperty(spriteNode, "variant", 0)); - } + if (xmlNameEqual(spriteNode, "sprite")) + loadSprite(downSprite); + + if (xmlNameEqual(spriteNode, "down")) + loadDownSprites(spriteNode, currentInfo); + else if (xmlNameEqual(spriteNode, "up")) + loadUpSprites(spriteNode, currentInfo); } mHorseInfos[id] = currentInfo; } } +static void loadDownSprites(XmlNodePtrConst parentNode, + HorseInfo *currentInfo) +{ + for_each_xml_child_node(spriteNode, parentNode) + { + if (!spriteNode->xmlChildrenNode) + continue; + + if (xmlNameEqual(spriteNode, "sprite")) + { + loadSprite(downSprite); + return; + } + } +} + +static void loadUpSprites(XmlNodePtrConst parentNode, + HorseInfo *currentInfo) +{ + for_each_xml_child_node(spriteNode, parentNode) + { + if (!spriteNode->xmlChildrenNode) + continue; + + if (xmlNameEqual(spriteNode, "sprite")) + { + loadSprite(upSprite); + return; + } + } +} + void HorseDB::unload() { FOR_EACH (HorseInfos::const_iterator, i, mHorseInfos) |