diff options
Diffstat (limited to 'tools/mapedit/src/map.cpp')
-rw-r--r-- | tools/mapedit/src/map.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
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) | |||
60 | { | 60 | { |
61 | if (!xmlStrcmp(entityNode->name, (const xmlChar*) "entity")) | 61 | if (!xmlStrcmp(entityNode->name, (const xmlChar*) "entity")) |
62 | { | 62 | { |
63 | MapObjectEntry data; | 63 | auto data = std::make_shared<MapObjectEntry>(); |
64 | |||
64 | for (xmlNodePtr entityDataNode = entityNode->xmlChildrenNode; entityDataNode != NULL; entityDataNode = entityDataNode->next) | 65 | for (xmlNodePtr entityDataNode = entityNode->xmlChildrenNode; entityDataNode != NULL; entityDataNode = entityDataNode->next) |
65 | { | 66 | { |
66 | if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-type")) | 67 | if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-type")) |
67 | { | 68 | { |
68 | xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); | 69 | xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); |
69 | data.object = MapObject::getAllObjects().at((char*) key).get(); | 70 | data->object = MapObject::getAllObjects().at((char*) key).get(); |
70 | xmlFree(key); | 71 | xmlFree(key); |
71 | } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position")) | 72 | } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position")) |
72 | { | 73 | { |
73 | xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); | 74 | xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); |
74 | sscanf((char*) key, "%lf,%lf", &data.position.first, &data.position.second); | 75 | sscanf((char*) key, "%lf,%lf", &data->position.first, &data->position.second); |
75 | xmlFree(key); | 76 | xmlFree(key); |
76 | } | 77 | } |
77 | } | 78 | } |
@@ -172,11 +173,11 @@ void Map::save(std::string name) | |||
172 | rc = xmlTextWriterStartElement(writer, (xmlChar*) "entity"); | 173 | rc = xmlTextWriterStartElement(writer, (xmlChar*) "entity"); |
173 | if (rc < 0) throw MapWriteException(name); | 174 | if (rc < 0) throw MapWriteException(name); |
174 | 175 | ||
175 | rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-type", (xmlChar*) object.object->getType().c_str()); | 176 | rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-type", (xmlChar*) object->object->getType().c_str()); |
176 | if (rc < 0) throw MapWriteException(name); | 177 | if (rc < 0) throw MapWriteException(name); |
177 | 178 | ||
178 | std::ostringstream entpos_out; | 179 | std::ostringstream entpos_out; |
179 | entpos_out << object.position.first << "," << object.position.second; | 180 | entpos_out << object->position.first << "," << object->position.second; |
180 | 181 | ||
181 | rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-position", (xmlChar*) entpos_out.str().c_str()); | 182 | rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-position", (xmlChar*) entpos_out.str().c_str()); |
182 | if (rc < 0) throw MapWriteException(name); | 183 | if (rc < 0) throw MapWriteException(name); |
@@ -226,7 +227,19 @@ void Map::setTitle(std::string title) | |||
226 | this->title = title; | 227 | this->title = title; |
227 | } | 228 | } |
228 | 229 | ||
229 | std::list<MapObjectEntry>& Map::getObjects() | 230 | const std::list<std::shared_ptr<MapObjectEntry>>& Map::getObjects() const |
230 | { | 231 | { |
231 | return objects; | 232 | return objects; |
232 | } | 233 | } |
234 | |||
235 | void Map::addObject(std::shared_ptr<MapObjectEntry>& obj) | ||
236 | { | ||
237 | dirty = true; | ||
238 | objects.push_back(obj); | ||
239 | } | ||
240 | |||
241 | void Map::removeObject(std::shared_ptr<MapObjectEntry>& obj) | ||
242 | { | ||
243 | dirty = true; | ||
244 | objects.remove(obj); | ||
245 | } | ||