summary refs log tree commit diff stats
path: root/tools/mapedit/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:55:37 -0400
committerGitHub <noreply@github.com>2018-05-17 15:55:37 -0400
commit90aadf3844386824140a20d7fbb847bc16009a94 (patch)
tree6f83fce90e71abb22b1a8f3e09c79963b2a34d5d /tools/mapedit/src
parentbc63fa57ced1c7329f7fdcfd168eaf7e290158bc (diff)
parent86f0106d0523825549f1e74b835688c78a10cf6c (diff)
downloadtherapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.gz
therapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.bz2
therapy-90aadf3844386824140a20d7fbb847bc16009a94.zip
Merge pull request #7 from hatkirby/es-rewrite
The ECS rewrite exceeds the original branch in functionality, so it is time to merge it in.
Diffstat (limited to 'tools/mapedit/src')
-rw-r--r--tools/mapedit/src/map.cpp14
-rw-r--r--tools/mapedit/src/map.h4
-rw-r--r--tools/mapedit/src/object.cpp15
-rw-r--r--tools/mapedit/src/object.h8
-rw-r--r--tools/mapedit/src/widget.cpp7
-rw-r--r--tools/mapedit/src/world.cpp20
6 files changed, 63 insertions, 5 deletions
diff --git a/tools/mapedit/src/map.cpp b/tools/mapedit/src/map.cpp index a099e29..7e6c3c0 100644 --- a/tools/mapedit/src/map.cpp +++ b/tools/mapedit/src/map.cpp
@@ -188,6 +188,11 @@ const Map::Adjacent& Map::getAdjacent(MoveDir direction) const
188 } 188 }
189} 189}
190 190
191size_t Map::getNextObjectIndex() const
192{
193 return nextObjectIndex;
194}
195
191void Map::setTitle(std::string title, bool dirty) 196void Map::setTitle(std::string title, bool dirty)
192{ 197{
193 this->title = title; 198 this->title = title;
@@ -271,3 +276,12 @@ void Map::setAdjacent(MoveDir direction, MoveType type, int map, bool dirty)
271 } 276 }
272} 277}
273 278
279size_t Map::getAndIncrementNextObjectIndex()
280{
281 return nextObjectIndex++;
282}
283
284void Map::setNextObjectIndex(size_t v)
285{
286 nextObjectIndex = v;
287}
diff --git a/tools/mapedit/src/map.h b/tools/mapedit/src/map.h index 9c14218..1ae905f 100644 --- a/tools/mapedit/src/map.h +++ b/tools/mapedit/src/map.h
@@ -89,6 +89,7 @@ class Map {
89 bool getHidden() const; 89 bool getHidden() const;
90 const std::map<MoveDir, Adjacent>& getAdjacents() const; 90 const std::map<MoveDir, Adjacent>& getAdjacents() const;
91 const Adjacent& getAdjacent(MoveDir direction) const; 91 const Adjacent& getAdjacent(MoveDir direction) const;
92 size_t getNextObjectIndex() const;
92 93
93 void setTitle(std::string title, bool dirty = true); 94 void setTitle(std::string title, bool dirty = true);
94 void setTileAt(int x, int y, int tile, bool dirty = true); 95 void setTileAt(int x, int y, int tile, bool dirty = true);
@@ -100,6 +101,8 @@ class Map {
100 void setExpanded(bool exp); 101 void setExpanded(bool exp);
101 void setHidden(bool hid); 102 void setHidden(bool hid);
102 void setAdjacent(MoveDir direction, MoveType type, int map = -1, bool dirty = true); 103 void setAdjacent(MoveDir direction, MoveType type, int map = -1, bool dirty = true);
104 size_t getAndIncrementNextObjectIndex();
105 void setNextObjectIndex(size_t v);
103 106
104 private: 107 private:
105 int id; 108 int id;
@@ -113,6 +116,7 @@ class Map {
113 bool hidden = false; 116 bool hidden = false;
114 std::map<MoveDir, Adjacent> adjacents; 117 std::map<MoveDir, Adjacent> adjacents;
115 const Adjacent defaultAdjacent {}; 118 const Adjacent defaultAdjacent {};
119 size_t nextObjectIndex = 0;
116}; 120};
117 121
118class MapPtrCtr : public wxTreeItemData { 122class MapPtrCtr : public wxTreeItemData {
diff --git a/tools/mapedit/src/object.cpp b/tools/mapedit/src/object.cpp index 8ed29af..aeb8fc1 100644 --- a/tools/mapedit/src/object.cpp +++ b/tools/mapedit/src/object.cpp
@@ -184,9 +184,15 @@ bool MapObject::operator!=(const MapObject& other) const
184 return id != other.id; 184 return id != other.id;
185} 185}
186 186
187MapObjectEntry::MapObjectEntry(const MapObject& object, int posx, int posy) : object(object) 187MapObjectEntry::MapObjectEntry(
188 const MapObject& object,
189 int posx,
190 int posy,
191 size_t index) :
192 object(object),
193 position(std::make_pair(posx, posy)),
194 index(index)
188{ 195{
189 position = std::make_pair(posx, posy);
190} 196}
191 197
192const MapObject& MapObjectEntry::getObject() const 198const MapObject& MapObjectEntry::getObject() const
@@ -209,6 +215,11 @@ const std::map<std::string, MapObjectEntry::Item>& MapObjectEntry::getItems() co
209 return items; 215 return items;
210} 216}
211 217
218size_t MapObjectEntry::getIndex() const
219{
220 return index;
221}
222
212void MapObjectEntry::addItem(std::string id, Item& item) 223void MapObjectEntry::addItem(std::string id, Item& item)
213{ 224{
214 items[id] = item; 225 items[id] = item;
diff --git a/tools/mapedit/src/object.h b/tools/mapedit/src/object.h index a870a2e..a87fa96 100644 --- a/tools/mapedit/src/object.h +++ b/tools/mapedit/src/object.h
@@ -67,7 +67,11 @@ class MapObject {
67 67
68class MapObjectEntry { 68class MapObjectEntry {
69 public: 69 public:
70 MapObjectEntry(const MapObject& object, int posx, int posy); 70 MapObjectEntry(
71 const MapObject& object,
72 int posx,
73 int posy,
74 size_t index);
71 75
72 struct Item { 76 struct Item {
73 MapObject::Input::Type type; 77 MapObject::Input::Type type;
@@ -78,6 +82,7 @@ class MapObjectEntry {
78 std::pair<int, int> getPosition() const; 82 std::pair<int, int> getPosition() const;
79 Item& getItem(std::string str); 83 Item& getItem(std::string str);
80 const std::map<std::string, Item>& getItems() const; 84 const std::map<std::string, Item>& getItems() const;
85 size_t getIndex() const;
81 86
82 void setPosition(int x, int y); 87 void setPosition(int x, int y);
83 void addItem(std::string id, Item& item); 88 void addItem(std::string id, Item& item);
@@ -89,6 +94,7 @@ class MapObjectEntry {
89 const MapObject& object; 94 const MapObject& object;
90 std::pair<int, int> position; 95 std::pair<int, int> position;
91 std::map<std::string, Item> items; 96 std::map<std::string, Item> items;
97 size_t index;
92}; 98};
93 99
94class VariableChoiceValidator : public wxValidator { 100class VariableChoiceValidator : public wxValidator {
diff --git a/tools/mapedit/src/widget.cpp b/tools/mapedit/src/widget.cpp index 8d74b39..85838e6 100644 --- a/tools/mapedit/src/widget.cpp +++ b/tools/mapedit/src/widget.cpp
@@ -256,7 +256,12 @@ void MapeditWidget::OnClick(wxMouseEvent& event)
256 int x = (event.GetPosition().x + vX - EDITOR_SPACING_X*scale) / scale - (addingEntity->getWidth() / 2); 256 int x = (event.GetPosition().x + vX - EDITOR_SPACING_X*scale) / scale - (addingEntity->getWidth() / 2);
257 int y = (event.GetPosition().y + vY - EDITOR_SPACING_Y*scale) / scale - (addingEntity->getHeight() / 2); 257 int y = (event.GetPosition().y + vY - EDITOR_SPACING_Y*scale) / scale - (addingEntity->getHeight() / 2);
258 258
259 auto data = std::make_shared<MapObjectEntry>(*addingEntity, x, y); 259 auto data = std::make_shared<MapObjectEntry>(
260 *addingEntity,
261 x,
262 y,
263 map->getAndIncrementNextObjectIndex());
264
260 frame->commitAction(std::make_shared<Undoable>("Add " + addingEntity->getName(), [=] () { 265 frame->commitAction(std::make_shared<Undoable>("Add " + addingEntity->getName(), [=] () {
261 map->addObject(data); 266 map->addObject(data);
262 267
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