summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-25 16:34:34 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-25 16:34:34 +0300
commitd5fa4f03b3f09efd0551b0dfd8bc2dc7de4d4acc (patch)
treeb3b51fc292ab941792d698b300a3af366869a1db /src/resources
parent6ce16c283d584fc1a90a5e68f986a90fdc6e8da5 (diff)
downloadplus-d5fa4f03b3f09efd0551b0dfd8bc2dc7de4d4acc.tar.gz
plus-d5fa4f03b3f09efd0551b0dfd8bc2dc7de4d4acc.tar.bz2
plus-d5fa4f03b3f09efd0551b0dfd8bc2dc7de4d4acc.tar.xz
plus-d5fa4f03b3f09efd0551b0dfd8bc2dc7de4d4acc.zip
Remove duplicate code from monsterdb, homunculusdb, mercenarydb.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/beingcommon.cpp116
-rw-r--r--src/resources/beingcommon.h7
-rw-r--r--src/resources/db/homunculusdb.cpp110
-rw-r--r--src/resources/db/mercenarydb.cpp110
-rw-r--r--src/resources/db/monsterdb.cpp110
5 files changed, 129 insertions, 324 deletions
diff --git a/src/resources/beingcommon.cpp b/src/resources/beingcommon.cpp
index 388312b34..4b685f8bf 100644
--- a/src/resources/beingcommon.cpp
+++ b/src/resources/beingcommon.cpp
@@ -20,10 +20,14 @@
#include "resources/beingcommon.h"
+#include "configuration.h"
+#include "logger.h"
+
#include "utils/files.h"
#include "utils/stringutils.h"
#include "resources/beinginfo.h"
+#include "resources/spritereference.h"
#include <algorithm>
@@ -64,3 +68,115 @@ void BeingCommon::getIncludeFiles(const std::string &dir,
}
std::sort(list.begin(), list.end());
}
+
+bool BeingCommon::readObjectNodes(XmlNodePtr &spriteNode,
+ SpriteDisplay &display,
+ BeingInfo *const currentInfo,
+ const std::string &dbName)
+{
+ if (xmlNameEqual(spriteNode, "sprite"))
+ {
+ if (!spriteNode->xmlChildrenNode)
+ return true;
+
+ SpriteReference *const currentSprite = new SpriteReference;
+ currentSprite->sprite = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
+
+ currentSprite->variant = XML::getProperty(
+ spriteNode, "variant", 0);
+ display.sprites.push_back(currentSprite);
+ return true;
+ }
+ else if (xmlNameEqual(spriteNode, "sound"))
+ {
+ if (!spriteNode->xmlChildrenNode)
+ return true;
+
+ const std::string event = XML::getProperty(
+ spriteNode, "event", "");
+ const int delay = XML::getProperty(
+ spriteNode, "delay", 0);
+ const char *const filename = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
+
+ if (event == "hit")
+ {
+ currentInfo->addSound(ItemSoundEvent::HIT, filename, delay);
+ }
+ else if (event == "miss")
+ {
+ currentInfo->addSound(ItemSoundEvent::MISS, filename, delay);
+ }
+ else if (event == "hurt")
+ {
+ currentInfo->addSound(ItemSoundEvent::HURT, filename, delay);
+ }
+ else if (event == "die")
+ {
+ currentInfo->addSound(ItemSoundEvent::DIE, filename, delay);
+ }
+ else if (event == "move")
+ {
+ currentInfo->addSound(ItemSoundEvent::MOVE, filename, delay);
+ }
+ else if (event == "sit")
+ {
+ currentInfo->addSound(ItemSoundEvent::SIT, filename, delay);
+ }
+ else if (event == "sittop")
+ {
+ currentInfo->addSound(ItemSoundEvent::SITTOP, filename, delay);
+ }
+ else if (event == "spawn")
+ {
+ currentInfo->addSound(ItemSoundEvent::SPAWN, filename, delay);
+ }
+ else
+ {
+ logger->log((dbName + ": Warning, sound effect %s for "
+ "unknown event %s of monster %s").c_str(),
+ filename, event.c_str(),
+ currentInfo->getName().c_str());
+ }
+ return true;
+ }
+ else if (xmlNameEqual(spriteNode, "attack"))
+ {
+ const int attackId = XML::getProperty(spriteNode, "id", 0);
+ const int effectId = XML::getProperty(spriteNode, "effect-id",
+ paths.getIntValue("effectId"));
+ const int hitEffectId = XML::getProperty(spriteNode, "hit-effect-id",
+ paths.getIntValue("hitEffectId"));
+ const int criticalHitEffectId = XML::getProperty(spriteNode,
+ "critical-hit-effect-id",
+ paths.getIntValue("criticalHitEffectId"));
+ const int missEffectId = XML::getProperty(spriteNode, "miss-effect-id",
+ paths.getIntValue("missEffectId"));
+
+ const std::string spriteAction = XML::getProperty(spriteNode, "action",
+ "attack");
+ const std::string skySpriteAction = XML::getProperty(spriteNode,
+ "skyaction", "skyattack");
+ const std::string waterSpriteAction = XML::getProperty(spriteNode,
+ "wateraction", "waterattack");
+
+ const std::string missileParticle = XML::getProperty(spriteNode,
+ "missile-particle", "");
+
+ currentInfo->addAttack(attackId, spriteAction, skySpriteAction,
+ waterSpriteAction, effectId, hitEffectId,
+ criticalHitEffectId, missEffectId, missileParticle);
+ return true;
+ }
+ else if (xmlNameEqual(spriteNode, "particlefx"))
+ {
+ if (!spriteNode->xmlChildrenNode)
+ return true;
+
+ display.particles.push_back(reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content));
+ return true;
+ }
+ return false;
+}
diff --git a/src/resources/beingcommon.h b/src/resources/beingcommon.h
index 2c9741a2c..301dc284e 100644
--- a/src/resources/beingcommon.h
+++ b/src/resources/beingcommon.h
@@ -29,6 +29,8 @@
class BeingInfo;
+struct SpriteDisplay;
+
#define loadXmlDir(name, function) \
{ \
StringVect listVect; \
@@ -55,6 +57,11 @@ namespace BeingCommon
void getIncludeFiles(const std::string &dir,
StringVect &list,
const std::string &ext);
+
+ bool readObjectNodes(XmlNodePtr &node,
+ SpriteDisplay &display,
+ BeingInfo *const currentInfo,
+ const std::string &dbName);
}
#endif // RESOURCES_BEINGCOMMON_H
diff --git a/src/resources/db/homunculusdb.cpp b/src/resources/db/homunculusdb.cpp
index 76d8189db..317d0c2df 100644
--- a/src/resources/db/homunculusdb.cpp
+++ b/src/resources/db/homunculusdb.cpp
@@ -128,114 +128,8 @@ void HomunculusDB::loadXmlFile(const std::string &fileName)
// iterate <sprite>s and <sound>s
for_each_xml_child_node(spriteNode, homunculusNode)
{
- if (xmlNameEqual(spriteNode, "sprite"))
- {
- if (!spriteNode->xmlChildrenNode)
- continue;
-
- SpriteReference *const currentSprite = new SpriteReference;
- currentSprite->sprite = reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content);
-
- currentSprite->variant = XML::getProperty(
- spriteNode, "variant", 0);
- display.sprites.push_back(currentSprite);
- }
- else if (xmlNameEqual(spriteNode, "sound"))
- {
- if (!spriteNode->xmlChildrenNode)
- continue;
-
- const std::string event = XML::getProperty(
- spriteNode, "event", "");
- const int delay = XML::getProperty(
- spriteNode, "delay", 0);
- const char *const filename = reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content);
-
- if (event == "hit")
- {
- currentInfo->addSound(ItemSoundEvent::HIT,
- filename, delay);
- }
- else if (event == "miss")
- {
- currentInfo->addSound(ItemSoundEvent::MISS,
- filename, delay);
- }
- else if (event == "hurt")
- {
- currentInfo->addSound(ItemSoundEvent::HURT,
- filename, delay);
- }
- else if (event == "die")
- {
- currentInfo->addSound(ItemSoundEvent::DIE,
- filename, delay);
- }
- else if (event == "move")
- {
- currentInfo->addSound(ItemSoundEvent::MOVE,
- filename, delay);
- }
- else if (event == "sit")
- {
- currentInfo->addSound(ItemSoundEvent::SIT,
- filename, delay);
- }
- else if (event == "sittop")
- {
- currentInfo->addSound(ItemSoundEvent::SITTOP,
- filename, delay);
- }
- else if (event == "spawn")
- {
- currentInfo->addSound(ItemSoundEvent::SPAWN,
- filename, delay);
- }
- else
- {
- logger->log("HomunculusDB: Warning, sound effect %s for "
- "unknown event %s of homunculus %s",
- filename, event.c_str(),
- currentInfo->getName().c_str());
- }
- }
- else if (xmlNameEqual(spriteNode, "attack"))
- {
- const int attackId = XML::getProperty(spriteNode, "id", 0);
- const int effectId = XML::getProperty(
- spriteNode, "effect-id", paths.getIntValue("effectId"));
- const int hitEffectId = XML::getProperty(spriteNode,
- "hit-effect-id", paths.getIntValue("hitEffectId"));
- const int criticalHitEffectId = XML::getProperty(spriteNode,
- "critical-hit-effect-id",
- paths.getIntValue("criticalHitEffectId"));
- const int missEffectId = XML::getProperty(spriteNode,
- "miss-effect-id", paths.getIntValue("missEffectId"));
-
- const std::string spriteAction = XML::getProperty(
- spriteNode, "action", "attack");
- const std::string skySpriteAction = XML::getProperty(
- spriteNode, "skyaction", "skyattack");
- const std::string waterSpriteAction = XML::getProperty(
- spriteNode, "wateraction", "waterattack");
-
- const std::string missileParticle = XML::getProperty(
- spriteNode, "missile-particle", "");
-
- currentInfo->addAttack(attackId, spriteAction, skySpriteAction,
- waterSpriteAction, effectId, hitEffectId,
- criticalHitEffectId, missEffectId, missileParticle);
- }
- else if (xmlNameEqual(spriteNode, "particlefx"))
- {
- if (!spriteNode->xmlChildrenNode)
- continue;
-
- display.particles.push_back(reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content));
- }
+ BeingCommon::readObjectNodes(spriteNode, display,
+ currentInfo, "HomunculusDB");
}
currentInfo->setDisplay(display);
diff --git a/src/resources/db/mercenarydb.cpp b/src/resources/db/mercenarydb.cpp
index ed8be1ffe..432b64006 100644
--- a/src/resources/db/mercenarydb.cpp
+++ b/src/resources/db/mercenarydb.cpp
@@ -128,114 +128,8 @@ void MercenaryDB::loadXmlFile(const std::string &fileName)
// iterate <sprite>s and <sound>s
for_each_xml_child_node(spriteNode, mercenaryNode)
{
- if (xmlNameEqual(spriteNode, "sprite"))
- {
- if (!spriteNode->xmlChildrenNode)
- continue;
-
- SpriteReference *const currentSprite = new SpriteReference;
- currentSprite->sprite = reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content);
-
- currentSprite->variant = XML::getProperty(
- spriteNode, "variant", 0);
- display.sprites.push_back(currentSprite);
- }
- else if (xmlNameEqual(spriteNode, "sound"))
- {
- if (!spriteNode->xmlChildrenNode)
- continue;
-
- const std::string event = XML::getProperty(
- spriteNode, "event", "");
- const int delay = XML::getProperty(
- spriteNode, "delay", 0);
- const char *const filename = reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content);
-
- if (event == "hit")
- {
- currentInfo->addSound(ItemSoundEvent::HIT,
- filename, delay);
- }
- else if (event == "miss")
- {
- currentInfo->addSound(ItemSoundEvent::MISS,
- filename, delay);
- }
- else if (event == "hurt")
- {
- currentInfo->addSound(ItemSoundEvent::HURT,
- filename, delay);
- }
- else if (event == "die")
- {
- currentInfo->addSound(ItemSoundEvent::DIE,
- filename, delay);
- }
- else if (event == "move")
- {
- currentInfo->addSound(ItemSoundEvent::MOVE,
- filename, delay);
- }
- else if (event == "sit")
- {
- currentInfo->addSound(ItemSoundEvent::SIT,
- filename, delay);
- }
- else if (event == "sittop")
- {
- currentInfo->addSound(ItemSoundEvent::SITTOP,
- filename, delay);
- }
- else if (event == "spawn")
- {
- currentInfo->addSound(ItemSoundEvent::SPAWN,
- filename, delay);
- }
- else
- {
- logger->log("MercenaryDB: Warning, sound effect %s for "
- "unknown event %s of mercenary %s",
- filename, event.c_str(),
- currentInfo->getName().c_str());
- }
- }
- else if (xmlNameEqual(spriteNode, "attack"))
- {
- const int attackId = XML::getProperty(spriteNode, "id", 0);
- const int effectId = XML::getProperty(
- spriteNode, "effect-id", paths.getIntValue("effectId"));
- const int hitEffectId = XML::getProperty(spriteNode,
- "hit-effect-id", paths.getIntValue("hitEffectId"));
- const int criticalHitEffectId = XML::getProperty(spriteNode,
- "critical-hit-effect-id",
- paths.getIntValue("criticalHitEffectId"));
- const int missEffectId = XML::getProperty(spriteNode,
- "miss-effect-id", paths.getIntValue("missEffectId"));
-
- const std::string spriteAction = XML::getProperty(
- spriteNode, "action", "attack");
- const std::string skySpriteAction = XML::getProperty(
- spriteNode, "skyaction", "skyattack");
- const std::string waterSpriteAction = XML::getProperty(
- spriteNode, "wateraction", "waterattack");
-
- const std::string missileParticle = XML::getProperty(
- spriteNode, "missile-particle", "");
-
- currentInfo->addAttack(attackId, spriteAction, skySpriteAction,
- waterSpriteAction, effectId, hitEffectId,
- criticalHitEffectId, missEffectId, missileParticle);
- }
- else if (xmlNameEqual(spriteNode, "particlefx"))
- {
- if (!spriteNode->xmlChildrenNode)
- continue;
-
- display.particles.push_back(reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content));
- }
+ BeingCommon::readObjectNodes(spriteNode, display,
+ currentInfo, "MonsterDB");
}
currentInfo->setDisplay(display);
diff --git a/src/resources/db/monsterdb.cpp b/src/resources/db/monsterdb.cpp
index 7897d6198..1cbfe66c5 100644
--- a/src/resources/db/monsterdb.cpp
+++ b/src/resources/db/monsterdb.cpp
@@ -135,114 +135,8 @@ void MonsterDB::loadXmlFile(const std::string &fileName)
// iterate <sprite>s and <sound>s
for_each_xml_child_node(spriteNode, monsterNode)
{
- if (xmlNameEqual(spriteNode, "sprite"))
- {
- if (!spriteNode->xmlChildrenNode)
- continue;
-
- SpriteReference *const currentSprite = new SpriteReference;
- currentSprite->sprite = reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content);
-
- currentSprite->variant = XML::getProperty(
- spriteNode, "variant", 0);
- display.sprites.push_back(currentSprite);
- }
- else if (xmlNameEqual(spriteNode, "sound"))
- {
- if (!spriteNode->xmlChildrenNode)
- continue;
-
- const std::string event = XML::getProperty(
- spriteNode, "event", "");
- const int delay = XML::getProperty(
- spriteNode, "delay", 0);
- const char *const filename = reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content);
-
- if (event == "hit")
- {
- currentInfo->addSound(ItemSoundEvent::HIT,
- filename, delay);
- }
- else if (event == "miss")
- {
- currentInfo->addSound(ItemSoundEvent::MISS,
- filename, delay);
- }
- else if (event == "hurt")
- {
- currentInfo->addSound(ItemSoundEvent::HURT,
- filename, delay);
- }
- else if (event == "die")
- {
- currentInfo->addSound(ItemSoundEvent::DIE,
- filename, delay);
- }
- else if (event == "move")
- {
- currentInfo->addSound(ItemSoundEvent::MOVE,
- filename, delay);
- }
- else if (event == "sit")
- {
- currentInfo->addSound(ItemSoundEvent::SIT,
- filename, delay);
- }
- else if (event == "sittop")
- {
- currentInfo->addSound(ItemSoundEvent::SITTOP,
- filename, delay);
- }
- else if (event == "spawn")
- {
- currentInfo->addSound(ItemSoundEvent::SPAWN,
- filename, delay);
- }
- else
- {
- logger->log("MonsterDB: Warning, sound effect %s for "
- "unknown event %s of monster %s",
- filename, event.c_str(),
- currentInfo->getName().c_str());
- }
- }
- else if (xmlNameEqual(spriteNode, "attack"))
- {
- const int attackId = XML::getProperty(spriteNode, "id", 0);
- const int effectId = XML::getProperty(
- spriteNode, "effect-id", paths.getIntValue("effectId"));
- const int hitEffectId = XML::getProperty(spriteNode,
- "hit-effect-id", paths.getIntValue("hitEffectId"));
- const int criticalHitEffectId = XML::getProperty(spriteNode,
- "critical-hit-effect-id",
- paths.getIntValue("criticalHitEffectId"));
- const int missEffectId = XML::getProperty(spriteNode,
- "miss-effect-id", paths.getIntValue("missEffectId"));
-
- const std::string spriteAction = XML::getProperty(
- spriteNode, "action", "attack");
- const std::string skySpriteAction = XML::getProperty(
- spriteNode, "skyaction", "skyattack");
- const std::string waterSpriteAction = XML::getProperty(
- spriteNode, "wateraction", "waterattack");
-
- const std::string missileParticle = XML::getProperty(
- spriteNode, "missile-particle", "");
-
- currentInfo->addAttack(attackId, spriteAction, skySpriteAction,
- waterSpriteAction, effectId, hitEffectId,
- criticalHitEffectId, missEffectId, missileParticle);
- }
- else if (xmlNameEqual(spriteNode, "particlefx"))
- {
- if (!spriteNode->xmlChildrenNode)
- continue;
-
- display.particles.push_back(reinterpret_cast<const char*>(
- spriteNode->xmlChildrenNode->content));
- }
+ BeingCommon::readObjectNodes(spriteNode, display,
+ currentInfo, "MonsterDB");
}
currentInfo->setDisplay(display);