summaryrefslogtreecommitdiff
path: root/src/resources/spritedef.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-07 08:37:23 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-07 08:37:23 +0000
commit64d58b9a7e057e6d829107678b1570082be1093f (patch)
treef95a940521150e8f5bbab1bba520c956c8b2aed9 /src/resources/spritedef.cpp
parent36a53a1d5e3b558dafe200a6929948e7730c94f0 (diff)
downloadmana-64d58b9a7e057e6d829107678b1570082be1093f.tar.gz
mana-64d58b9a7e057e6d829107678b1570082be1093f.tar.bz2
mana-64d58b9a7e057e6d829107678b1570082be1093f.tar.xz
mana-64d58b9a7e057e6d829107678b1570082be1093f.zip
Added XML::Document class which simplifies parsing an XML document and
automatically cleans it up again.
Diffstat (limited to 'src/resources/spritedef.cpp')
-rw-r--r--src/resources/spritedef.cpp32
1 files changed, 10 insertions, 22 deletions
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index d8dfb23d..1662e2ac 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -51,7 +51,6 @@ SpriteDef::getAction(SpriteAction action) const
SpriteDef *SpriteDef::load(std::string const &animationFile, int variant)
{
- int size;
ResourceManager *resman = ResourceManager::getInstance();
std::string::size_type pos = animationFile.find('|');
@@ -59,27 +58,18 @@ SpriteDef *SpriteDef::load(std::string const &animationFile, int variant)
if (pos != std::string::npos)
palettes = animationFile.substr(pos + 1);
- char *data = (char*) resman->loadFile
- (animationFile.substr(0, pos).c_str(), size);
+ XML::Document doc(animationFile.substr(0, pos));
+ xmlNodePtr rootNode = doc.rootNode();
- if (!data && animationFile != "graphics/sprites/error.xml")
- return load("graphics/sprites/error.xml", 0);
-
- xmlDocPtr doc = xmlParseMemory(data, size);
- free(data);
-
- 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->log("Error, failed to parse %s.", animationFile.c_str());
- xmlFreeDoc(doc);
- return NULL;
+ logger->log("Error, failed to parse %s", animationFile.c_str());
+
+ if (animationFile != "graphics/sprites/error.xml") {
+ return load("graphics/sprites/error.xml", 0);
+ } else {
+ return NULL;
+ }
}
// Get the variant
@@ -109,8 +99,6 @@ SpriteDef *SpriteDef::load(std::string const &animationFile, int variant)
}
}
- xmlFreeDoc(doc);
-
def->substituteActions();
return def;
}
@@ -277,7 +265,7 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode,
void
SpriteDef::includeSprite(xmlNodePtr includeNode)
{
- std::string filename = XML::getProperty(includeNode, "file", "");
+ const std::string filename = XML::getProperty(includeNode, "file", "");
ResourceManager *resman = ResourceManager::getInstance();
SpriteDef *sprite = resman->getSprite("graphics/sprites/" + filename);