summary refs log tree commit diff stats
path: root/tools/mapedit/src/world.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-03-05 16:07:07 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-03-05 16:07:07 -0500
commit13f946689e28e99ac71172925f63f4320798a0ee (patch)
treeba30132da24aa70b0d2daffc96ac3b3f63d57df6 /tools/mapedit/src/world.cpp
parentdbc486d5cc0fa6b7cdb690fb4591f292d33e9ecc (diff)
downloadtherapy-13f946689e28e99ac71172925f63f4320798a0ee.tar.gz
therapy-13f946689e28e99ac71172925f63f4320798a0ee.tar.bz2
therapy-13f946689e28e99ac71172925f63f4320798a0ee.zip
Added entity indexing
Changed the world format so that map objects are indexed (per map). The next available map object index is cached for each map.
Diffstat (limited to 'tools/mapedit/src/world.cpp')
-rw-r--r--tools/mapedit/src/world.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index 79f5a58..9983731 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp
@@ -94,6 +94,11 @@ World::World(std::string filename)
94 map->setTitle((char*) titleKey, false); 94 map->setTitle((char*) titleKey, false);
95 xmlFree(titleKey); 95 xmlFree(titleKey);
96 96
97 xmlChar* noiKey = xmlGetProp(node, (xmlChar*) "nextObject");
98 if (noiKey == 0) throw MapLoadException("map missing nextObject attribute");
99 map->setNextObjectIndex(atoi((char*) noiKey));
100 xmlFree(noiKey);
101
97 for (xmlNodePtr mapNode = node->xmlChildrenNode; mapNode != NULL; mapNode = mapNode->next) 102 for (xmlNodePtr mapNode = node->xmlChildrenNode; mapNode != NULL; mapNode = mapNode->next)
98 { 103 {
99 if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment")) 104 if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment"))
@@ -125,7 +130,12 @@ World::World(std::string filename)
125 int ypos = atoi((char*) yKey); 130 int ypos = atoi((char*) yKey);
126 xmlFree(yKey); 131 xmlFree(yKey);
127 132
128 auto data = std::make_shared<MapObjectEntry>(obj, xpos, ypos); 133 xmlChar* indexKey = xmlGetProp(mapNode, (const xmlChar*) "index");
134 if (indexKey == 0) throw MapLoadException("entity missing index attribute");
135 int objIndex = atoi((char*) indexKey);
136 xmlFree(indexKey);
137
138 auto data = std::make_shared<MapObjectEntry>(obj, xpos, ypos, objIndex);
129 139
130 map->addObject(data, false); 140 map->addObject(data, false);
131 141
@@ -312,6 +322,10 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
312 // title= 322 // title=
313 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "title", (xmlChar*) map.getTitle().c_str()); 323 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "title", (xmlChar*) map.getTitle().c_str());
314 if (rc < 0) throw MapWriteException(name); 324 if (rc < 0) throw MapWriteException(name);
325
326 // nextObject=
327 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "nextObject", "%zu", map.getNextObjectIndex());
328 if (rc < 0) throw MapWriteException(name);
315 329
316 // <environment 330 // <environment
317 rc = xmlTextWriterStartElement(writer, (xmlChar*) "environment"); 331 rc = xmlTextWriterStartElement(writer, (xmlChar*) "environment");
@@ -358,6 +372,10 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
358 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "y", "%d", object->getPosition().second); 372 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "y", "%d", object->getPosition().second);
359 if (rc < 0) throw MapWriteException(name); 373 if (rc < 0) throw MapWriteException(name);
360 374
375 // index=
376 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "index", "%zu", object->getIndex());
377 if (rc < 0) throw MapWriteException(name);
378
361 for (auto item : object->getItems()) 379 for (auto item : object->getItems())
362 { 380 {
363 // <item 381 // <item