summaryrefslogtreecommitdiff
path: root/src/resources/spritedef.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-11-20 12:27:56 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-11-20 12:27:56 +0000
commitca58ec1faedca0081ecd233f2cefa1ba783cebf4 (patch)
tree11216c01bb8867a9bd4ad6d4b8bdefc3c61a952a /src/resources/spritedef.cpp
parent5a7abdafdac8f6ddd7972cadbc7e20563a0a29fc (diff)
downloadmana-client-ca58ec1faedca0081ecd233f2cefa1ba783cebf4.tar.gz
mana-client-ca58ec1faedca0081ecd233f2cefa1ba783cebf4.tar.bz2
mana-client-ca58ec1faedca0081ecd233f2cefa1ba783cebf4.tar.xz
mana-client-ca58ec1faedca0081ecd233f2cefa1ba783cebf4.zip
Merged revisions 3642,3662-3664,3667 via svnmerge from
https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/trunk ........ r3642 | gmelquio | 2007-10-19 19:46:46 +0200 (Fri, 19 Oct 2007) | 1 line Factored code between resource handlers. Implemented failure-friendly sprite loader. ........ r3662 | gmelquio | 2007-10-21 21:01:16 +0200 (Sun, 21 Oct 2007) | 1 line Added persistent positioning. ........ r3663 | gmelquio | 2007-10-21 21:03:43 +0200 (Sun, 21 Oct 2007) | 1 line Fixed missing pixels at bottom and right. ........ r3664 | gmelquio | 2007-10-21 21:05:56 +0200 (Sun, 21 Oct 2007) | 1 line Changed to use default values when restoring missing settings. ........ r3667 | gmelquio | 2007-10-21 22:09:08 +0200 (Sun, 21 Oct 2007) | 1 line Fixed invisible text in dropboxes and shopboxes. ........
Diffstat (limited to 'src/resources/spritedef.cpp')
-rw-r--r--src/resources/spritedef.cpp47
1 files changed, 22 insertions, 25 deletions
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 6eb2365b..45a52d2e 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -35,16 +35,6 @@
#include "../utils/xml.h"
-SpriteDef::SpriteDef(const std::string &idPath,
- const std::string &file, int variant):
- Resource(idPath),
- mAction(NULL),
- mDirection(DIRECTION_DOWN),
- mLastTime(0)
-{
- load(file, variant);
-}
-
Action*
SpriteDef::getAction(SpriteAction action) const
{
@@ -59,29 +49,29 @@ SpriteDef::getAction(SpriteAction action) const
return i->second;
}
-void
-SpriteDef::load(const std::string &animationFile, int variant)
+SpriteDef *SpriteDef::load(std::string const &animationFile, int variant)
{
int size;
ResourceManager *resman = ResourceManager::getInstance();
char *data = (char*) resman->loadFile(animationFile.c_str(), size);
- if (!data) {
- logger->error("Animation: Could not find " + animationFile + "!");
- }
+ if (!data) return NULL;
xmlDocPtr doc = xmlParseMemory(data, size);
free(data);
- if (!doc) {
- logger->error(
- "Animation: Error while parsing " + animationFile + " file!");
+ if (!doc)
+ {
+ logger->log("Error, failed to parse %s.", animationFile.c_str());
+ return NULL;
}
xmlNodePtr rootNode = xmlDocGetRootElement(doc);
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite")) {
- logger->error(
- "Animation: this is not a valid " + animationFile + " file!");
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite"))
+ {
+ logger->log("Error, failed to parse %s.", animationFile.c_str());
+ xmlFreeDoc(doc);
+ return NULL;
}
// Get the variant
@@ -93,25 +83,32 @@ SpriteDef::load(const std::string &animationFile, int variant)
variant_offset = variant * XML::getProperty(rootNode, "variant_offset", 0);
}
+ SpriteDef *def = new SpriteDef;
+
for_each_xml_child_node(node, rootNode)
{
if (xmlStrEqual(node->name, BAD_CAST "imageset"))
{
- loadImageSet(node);
+ def->loadImageSet(node);
}
else if (xmlStrEqual(node->name, BAD_CAST "action"))
{
- loadAction(node, variant_offset);
+ def->loadAction(node, variant_offset);
}
else if (xmlStrEqual(node->name, BAD_CAST "include"))
{
- includeSprite(node);
+ def->includeSprite(node);
}
}
xmlFreeDoc(doc);
- // Complete missing actions
+ def->substituteActions();
+ return def;
+}
+
+void SpriteDef::substituteActions()
+{
substituteAction(ACTION_STAND, ACTION_DEFAULT);
substituteAction(ACTION_WALK, ACTION_STAND);
substituteAction(ACTION_WALK, ACTION_RUN);