diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-09-25 01:40:43 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-09-30 02:57:13 +0300 |
commit | 3a2bab265768c219b0c077eef10b69dfe8158131 (patch) | |
tree | d5274ccdbf40c1a57e8f1541a74e106fde4fbcbb /src/resources | |
parent | abc334f8e88253e5393e27594c07cc56525b4e9a (diff) | |
download | manaverse-3a2bab265768c219b0c077eef10b69dfe8158131.tar.gz manaverse-3a2bab265768c219b0c077eef10b69dfe8158131.tar.bz2 manaverse-3a2bab265768c219b0c077eef10b69dfe8158131.tar.xz manaverse-3a2bab265768c219b0c077eef10b69dfe8158131.zip |
Load additional info about maps from maps.xml.
For now here only atlases information.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/mapdb.cpp | 63 | ||||
-rw-r--r-- | src/resources/mapdb.h | 16 |
2 files changed, 78 insertions, 1 deletions
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 <map> -#include <string> /** * Color information database. */ namespace MapDB { + struct MapInfo + { + std::string atlas; + }; + /** * Loads the map remap data from <code>maps\remap.xml</code>. */ void load(); + void loadRemap(); + + void loadInfo(); + /** * Clear the remap data */ @@ -45,6 +55,10 @@ namespace MapDB // Maps DB typedef std::map<std::string, std::string> Maps; typedef Maps::iterator MapIterator; + // map to infos map + typedef std::map<std::string, MapInfo> MapInfos; + // atlas to files map + typedef std::map<std::string, StringVect> Atlases; } #endif |