summaryrefslogtreecommitdiff
path: root/src/resources/mapreader.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2007-04-23 00:48:37 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2007-04-23 00:48:37 +0000
commitb3376bfe4e26591e1dc1066d8f2270baf4f9f759 (patch)
tree6cba270a59320bf7c77266fe736cfb68bc2521a0 /src/resources/mapreader.cpp
parent6d09c8f4667f75fece4a5549de237e17490398cf (diff)
downloadmana-client-b3376bfe4e26591e1dc1066d8f2270baf4f9f759.tar.gz
mana-client-b3376bfe4e26591e1dc1066d8f2270baf4f9f759.tar.bz2
mana-client-b3376bfe4e26591e1dc1066d8f2270baf4f9f759.tar.xz
mana-client-b3376bfe4e26591e1dc1066d8f2270baf4f9f759.zip
Merged Björn Steinbrinks improvements at the xml parsing from trunk version.
Diffstat (limited to 'src/resources/mapreader.cpp')
-rw-r--r--src/resources/mapreader.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 9d9aabca..fda8916d 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -181,7 +181,6 @@ MapReader::readMap(const std::string &filename)
if (!node || !xmlStrEqual(node->name, BAD_CAST "map")) {
logger->log("Error: Not a map file (%s)!", filename.c_str());
- return NULL;
}
else
{
@@ -213,24 +212,24 @@ MapReader::readMap(xmlNodePtr node, const std::string &path)
int layerNr = 0;
Map *map = new Map(w, h, tilew, tileh);
- for (node = node->xmlChildrenNode; node != NULL; node = node->next)
+ for_each_xml_child_node(childNode, node)
{
- if (xmlStrEqual(node->name, BAD_CAST "tileset"))
+ if (xmlStrEqual(childNode->name, BAD_CAST "tileset"))
{
- Tileset *tileset = readTileset(node, pathDir, map);
+ Tileset *tileset = readTileset(childNode, pathDir, map);
if (tileset) {
map->addTileset(tileset);
}
}
- else if (xmlStrEqual(node->name, BAD_CAST "layer"))
+ else if (xmlStrEqual(childNode->name, BAD_CAST "layer"))
{
logger->log("- Loading layer %d", layerNr);
- readLayer(node, map, layerNr);
+ readLayer(childNode, map, layerNr);
layerNr++;
}
- else if (xmlStrEqual(node->name, BAD_CAST "properties"))
+ else if (xmlStrEqual(childNode->name, BAD_CAST "properties"))
{
- readProperties(node, map);
+ readProperties(childNode, map);
}
}
@@ -242,13 +241,14 @@ MapReader::readMap(xmlNodePtr node, const std::string &path)
void
MapReader::readProperties(xmlNodePtr node, Properties* props)
{
- for (node = node->xmlChildrenNode; node; node = node->next) {
- if (!xmlStrEqual(node->name, BAD_CAST "property"))
+ for_each_xml_child_node(childNode, node)
+ {
+ if (!xmlStrEqual(childNode->name, BAD_CAST "property"))
continue;
// Example: <property name="name" value="value"/>
- xmlChar *name = xmlGetProp(node, BAD_CAST "name");
- xmlChar *value = xmlGetProp(node, BAD_CAST "value");
+ xmlChar *name = xmlGetProp(childNode, BAD_CAST "name");
+ xmlChar *value = xmlGetProp(childNode, BAD_CAST "value");
if (name && value) {
props->setProperty((const char*)name, (const char*)value);
@@ -269,12 +269,13 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
// Load the tile data. Layers are assumed to be map size, with (0,0) as
// origin.
- for (node = node->xmlChildrenNode; node; node = node->next) {
- if (!xmlStrEqual(node->name, BAD_CAST "data"))
+ for_each_xml_child_node(childNode, node)
+ {
+ if (!xmlStrEqual(childNode->name, BAD_CAST "data"))
continue;
- xmlChar *encoding = xmlGetProp(node, BAD_CAST "encoding");
- xmlChar *compression = xmlGetProp(node, BAD_CAST "compression");
+ xmlChar *encoding = xmlGetProp(childNode, BAD_CAST "encoding");
+ xmlChar *compression = xmlGetProp(childNode, BAD_CAST "compression");
if (encoding && xmlStrEqual(encoding, BAD_CAST "base64"))
{
@@ -287,7 +288,7 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
}
// Read base64 encoded map file
- xmlNodePtr dataChild = node->xmlChildrenNode;
+ xmlNodePtr dataChild = childNode->xmlChildrenNode;
if (!dataChild)
continue;
@@ -351,11 +352,12 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
}
else {
// Read plain XML map file
- for (xmlNodePtr n2 = node->xmlChildrenNode; n2; n2 = n2->next) {
- if (!xmlStrEqual(n2->name, BAD_CAST "tile"))
+ for_each_xml_child_node(childNode2, childNode)
+ {
+ if (!xmlStrEqual(childNode2->name, BAD_CAST "tile"))
continue;
- int gid = XML::getProperty(n2, "gid", -1);
+ int gid = XML::getProperty(childNode2, "gid", -1);
map->setTileWithGid(x, y, layer, gid);
x++;
@@ -392,11 +394,12 @@ MapReader::readTileset(xmlNodePtr node,
int tw = XML::getProperty(node, "tilewidth", map->getTileWidth());
int th = XML::getProperty(node, "tileheight", map->getTileHeight());
- for (node = node->xmlChildrenNode; node; node = node->next) {
- if (!xmlStrEqual(node->name, BAD_CAST "image"))
+ for_each_xml_child_node(childNode, node)
+ {
+ if (!xmlStrEqual(childNode->name, BAD_CAST "image"))
continue;
- xmlChar* source = xmlGetProp(node, BAD_CAST "source");
+ xmlChar* source = xmlGetProp(childNode, BAD_CAST "source");
if (source)
{