summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-10-18 18:20:38 +0300
committerAndrei Karas <akaras@inbox.ru>2015-10-18 18:23:44 +0300
commita3ad4ab670c7fa776375f569e9fe9d7fbe227245 (patch)
tree53ff5ff6a5947af648125b7626229b3ca423aba4 /src
parentcca1dbbcba03e5c50e92096503b612fba5b399a2 (diff)
downloadmv-a3ad4ab670c7fa776375f569e9fe9d7fbe227245.tar.gz
mv-a3ad4ab670c7fa776375f569e9fe9d7fbe227245.tar.bz2
mv-a3ad4ab670c7fa776375f569e9fe9d7fbe227245.tar.xz
mv-a3ad4ab670c7fa776375f569e9fe9d7fbe227245.zip
Change a bit horses.xml format.
Diffstat (limited to 'src')
-rw-r--r--src/resources/db/horsedb.cpp68
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)