From ca58ec1faedca0081ecd233f2cefa1ba783cebf4 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 20 Nov 2007 12:27:56 +0000 Subject: 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. ........ --- src/resources/spritedef.cpp | 47 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'src/resources/spritedef.cpp') 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); -- cgit v1.2.3-70-g09d2