From 3a2bab265768c219b0c077eef10b69dfe8158131 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 25 Sep 2012 01:40:43 +0300 Subject: Load additional info about maps from maps.xml. For now here only atlases information. --- src/resources/mapdb.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ src/resources/mapdb.h | 16 ++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp index 3c4347301..55c3d7306 100644 --- a/src/resources/mapdb.cpp +++ b/src/resources/mapdb.cpp @@ -31,6 +31,14 @@ namespace { bool mLoaded = false; MapDB::Maps mMaps; + MapDB::MapInfos mInfos; + MapDB::Atlases mAtlases; +} + +namespace MapDB +{ + void readMap(XmlNodePtr node); + void readAtlas(XmlNodePtr node); } void MapDB::load() @@ -38,6 +46,12 @@ void MapDB::load() if (mLoaded) unload(); + loadRemap(); + loadInfo(); +} + +void MapDB::loadRemap() +{ XML::Document *doc = new XML::Document( paths.getStringValue("maps") + "remap.xml"); @@ -69,6 +83,55 @@ void MapDB::load() mLoaded = true; } +void MapDB::readMap(XmlNodePtr node) +{ + const std::string map = XML::getProperty(node, "name", ""); + if (map.empty()) + return; + + for_each_xml_child_node(childNode, node) + { + if (xmlNameEqual(childNode, "atlas")) + { + const std::string atlas = XML::getProperty(childNode, "name", ""); + if (atlas.empty()) + continue; + mInfos[map].atlas = atlas; + } + } +} + +void MapDB::readAtlas(XmlNodePtr node) +{ + const std::string atlas = XML::getProperty(node, "name", ""); + if (atlas.empty()) + return; + for_each_xml_child_node(childNode, node) + { + if (xmlNameEqual(childNode, "file")) + { + const std::string file = XML::getProperty(childNode, "name", ""); + if (file.empty()) + continue; + mAtlases[atlas].push_back(file); + } + } +} + +void MapDB::loadInfo() +{ + XML::Document *doc = new XML::Document("maps.xml"); + + const XmlNodePtr root = doc->rootNode(); + + for_each_xml_child_node(node, root) + { + if (xmlNameEqual(node, "map")) + readMap(node); + else if (xmlNameEqual(node, "atlas")) + readAtlas(node); + } +} void MapDB::unload() { diff --git a/src/resources/mapdb.h b/src/resources/mapdb.h index 0d13428ee..b8fd954fa 100644 --- a/src/resources/mapdb.h +++ b/src/resources/mapdb.h @@ -22,19 +22,29 @@ #ifndef MAPDB_H #define MAPDB_H +#include "utils/stringvector.h" + #include -#include /** * Color information database. */ namespace MapDB { + struct MapInfo + { + std::string atlas; + }; + /** * Loads the map remap data from maps\remap.xml. */ void load(); + void loadRemap(); + + void loadInfo(); + /** * Clear the remap data */ @@ -45,6 +55,10 @@ namespace MapDB // Maps DB typedef std::map Maps; typedef Maps::iterator MapIterator; + // map to infos map + typedef std::map MapInfos; + // atlas to files map + typedef std::map Atlases; } #endif -- cgit v1.2.3-70-g09d2