From 6722e88207a733e4912cabf957f966d1c4a8d102 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 19 Jul 2006 20:48:05 +0000 Subject: Implemented loading for the way Tiled saves properties since version 0.6.0 and updated all current maps. --- src/resources/mapreader.cpp | 50 ++++++++++++++++++++++++++++++--------------- src/resources/mapreader.h | 10 +++++++++ 2 files changed, 43 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index bddc1092..48f23aea 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -192,26 +192,11 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) int tilew = getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH); int tileh = getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT); int layerNr = 0; - Map* map = new Map(w, h, tilew, tileh); + Map *map = new Map(w, h, tilew, tileh); for (node = node->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlStrEqual(node->name, BAD_CAST "property")) - { - // Example: - - xmlChar *name = xmlGetProp(node, BAD_CAST "name"); - xmlChar *value = xmlGetProp(node, BAD_CAST "value"); - - if (name && value) - { - map->setProperty((const char*)name, (const char*)value); - } - - if (name) xmlFree(name); - if (value) xmlFree(value); - } - else if (xmlStrEqual(node->name, BAD_CAST "tileset")) + if (xmlStrEqual(node->name, BAD_CAST "tileset")) { Tileset *tileset = readTileset(node, pathDir, map); if (tileset) { @@ -224,11 +209,42 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) readLayer(node, map, layerNr); layerNr++; } + else if (xmlStrEqual(node->name, BAD_CAST "properties")) + { + readProperties(node, map); + } } return map; } +void +MapReader::readProperties(xmlNodePtr node, Properties* props) +{ + node = node->xmlChildrenNode; + + while (node != NULL) + { + if (xmlStrEqual(node->name, BAD_CAST "property")) + { + // Example: + + xmlChar *name = xmlGetProp(node, BAD_CAST "name"); + xmlChar *value = xmlGetProp(node, BAD_CAST "value"); + + if (name && value) + { + props->setProperty((const char*) name, (const char*) value); + } + + if (name) xmlFree(name); + if (value) xmlFree(value); + } + + node = node->next; + } +} + void MapReader::readLayer(xmlNodePtr node, Map *map, int layer) { diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h index eb5a8577..ad21762d 100644 --- a/src/resources/mapreader.h +++ b/src/resources/mapreader.h @@ -28,6 +28,7 @@ #include +class Properties; class Map; class Tileset; @@ -51,6 +52,15 @@ class MapReader readMap(xmlNodePtr node, const std::string &path); private: + /** + * Reads the properties element. + * + * @param props the Properties instance to which the properties will + * be assigned + */ + static void + readProperties(xmlNodePtr node, Properties* props); + /** * Reads a map layer. */ -- cgit v1.2.3-70-g09d2