From e4e2f2d2a7b6a282b9618aa0004d9453936f43c6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 18 Feb 2018 15:25:52 -0500 Subject: Added player death and event scheduling Also added ability to make sprites flicker, to freeze physics for an entity, and to freeze progression of a sprite's animation loop. --- res/maps.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'res/maps.xml') diff --git a/res/maps.xml b/res/maps.xml index 9d855a2..c561912 100644 --- a/res/maps.xml +++ b/res/maps.xml @@ -1,5 +1,5 @@ -00,0,0,0,0,0,0,0,0,0,19,0,0,0,0,0,20,0,0,0,0,0,0,0,18,9,8,10,8,11,8,10,10,8,11,8,9,10,21,0, +00,0,0,0,0,0,0,0,0,0,19,0,0,0,0,0,20,0,0,0,0,0,0,0,18,9,8,10,8,11,8,10,10,8,11,8,9,10,21,0, 0,0,0,0,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,8,8,17,0,0,0,0,0,0,0,0,0,0,0,0,0,22,21, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,8,8,8,8,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12, 0,19,0,0,0,0,0,0,0,0,0,0,0,18,8,8,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12, -- cgit 1.4.1 From 13f946689e28e99ac71172925f63f4320798a0ee Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 5 Mar 2018 16:07:07 -0500 Subject: 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. --- res/maps.xml | 10 +++++----- res/maps.xsd | 2 ++ tools/mapedit/src/map.cpp | 14 ++++++++++++++ tools/mapedit/src/map.h | 4 ++++ tools/mapedit/src/object.cpp | 15 +++++++++++++-- tools/mapedit/src/object.h | 8 +++++++- tools/mapedit/src/widget.cpp | 7 ++++++- tools/mapedit/src/world.cpp | 20 +++++++++++++++++++- 8 files changed, 70 insertions(+), 10 deletions(-) (limited to 'res/maps.xml') diff --git a/res/maps.xml b/res/maps.xml index c561912..81fe743 100644 --- a/res/maps.xml +++ b/res/maps.xml @@ -1,5 +1,5 @@ -00,0,0,0,0,0,0,0,0,0,19,0,0,0,0,0,20,0,0,0,0,0,0,0,18,9,8,10,8,11,8,10,10,8,11,8,9,10,21,0, +00,0,0,0,0,0,0,0,0,0,19,0,0,0,0,0,20,0,0,0,0,0,0,0,18,9,8,10,8,11,8,10,10,8,11,8,9,10,21,0, 0,0,0,0,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,8,8,17,0,0,0,0,0,0,0,0,0,0,0,0,0,22,21, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,8,8,8,8,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12, 0,19,0,0,0,0,0,0,0,0,0,0,0,18,8,8,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12, @@ -23,7 +23,7 @@ 0,0,0,0,24,3,1,2,1,1,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19,0,27,1,3,2,26,0,0,0,0,0,0, 1,2,3,1,25,0,0,0,0,0,20,0,0,0,0,0,0,19,0,0,0,0,0,0,20,0,0,0,0,0,0,0,0,27,1,2,2,4,3,1, 0,0,0,0,0,0,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,0,0,0, -1450,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1450,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19,0,0,0,0,0,0,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0, 0,0,20,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,13,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,13,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,13,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,13,0,0,0,20,0,0,0,0,0,0,0, 0,0,0,19,0,0,0,0,0,0,0,0,19,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,19,0,0,0,0,0, @@ -95,4 +95,4 @@ 2,2,2,2,2,2,26,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,12,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,27,1,3,4,2,1,3,2,1,1,2,4,1,1,1,3,1,1,4,2,1,3,4,1,25,19,0,0,0,0,0,0,0,0, 0,0,19,0,0,0,0,0,0,0,0,0,0,0,0,0,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -19030 +19030 diff --git a/res/maps.xsd b/res/maps.xsd index 9d36fab..64fd21f 100644 --- a/res/maps.xsd +++ b/res/maps.xsd @@ -54,6 +54,7 @@ + @@ -77,6 +78,7 @@ + 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 } } +size_t Map::getNextObjectIndex() const +{ + return nextObjectIndex; +} + void Map::setTitle(std::string title, bool dirty) { this->title = title; @@ -271,3 +276,12 @@ void Map::setAdjacent(MoveDir direction, MoveType type, int map, bool dirty) } } +size_t Map::getAndIncrementNextObjectIndex() +{ + return nextObjectIndex++; +} + +void Map::setNextObjectIndex(size_t v) +{ + nextObjectIndex = v; +} 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 { bool getHidden() const; const std::map& getAdjacents() const; const Adjacent& getAdjacent(MoveDir direction) const; + size_t getNextObjectIndex() const; void setTitle(std::string title, bool dirty = true); void setTileAt(int x, int y, int tile, bool dirty = true); @@ -100,6 +101,8 @@ class Map { void setExpanded(bool exp); void setHidden(bool hid); void setAdjacent(MoveDir direction, MoveType type, int map = -1, bool dirty = true); + size_t getAndIncrementNextObjectIndex(); + void setNextObjectIndex(size_t v); private: int id; @@ -113,6 +116,7 @@ class Map { bool hidden = false; std::map adjacents; const Adjacent defaultAdjacent {}; + size_t nextObjectIndex = 0; }; class 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 return id != other.id; } -MapObjectEntry::MapObjectEntry(const MapObject& object, int posx, int posy) : object(object) +MapObjectEntry::MapObjectEntry( + const MapObject& object, + int posx, + int posy, + size_t index) : + object(object), + position(std::make_pair(posx, posy)), + index(index) { - position = std::make_pair(posx, posy); } const MapObject& MapObjectEntry::getObject() const @@ -209,6 +215,11 @@ const std::map& MapObjectEntry::getItems() co return items; } +size_t MapObjectEntry::getIndex() const +{ + return index; +} + void MapObjectEntry::addItem(std::string id, Item& item) { 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 { class MapObjectEntry { public: - MapObjectEntry(const MapObject& object, int posx, int posy); + MapObjectEntry( + const MapObject& object, + int posx, + int posy, + size_t index); struct Item { MapObject::Input::Type type; @@ -78,6 +82,7 @@ class MapObjectEntry { std::pair getPosition() const; Item& getItem(std::string str); const std::map& getItems() const; + size_t getIndex() const; void setPosition(int x, int y); void addItem(std::string id, Item& item); @@ -89,6 +94,7 @@ class MapObjectEntry { const MapObject& object; std::pair position; std::map items; + size_t index; }; class 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) int x = (event.GetPosition().x + vX - EDITOR_SPACING_X*scale) / scale - (addingEntity->getWidth() / 2); int y = (event.GetPosition().y + vY - EDITOR_SPACING_Y*scale) / scale - (addingEntity->getHeight() / 2); - auto data = std::make_shared(*addingEntity, x, y); + auto data = std::make_shared( + *addingEntity, + x, + y, + map->getAndIncrementNextObjectIndex()); + frame->commitAction(std::make_shared("Add " + addingEntity->getName(), [=] () { map->addObject(data); 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) map->setTitle((char*) titleKey, false); xmlFree(titleKey); + xmlChar* noiKey = xmlGetProp(node, (xmlChar*) "nextObject"); + if (noiKey == 0) throw MapLoadException("map missing nextObject attribute"); + map->setNextObjectIndex(atoi((char*) noiKey)); + xmlFree(noiKey); + for (xmlNodePtr mapNode = node->xmlChildrenNode; mapNode != NULL; mapNode = mapNode->next) { if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment")) @@ -125,7 +130,12 @@ World::World(std::string filename) int ypos = atoi((char*) yKey); xmlFree(yKey); - auto data = std::make_shared(obj, xpos, ypos); + xmlChar* indexKey = xmlGetProp(mapNode, (const xmlChar*) "index"); + if (indexKey == 0) throw MapLoadException("entity missing index attribute"); + int objIndex = atoi((char*) indexKey); + xmlFree(indexKey); + + auto data = std::make_shared(obj, xpos, ypos, objIndex); map->addObject(data, false); @@ -312,6 +322,10 @@ void World::save(std::string name, wxTreeCtrl* mapTree) // title= rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "title", (xmlChar*) map.getTitle().c_str()); if (rc < 0) throw MapWriteException(name); + + // nextObject= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "nextObject", "%zu", map.getNextObjectIndex()); + if (rc < 0) throw MapWriteException(name); // getPosition().second); if (rc < 0) throw MapWriteException(name); + // index= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "index", "%zu", object->getIndex()); + if (rc < 0) throw MapWriteException(name); + for (auto item : object->getItems()) { //