diff options
Diffstat (limited to 'tools/mapedit/src/world.cpp')
| -rw-r--r-- | tools/mapedit/src/world.cpp | 139 |
1 files changed, 120 insertions, 19 deletions
| diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index fb0bb36..043cf8a 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp | |||
| @@ -1,8 +1,11 @@ | |||
| 1 | #include "world.h" | 1 | #include "world.h" |
| 2 | #include <libxml/parser.h> | 2 | #include <libxml/parser.h> |
| 3 | #include <libxml/xmlwriter.h> | 3 | #include <libxml/xmlwriter.h> |
| 4 | #include "frame.h" | ||
| 5 | #include <sstream> | 4 | #include <sstream> |
| 5 | #include "frame.h" | ||
| 6 | #include "map.h" | ||
| 7 | #include "object.h" | ||
| 8 | #include "consts.h" | ||
| 6 | 9 | ||
| 7 | World::World() | 10 | World::World() |
| 8 | { | 11 | { |
| @@ -103,20 +106,60 @@ World::World(std::string filename) | |||
| 103 | xmlFree(key); | 106 | xmlFree(key); |
| 104 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "leftmap")) | 107 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "leftmap")) |
| 105 | { | 108 | { |
| 106 | xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); | 109 | xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); |
| 107 | if (key != 0) | 110 | if (typeKey == 0) throw MapLoadException(filename); |
| 111 | map->setLeftMoveType(Map::moveTypeForShort((char*) typeKey), false); | ||
| 112 | xmlFree(typeKey); | ||
| 113 | |||
| 114 | if (Map::moveTypeTakesMap(map->getLeftMoveType())) | ||
| 108 | { | 115 | { |
| 109 | map->setLeftmap(atoi((char*) key), false); | 116 | xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); |
| 117 | if (idKey == 0) throw MapLoadException(filename); | ||
| 118 | map->setLeftMoveMapID(atoi((char*) idKey), false); | ||
| 119 | xmlFree(idKey); | ||
| 110 | } | 120 | } |
| 111 | xmlFree(key); | ||
| 112 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "rightmap")) | 121 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "rightmap")) |
| 113 | { | 122 | { |
| 114 | xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); | 123 | xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); |
| 115 | if (key != 0) | 124 | if (typeKey == 0) throw MapLoadException(filename); |
| 125 | map->setRightMoveType(Map::moveTypeForShort((char*) typeKey), false); | ||
| 126 | xmlFree(typeKey); | ||
| 127 | |||
| 128 | if (Map::moveTypeTakesMap(map->getRightMoveType())) | ||
| 116 | { | 129 | { |
| 117 | map->setRightmap(atoi((char*) key), false); | 130 | xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); |
| 131 | if (idKey == 0) throw MapLoadException(filename); | ||
| 132 | map->setRightMoveMapID(atoi((char*) idKey), false); | ||
| 133 | xmlFree(idKey); | ||
| 134 | } | ||
| 135 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "upmap")) | ||
| 136 | { | ||
| 137 | xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); | ||
| 138 | if (typeKey == 0) throw MapLoadException(filename); | ||
| 139 | map->setUpMoveType(Map::moveTypeForShort((char*) typeKey), false); | ||
| 140 | xmlFree(typeKey); | ||
| 141 | |||
| 142 | if (Map::moveTypeTakesMap(map->getUpMoveType())) | ||
| 143 | { | ||
| 144 | xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); | ||
| 145 | if (idKey == 0) throw MapLoadException(filename); | ||
| 146 | map->setUpMoveMapID(atoi((char*) idKey), false); | ||
| 147 | xmlFree(idKey); | ||
| 148 | } | ||
| 149 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "downmap")) | ||
| 150 | { | ||
| 151 | xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); | ||
| 152 | if (typeKey == 0) throw MapLoadException(filename); | ||
| 153 | map->setDownMoveType(Map::moveTypeForShort((char*) typeKey), false); | ||
| 154 | xmlFree(typeKey); | ||
| 155 | |||
| 156 | if (Map::moveTypeTakesMap(map->getDownMoveType())) | ||
| 157 | { | ||
| 158 | xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); | ||
| 159 | if (idKey == 0) throw MapLoadException(filename); | ||
| 160 | map->setDownMoveMapID(atoi((char*) idKey), false); | ||
| 161 | xmlFree(idKey); | ||
| 118 | } | 162 | } |
| 119 | xmlFree(key); | ||
| 120 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entities")) | 163 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entities")) |
| 121 | { | 164 | { |
| 122 | for (xmlNodePtr entityNode = mapNode->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next) | 165 | for (xmlNodePtr entityNode = mapNode->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next) |
| @@ -248,7 +291,7 @@ void World::save(std::string name, wxTreeCtrl* mapTree) | |||
| 248 | if (rc < 0) throw MapWriteException(name); | 291 | if (rc < 0) throw MapWriteException(name); |
| 249 | } | 292 | } |
| 250 | 293 | ||
| 251 | // <startpos> | 294 | // <startpos/> |
| 252 | rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos"); | 295 | rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos"); |
| 253 | if (rc < 0) throw MapWriteException(name); | 296 | if (rc < 0) throw MapWriteException(name); |
| 254 | 297 | ||
| @@ -300,21 +343,79 @@ void World::save(std::string name, wxTreeCtrl* mapTree) | |||
| 300 | if (rc < 0) throw MapWriteException(name); | 343 | if (rc < 0) throw MapWriteException(name); |
| 301 | 344 | ||
| 302 | // <leftmap/> | 345 | // <leftmap/> |
| 303 | std::ostringstream leftmap_out; | 346 | rc = xmlTextWriterStartElement(writer, (xmlChar*) "leftmap"); |
| 304 | if (map.getLeftmap()) | 347 | if (rc < 0) throw MapWriteException(name); |
| 348 | |||
| 349 | // type= | ||
| 350 | rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getLeftMoveType()).c_str()); | ||
| 351 | if (rc < 0) throw MapWriteException(name); | ||
| 352 | |||
| 353 | if (Map::moveTypeTakesMap(map.getLeftMoveType())) | ||
| 305 | { | 354 | { |
| 306 | leftmap_out << map.getLeftmap()->getID(); | 355 | // map= |
| 356 | rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getLeftMoveMapID()); | ||
| 357 | if (rc < 0) throw MapWriteException(name); | ||
| 307 | } | 358 | } |
| 308 | rc = xmlTextWriterWriteElement(writer, (xmlChar*) "leftmap", (xmlChar*) leftmap_out.str().c_str()); | 359 | |
| 360 | // </leftmap> | ||
| 361 | rc = xmlTextWriterEndElement(writer); | ||
| 309 | if (rc < 0) throw MapWriteException(name); | 362 | if (rc < 0) throw MapWriteException(name); |
| 310 | 363 | ||
| 311 | // <rightmap/> | 364 | // <rightmap/> |
| 312 | std::ostringstream rightmap_out; | 365 | rc = xmlTextWriterStartElement(writer, (xmlChar*) "rightmap"); |
| 313 | if (map.getRightmap()) | 366 | if (rc < 0) throw MapWriteException(name); |
| 367 | |||
| 368 | // type= | ||
| 369 | rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getRightMoveType()).c_str()); | ||
| 370 | if (rc < 0) throw MapWriteException(name); | ||
| 371 | |||
| 372 | if (Map::moveTypeTakesMap(map.getRightMoveType())) | ||
| 373 | { | ||
| 374 | // map= | ||
| 375 | rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getRightMoveMapID()); | ||
| 376 | if (rc < 0) throw MapWriteException(name); | ||
| 377 | } | ||
| 378 | |||
| 379 | // </rightmap> | ||
| 380 | rc = xmlTextWriterEndElement(writer); | ||
| 381 | if (rc < 0) throw MapWriteException(name); | ||
| 382 | |||
| 383 | // <upmap/> | ||
| 384 | rc = xmlTextWriterStartElement(writer, (xmlChar*) "upmap"); | ||
| 385 | if (rc < 0) throw MapWriteException(name); | ||
| 386 | |||
| 387 | // type= | ||
| 388 | rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getUpMoveType()).c_str()); | ||
| 389 | if (rc < 0) throw MapWriteException(name); | ||
| 390 | |||
| 391 | if (Map::moveTypeTakesMap(map.getUpMoveType())) | ||
| 314 | { | 392 | { |
| 315 | rightmap_out << map.getRightmap()->getID(); | 393 | // map= |
| 394 | rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getUpMoveMapID()); | ||
| 395 | if (rc < 0) throw MapWriteException(name); | ||
| 396 | } | ||
| 397 | |||
| 398 | // </upmap> | ||
| 399 | rc = xmlTextWriterEndElement(writer); | ||
| 400 | if (rc < 0) throw MapWriteException(name); | ||
| 401 | |||
| 402 | // <downmap/> | ||
| 403 | rc = xmlTextWriterStartElement(writer, (xmlChar*) "downmap"); | ||
| 404 | if (rc < 0) throw MapWriteException(name); | ||
| 405 | |||
| 406 | // type= | ||
| 407 | rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getDownMoveType()).c_str()); | ||
| 408 | if (rc < 0) throw MapWriteException(name); | ||
| 409 | |||
| 410 | if (Map::moveTypeTakesMap(map.getDownMoveType())) | ||
| 411 | { | ||
| 412 | // map= | ||
| 413 | rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getDownMoveMapID()); | ||
| 414 | if (rc < 0) throw MapWriteException(name); | ||
| 316 | } | 415 | } |
| 317 | rc = xmlTextWriterWriteElement(writer, (xmlChar*) "rightmap", (xmlChar*) rightmap_out.str().c_str()); | 416 | |
| 417 | // </downmap> | ||
| 418 | rc = xmlTextWriterEndElement(writer); | ||
| 318 | if (rc < 0) throw MapWriteException(name); | 419 | if (rc < 0) throw MapWriteException(name); |
| 319 | 420 | ||
| 320 | // <entities> | 421 | // <entities> |
