summary refs log tree commit diff stats
path: root/tools/mapedit/src/world.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mapedit/src/world.cpp')
-rw-r--r--tools/mapedit/src/world.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index c30f76c..3145e4e 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp
@@ -59,6 +59,17 @@ World::World(std::string filename)
59 rootChildren.push_back(atoi((char*) key)); 59 rootChildren.push_back(atoi((char*) key));
60 } 60 }
61 xmlFree(key); 61 xmlFree(key);
62 } else if (!xmlStrcmp(node->name, (const xmlChar*) "startpos"))
63 {
64 xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id");
65 if (idKey == 0) throw MapLoadException(filename);
66 startingMap = atoi((char*) idKey);
67 xmlFree(idKey);
68
69 xmlChar* posKey = xmlGetProp(node, (xmlChar*) "pos");
70 if (posKey == 0) throw MapLoadException(filename);
71 sscanf((char*) posKey, "%d,%d", &startingPosition.first, &startingPosition.second);
72 xmlFree(posKey);
62 } else if (!xmlStrcmp(node->name, (const xmlChar*) "map")) 73 } else if (!xmlStrcmp(node->name, (const xmlChar*) "map"))
63 { 74 {
64 xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id"); 75 xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id");
@@ -237,6 +248,22 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
237 if (rc < 0) throw MapWriteException(name); 248 if (rc < 0) throw MapWriteException(name);
238 } 249 }
239 250
251 // <startpos>
252 rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos");
253 if (rc < 0) throw MapWriteException(name);
254
255 // id=
256 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "id", "%d", startingMap);
257 if (rc < 0) throw MapWriteException(name);
258
259 // pos=
260 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "pos", "%d,%d", startingPosition.first, startingPosition.second);
261 if (rc < 0) throw MapWriteException(name);
262
263 // </startpos>
264 rc = xmlTextWriterEndElement(writer);
265 if (rc < 0) throw MapWriteException(name);
266
240 for (auto mapPair : maps) 267 for (auto mapPair : maps)
241 { 268 {
242 Map& map = *mapPair.second; 269 Map& map = *mapPair.second;
@@ -379,3 +406,21 @@ bool World::getEmpty() const
379{ 406{
380 return empty; 407 return empty;
381} 408}
409
410Map* World::getStartingMap() const
411{
412 return getMap(startingMap).get();
413}
414
415std::pair<double, double> World::getStartingPosition() const
416{
417 return startingPosition;
418}
419
420void World::setStart(Map* map, std::pair<double, double> startPos)
421{
422 startingMap = map->getID();
423 startingPosition = startPos;
424
425 setDirty(true);
426}