ManaPlus
Typedefs | Functions
MapDB Namespace Reference

Typedefs

typedef std::map< std::string, std::string > Maps
 
typedef Maps::iterator MapIterator
 
typedef std::map< std::string, MapInfoMapInfos
 
typedef MapInfos::iterator MapInfoIter
 
typedef std::map< std::string, StringVectAtlases
 
typedef Atlases::iterator AtlasIter
 
typedef Atlases::const_iterator AtlasCIter
 

Functions

void readMap (xmlNode *const node)
 
void readAtlas (xmlNode *const node)
 
void load ()
 
void loadRemapXmlFile (const std::string &fileName, const SkipError skipError)
 
void loadInfo (const std::string &fileName, const SkipError skipError)
 
void unload ()
 
const std::string getMapName (const std::string &name)
 
const MapInfogetMapAtlas (const std::string &name)
 
const MapInfogetAtlas (const std::string &name)
 
bool isEmptyTileset (const std::string &name)
 

Detailed Description

Color information database.

Typedef Documentation

◆ AtlasCIter

typedef Atlases::const_iterator MapDB::AtlasCIter

Definition at line 72 of file mapdb.h.

◆ Atlases

typedef std::map<std::string, StringVect> MapDB::Atlases

Definition at line 70 of file mapdb.h.

◆ AtlasIter

typedef Atlases::iterator MapDB::AtlasIter

Definition at line 71 of file mapdb.h.

◆ MapInfoIter

typedef MapInfos::iterator MapDB::MapInfoIter

Definition at line 68 of file mapdb.h.

◆ MapInfos

typedef std::map<std::string, MapInfo> MapDB::MapInfos

Definition at line 67 of file mapdb.h.

◆ MapIterator

typedef Maps::iterator MapDB::MapIterator

Definition at line 65 of file mapdb.h.

◆ Maps

typedef std::map<std::string, std::string> MapDB::Maps

Definition at line 64 of file mapdb.h.

Function Documentation

◆ getAtlas()

const MapInfo * MapDB::getAtlas ( const std::string &  name)

Definition at line 226 of file mapdb.cpp.

227 {
228  const AtlasCIter it = mAtlases.find(name);
229  if (it == mAtlases.end())
230  return nullptr;
231 
232  MapInfo *const info = new MapInfo;
233  info->atlas = name;
234  info->files = &(*it).second;
235  return info;
236 }
bool info(InputEvent &event)
Definition: commands.cpp:57
Atlases::const_iterator AtlasCIter
Definition: mapdb.h:72
MapDB::Atlases mAtlases
Definition: mapdb.cpp:37

References Actions::info(), and anonymous_namespace{mapdb.cpp}::mAtlases.

Referenced by MapReader::loadEmptyAtlas().

◆ getMapAtlas()

const MapInfo * MapDB::getMapAtlas ( const std::string &  name)

Definition at line 213 of file mapdb.cpp.

214 {
215  const MapInfoIter it = mInfos.find(name);
216  if (it == mInfos.end())
217  return nullptr;
218  MapInfo *const info = &(*it).second;
219  const AtlasCIter it2 = mAtlases.find(info->atlas);
220  if (it2 == mAtlases.end())
221  return nullptr;
222  info->files = &((*it2).second);
223  return info;
224 }
MapInfos::iterator MapInfoIter
Definition: mapdb.h:68
MapDB::MapInfos mInfos
Definition: mapdb.cpp:36

References Actions::info(), anonymous_namespace{mapdb.cpp}::mAtlases, and anonymous_namespace{mapdb.cpp}::mInfos.

◆ getMapName()

const std::string MapDB::getMapName ( const std::string &  name)

Definition at line 204 of file mapdb.cpp.

205 {
206  const MapIterator it = mMaps.find(name);
207 
208  if (it != mMaps.end())
209  return it->second;
210  return name;
211 }
Maps::iterator MapIterator
Definition: mapdb.h:65

References anonymous_namespace{mapdb.cpp}::mMaps.

Referenced by Game::changeMap().

◆ isEmptyTileset()

bool MapDB::isEmptyTileset ( const std::string &  name)

Definition at line 238 of file mapdb.cpp.

239 {
240  return mEmptyTilesets.find(name) != mEmptyTilesets.end();
241 }
std::set< std::string > mEmptyTilesets
Definition: mapdb.cpp:38

References anonymous_namespace{mapdb.cpp}::mEmptyTilesets.

Referenced by MapReader::readTileset().

◆ load()

void MapDB::load ( )

Loads the map remap data from maps\remap.xml.

Definition at line 47 of file mapdb.cpp.

48 {
49  if (mLoaded)
50  unload();
51 
52  logger->log1("Initializing maps database...");
53  loadRemapXmlFile(paths.getStringValue("mapsRemapFile"),
55  loadRemapXmlFile(paths.getStringValue("mapsRemapPatchFile"),
57  loadXmlDir("mapsRemapPatchDir", loadRemapXmlFile)
58 
60  loadInfo(paths.getStringValue("mapsPatchFile"), SkipError_true);
61  loadXmlDir("mapsPatchDir", loadInfo)
62  mLoaded = true;
63 }
#define loadXmlDir(name, function)
Definition: beingcommon.h:39
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
void loadRemapXmlFile(const std::string &fileName, const SkipError skipError)
Definition: mapdb.cpp:65
void loadInfo(const std::string &fileName, const SkipError skipError)
Definition: mapdb.cpp:162
void unload()
Definition: net.cpp:180
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30

References Configuration::getStringValue(), loadInfo(), loadRemapXmlFile(), loadXmlDir, Logger::log1(), logger, anonymous_namespace{mapdb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadInfo()

void MapDB::loadInfo ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 162 of file mapdb.cpp.

164 {
167  skipError);
168  XmlNodeConstPtrConst root = doc->rootNode();
169  if (root == nullptr)
170  {
171  delete doc;
172  return;
173  }
174 
175  for_each_xml_child_node(node, root)
176  {
177  if (xmlNameEqual(node, "map"))
178  {
179  readMap(node);
180  }
181  else if (xmlNameEqual(node, "atlas"))
182  {
183  readAtlas(node);
184  }
185  else if (xmlNameEqual(node, "include"))
186  {
187  const std::string name = XML::getProperty(node, "name", "");
188  if (!name.empty())
189  loadInfo(name, skipError);
190  continue;
191  }
192  }
193  delete doc;
194 }
xmlNodePtr rootNode()
Definition: libxml.cpp:169
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
void readMap(xmlNode *const node)
Definition: mapdb.cpp:105
void readAtlas(xmlNode *const node)
Definition: mapdb.cpp:125
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References fileName, for_each_xml_child_node, XML::getProperty(), readAtlas(), readMap(), XML::Document::rootNode(), and UseVirtFs_true.

Referenced by load().

◆ loadRemapXmlFile()

void MapDB::loadRemapXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 65 of file mapdb.cpp.

67 {
68  XML::Document *const doc = new XML::Document(fileName,
70  skipError);
71 
72  XmlNodeConstPtrConst root = doc->rootNode();
73  if (root == nullptr)
74  {
75  delete doc;
76  return;
77  }
78 
79  for_each_xml_child_node(node, root)
80  {
81  if (xmlNameEqual(node, "map"))
82  {
83  const std::string name = XML::getProperty(node, "name", "");
84  if (name.empty())
85  continue;
86 
87  const std::string value = XML::getProperty(node, "value", "");
88  if (value.empty())
89  continue;
90 
91  mMaps[name] = value;
92  }
93  else if (xmlNameEqual(node, "include"))
94  {
95  const std::string name = XML::getProperty(node, "name", "");
96  if (!name.empty())
97  loadRemapXmlFile(name, skipError);
98  continue;
99  }
100  }
101 
102  delete doc;
103 }

References fileName, for_each_xml_child_node, XML::getProperty(), anonymous_namespace{mapdb.cpp}::mMaps, XML::Document::rootNode(), and UseVirtFs_true.

Referenced by load().

◆ readAtlas()

void MapDB::readAtlas ( xmlNode *const  node)

Definition at line 125 of file mapdb.cpp.

126 {
127  if (node == nullptr)
128  return;
129  const std::string atlas = XML::getProperty(node, "name", "");
130  if (atlas.empty())
131  return;
132  for_each_xml_child_node(childNode, node)
133  {
134  if (xmlNameEqual(childNode, "file"))
135  {
136  const std::string file = XML::getProperty(childNode, "name", "");
137  if (file.empty())
138  continue;
139  mAtlases[atlas].push_back(file);
140  }
141  }
142  if (atlas == paths.getStringValue("emptyAtlasName"))
143  {
144  const StringVect *files = &mAtlases[atlas];
145  FOR_EACHP (StringVectCIter, it, files)
146  {
147  mEmptyTilesets.insert(*it);
148  logger->log("empty tileset: " + *it);
149  }
150  }
151  else if (atlas != "all")
152  {
153  const AtlasCIter &allAtlas = mAtlases.find("all");
154  if (allAtlas != mAtlases.end())
155  {
156  FOR_EACH (StringVectCIter, it, (*allAtlas).second)
157  mAtlases[atlas].push_back(*it);
158  }
159  }
160 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:31
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31
std::vector< std::string > StringVect
Definition: stringvector.h:29

References FOR_EACH, for_each_xml_child_node, FOR_EACHP, XML::getProperty(), Configuration::getStringValue(), Logger::log(), logger, anonymous_namespace{mapdb.cpp}::mAtlases, anonymous_namespace{mapdb.cpp}::mEmptyTilesets, and paths.

Referenced by loadInfo().

◆ readMap()

void MapDB::readMap ( xmlNode *const  node)

Definition at line 105 of file mapdb.cpp.

106 {
107  if (node == nullptr)
108  return;
109  const std::string map = XML::getProperty(node, "name", "");
110  if (map.empty())
111  return;
112 
113  for_each_xml_child_node(childNode, node)
114  {
115  if (xmlNameEqual(childNode, "atlas"))
116  {
117  const std::string atlas = XML::getProperty(childNode, "name", "");
118  if (atlas.empty())
119  continue;
120  mInfos[map].atlas = atlas;
121  }
122  }
123 }

References for_each_xml_child_node, XML::getProperty(), and anonymous_namespace{mapdb.cpp}::mInfos.

Referenced by loadInfo().

◆ unload()

void MapDB::unload ( )

Clear the remap data

Definition at line 196 of file mapdb.cpp.

197 {
198  logger->log1("Unloading map database...");
199 
200  mMaps.clear();
201  mLoaded = false;
202 }

References Logger::log1(), logger, anonymous_namespace{mapdb.cpp}::mLoaded, and anonymous_namespace{mapdb.cpp}::mMaps.