summary refs log tree commit diff stats
path: root/tools/mapedit/src/map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mapedit/src/map.cpp')
-rw-r--r--tools/mapedit/src/map.cpp64
1 files changed, 57 insertions, 7 deletions
diff --git a/tools/mapedit/src/map.cpp b/tools/mapedit/src/map.cpp index 3a24ace..b0440fb 100644 --- a/tools/mapedit/src/map.cpp +++ b/tools/mapedit/src/map.cpp
@@ -54,6 +54,31 @@ Map::Map(std::string filename)
54 xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); 54 xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
55 rightmap = (char*) key; 55 rightmap = (char*) key;
56 xmlFree(key); 56 xmlFree(key);
57 } else if (!xmlStrcmp(node->name, (const xmlChar*) "entities"))
58 {
59 for (xmlNodePtr entityNode = node->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next)
60 {
61 if (!xmlStrcmp(entityNode->name, (const xmlChar*) "entity"))
62 {
63 MapObjectEntry data;
64 for (xmlNodePtr entityDataNode = entityNode->xmlChildrenNode; entityDataNode != NULL; entityDataNode = entityDataNode->next)
65 {
66 if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-type"))
67 {
68 xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1);
69 data.object = MapObject::getAllObjects().at((char*) key);
70 xmlFree(key);
71 } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position"))
72 {
73 xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1);
74 sscanf((char*) key, "%lf,%lf", &data.position.first, &data.position.second);
75 xmlFree(key);
76 }
77 }
78
79 objects.push_back(data);
80 }
81 }
57 } 82 }
58 } 83 }
59 84
@@ -69,6 +94,7 @@ Map::Map(const Map& map)
69 leftmap = map.leftmap; 94 leftmap = map.leftmap;
70 rightmap = map.rightmap; 95 rightmap = map.rightmap;
71 dirty = map.dirty; 96 dirty = map.dirty;
97 objects = map.objects;
72} 98}
73 99
74Map::Map(Map&& map) : Map() 100Map::Map(Map&& map) : Map()
@@ -95,6 +121,7 @@ void swap(Map& first, Map& second)
95 std::swap(first.leftmap, second.leftmap); 121 std::swap(first.leftmap, second.leftmap);
96 std::swap(first.rightmap, second.rightmap); 122 std::swap(first.rightmap, second.rightmap);
97 std::swap(first.dirty, second.dirty); 123 std::swap(first.dirty, second.dirty);
124 std::swap(first.objects, second.objects);
98} 125}
99 126
100#define MY_ENCODING "ISO-8859-1" 127#define MY_ENCODING "ISO-8859-1"
@@ -131,21 +158,39 @@ void Map::save(std::string name)
131 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "environment", (xmlChar*) mapdata_out.str().c_str()); 158 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "environment", (xmlChar*) mapdata_out.str().c_str());
132 if (rc < 0) throw MapWriteException(name); 159 if (rc < 0) throw MapWriteException(name);
133 160
134 if (leftmap != "") 161 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "leftmap", (xmlChar*) leftmap.c_str());
135 { 162 if (rc < 0) throw MapWriteException(name);
136 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "leftmap", (xmlChar*) leftmap.c_str()); 163
137 if (rc < 0) throw MapWriteException(name); 164 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "rightmap", (xmlChar*) rightmap.c_str());
138 } 165 if (rc < 0) throw MapWriteException(name);
139 166
140 if (rightmap != "") 167 rc = xmlTextWriterStartElement(writer, (xmlChar*) "entities");
168 if (rc < 0) throw MapWriteException(name);
169
170 for (auto object : objects)
141 { 171 {
142 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "rightmap", (xmlChar*) rightmap.c_str()); 172 rc = xmlTextWriterStartElement(writer, (xmlChar*) "entity");
173 if (rc < 0) throw MapWriteException(name);
174
175 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-type", (xmlChar*) object.object->getType().c_str());
176 if (rc < 0) throw MapWriteException(name);
177
178 std::ostringstream entpos_out;
179 entpos_out << object.position.first << "," << object.position.second;
180
181 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-position", (xmlChar*) entpos_out.str().c_str());
182 if (rc < 0) throw MapWriteException(name);
183
184 rc = xmlTextWriterEndElement(writer);
143 if (rc < 0) throw MapWriteException(name); 185 if (rc < 0) throw MapWriteException(name);
144 } 186 }
145 187
146 rc = xmlTextWriterEndElement(writer); 188 rc = xmlTextWriterEndElement(writer);
147 if (rc < 0) throw MapWriteException(name); 189 if (rc < 0) throw MapWriteException(name);
148 190
191 rc = xmlTextWriterEndElement(writer);
192 if (rc < 0) throw MapWriteException(name);
193
149 rc = xmlTextWriterEndDocument(writer); 194 rc = xmlTextWriterEndDocument(writer);
150 if (rc < 0) throw MapWriteException(name); 195 if (rc < 0) throw MapWriteException(name);
151 196
@@ -180,3 +225,8 @@ void Map::setTitle(std::string title)
180 dirty = true; 225 dirty = true;
181 this->title = title; 226 this->title = title;
182} 227}
228
229std::list<MapObjectEntry> Map::getObjects()
230{
231 return objects;
232}