From c46db36fe1c319a76cb6bd089b25952db0d98e11 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 16 Mar 2015 10:30:31 -0400 Subject: Added ability to edit and remove entities to map editor --- tools/mapedit/src/map.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tools/mapedit/src/map.cpp') diff --git a/tools/mapedit/src/map.cpp b/tools/mapedit/src/map.cpp index 1414e16..2799a4e 100644 --- a/tools/mapedit/src/map.cpp +++ b/tools/mapedit/src/map.cpp @@ -60,18 +60,19 @@ Map::Map(std::string filename) { if (!xmlStrcmp(entityNode->name, (const xmlChar*) "entity")) { - MapObjectEntry data; + auto data = std::make_shared(); + for (xmlNodePtr entityDataNode = entityNode->xmlChildrenNode; entityDataNode != NULL; entityDataNode = entityDataNode->next) { if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-type")) { xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); - data.object = MapObject::getAllObjects().at((char*) key).get(); + data->object = MapObject::getAllObjects().at((char*) key).get(); xmlFree(key); } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position")) { xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); - sscanf((char*) key, "%lf,%lf", &data.position.first, &data.position.second); + sscanf((char*) key, "%lf,%lf", &data->position.first, &data->position.second); xmlFree(key); } } @@ -172,11 +173,11 @@ void Map::save(std::string name) rc = xmlTextWriterStartElement(writer, (xmlChar*) "entity"); if (rc < 0) throw MapWriteException(name); - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-type", (xmlChar*) object.object->getType().c_str()); + rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-type", (xmlChar*) object->object->getType().c_str()); if (rc < 0) throw MapWriteException(name); std::ostringstream entpos_out; - entpos_out << object.position.first << "," << object.position.second; + entpos_out << object->position.first << "," << object->position.second; rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-position", (xmlChar*) entpos_out.str().c_str()); if (rc < 0) throw MapWriteException(name); @@ -226,7 +227,19 @@ void Map::setTitle(std::string title) this->title = title; } -std::list& Map::getObjects() +const std::list>& Map::getObjects() const { return objects; } + +void Map::addObject(std::shared_ptr& obj) +{ + dirty = true; + objects.push_back(obj); +} + +void Map::removeObject(std::shared_ptr& obj) +{ + dirty = true; + objects.remove(obj); +} -- cgit 1.4.1