From 103587c2d5f9deb20e549a86cdf5023b429cc6a1 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 18 Mar 2015 18:23:54 -0400 Subject: Wrote an XML Schema describing maps file and also changed the spec a bit --- tools/mapedit/src/frame.cpp | 188 ++++++++++---------- tools/mapedit/src/map.cpp | 162 ++++-------------- tools/mapedit/src/map.h | 44 +++-- tools/mapedit/src/widget.cpp | 16 +- tools/mapedit/src/world.cpp | 397 ++++++++++++++++--------------------------- 5 files changed, 315 insertions(+), 492 deletions(-) (limited to 'tools/mapedit/src') diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index cc45c29..06102f7 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp @@ -190,22 +190,22 @@ MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") wxStaticText* leftmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Leftmap Action:"); wxChoice* leftmapChoice = new wxChoice(propertyEditor, LEFTMAP_TYPE_CHOICE); wxComboCtrl* leftmapCombo = new wxComboCtrl(propertyEditor, LEFTMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY); - leftmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getLeftMoveMapID())); + leftmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getAdjacent(Map::MoveDir::Left).map)); wxStaticText* rightmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Rightmap Action:"); wxChoice* rightmapChoice = new wxChoice(propertyEditor, RIGHTMAP_TYPE_CHOICE); wxComboCtrl* rightmapCombo = new wxComboCtrl(propertyEditor, RIGHTMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY); - rightmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getRightMoveMapID())); + rightmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getAdjacent(Map::MoveDir::Right).map)); wxStaticText* upmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Upmap Action:"); wxChoice* upmapChoice = new wxChoice(propertyEditor, UPMAP_TYPE_CHOICE); wxComboCtrl* upmapCombo = new wxComboCtrl(propertyEditor, UPMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY); - upmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getUpMoveMapID())); + upmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getAdjacent(Map::MoveDir::Up).map)); wxStaticText* downmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Downmap Action:"); wxChoice* downmapChoice = new wxChoice(propertyEditor, DOWNMAP_TYPE_CHOICE); wxComboCtrl* downmapCombo = new wxComboCtrl(propertyEditor, DOWNMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY); - downmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getDownMoveMapID())); + downmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getAdjacent(Map::MoveDir::Down).map)); for (auto type : Map::listMoveTypes()) { @@ -674,157 +674,169 @@ void MapeditFrame::OnThreeMovingSash(wxSplitterEvent& event) void MapeditFrame::OnSetLeftmapType(wxCommandEvent&) { - wxChoice* leftmapChoice = (wxChoice*) wxWindow::FindWindowById(LEFTMAP_TYPE_CHOICE, this); - wxComboCtrl* leftmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(LEFTMAP_MAP_CHOICE, this); - - Map::MoveType old = currentMap->getLeftMoveType(); - Map::MoveType newt = ((MoveTypeCtr*) leftmapChoice->GetClientData(leftmapChoice->GetSelection()))->type; + wxChoice* choice = (wxChoice*) wxWindow::FindWindowById(LEFTMAP_TYPE_CHOICE, this); + wxComboCtrl* combo = (wxComboCtrl*) wxChoice::FindWindowById(LEFTMAP_MAP_CHOICE, this); + Map::MoveDir dir = Map::MoveDir::Left; + Map::Adjacent adjacent = currentMap->getAdjacent(dir); + Map::MoveType newt = ((MoveTypeCtr*) choice->GetClientData(choice->GetSelection()))->type; commitAction(std::make_shared("Set Leftmap Action", [=] () { - leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(newt))); - currentMap->setLeftMoveType(newt); - leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getLeftMoveType())); + choice->SetSelection(choice->FindString(Map::stringForMoveType(newt))); + currentMap->setAdjacent(dir, newt); + combo->Enable(Map::moveTypeTakesMap(newt)); }, [=] () { - leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(old))); - currentMap->setLeftMoveType(old); - leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getLeftMoveType())); + choice->SetSelection(choice->FindString(Map::stringForMoveType(adjacent.type))); + currentMap->setAdjacent(dir, adjacent.type); + combo->Enable(Map::moveTypeTakesMap(adjacent.type)); })); } void MapeditFrame::OnSetLeftmapMap(wxCommandEvent&) { - wxComboCtrl* leftmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(LEFTMAP_MAP_CHOICE, this); - MapSelectComboPopup* popup = (MapSelectComboPopup*) leftmapCombo->GetPopupControl(); - int old = currentMap->getLeftMoveMapID(); + wxComboCtrl* combo = (wxComboCtrl*) wxWindow::FindWindowById(LEFTMAP_MAP_CHOICE, this); + Map::MoveDir dir = Map::MoveDir::Left; + + Map::Adjacent adjacent = currentMap->getAdjacent(dir); + MapSelectComboPopup* popup = (MapSelectComboPopup*) combo->GetPopupControl(); + int old = adjacent.map; int newt = popup->GetSelectedMapID(); if (old == newt) return; commitAction(std::make_shared("Set Leftmap Map", [=] () { popup->SetSelectedMapID(newt); - leftmapCombo->SetValue(world->getMap(newt)->getTitle()); - currentMap->setLeftMoveMapID(newt); + combo->SetValue(world->getMap(newt)->getTitle()); + currentMap->setAdjacent(dir, adjacent.type, newt); }, [=] () { popup->SetSelectedMapID(old); - leftmapCombo->SetValue(world->getMap(old)->getTitle()); - currentMap->setLeftMoveMapID(old); + combo->SetValue(world->getMap(old)->getTitle()); + currentMap->setAdjacent(dir, adjacent.type, old); })); } void MapeditFrame::OnSetRightmapType(wxCommandEvent&) { - wxChoice* rightmapChoice = (wxChoice*) wxWindow::FindWindowById(RIGHTMAP_TYPE_CHOICE, this); - wxComboCtrl* rightmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(RIGHTMAP_MAP_CHOICE, this); - - Map::MoveType old = currentMap->getRightMoveType(); - Map::MoveType newt = ((MoveTypeCtr*) rightmapChoice->GetClientData(rightmapChoice->GetSelection()))->type; + wxChoice* choice = (wxChoice*) wxWindow::FindWindowById(RIGHTMAP_TYPE_CHOICE, this); + wxComboCtrl* combo = (wxComboCtrl*) wxChoice::FindWindowById(RIGHTMAP_MAP_CHOICE, this); + Map::MoveDir dir = Map::MoveDir::Right; + Map::Adjacent adjacent = currentMap->getAdjacent(dir); + Map::MoveType newt = ((MoveTypeCtr*) choice->GetClientData(choice->GetSelection()))->type; commitAction(std::make_shared("Set Rightmap Action", [=] () { - rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(newt))); - currentMap->setRightMoveType(newt); - rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getRightMoveType())); + choice->SetSelection(choice->FindString(Map::stringForMoveType(newt))); + currentMap->setAdjacent(dir, newt); + combo->Enable(Map::moveTypeTakesMap(newt)); }, [=] () { - rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(old))); - currentMap->setRightMoveType(old); - rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getRightMoveType())); + choice->SetSelection(choice->FindString(Map::stringForMoveType(adjacent.type))); + currentMap->setAdjacent(dir, adjacent.type); + combo->Enable(Map::moveTypeTakesMap(adjacent.type)); })); } void MapeditFrame::OnSetRightmapMap(wxCommandEvent&) { - wxComboCtrl* rightmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(RIGHTMAP_MAP_CHOICE, this); - MapSelectComboPopup* popup = (MapSelectComboPopup*) rightmapCombo->GetPopupControl(); - int old = currentMap->getRightMoveMapID(); + wxComboCtrl* combo = (wxComboCtrl*) wxWindow::FindWindowById(RIGHTMAP_MAP_CHOICE, this); + Map::MoveDir dir = Map::MoveDir::Right; + + Map::Adjacent adjacent = currentMap->getAdjacent(dir); + MapSelectComboPopup* popup = (MapSelectComboPopup*) combo->GetPopupControl(); + int old = adjacent.map; int newt = popup->GetSelectedMapID(); if (old == newt) return; commitAction(std::make_shared("Set Rightmap Map", [=] () { popup->SetSelectedMapID(newt); - rightmapCombo->SetValue(world->getMap(newt)->getTitle()); - currentMap->setRightMoveMapID(newt); + combo->SetValue(world->getMap(newt)->getTitle()); + currentMap->setAdjacent(dir, adjacent.type, newt); }, [=] () { popup->SetSelectedMapID(old); - rightmapCombo->SetValue(world->getMap(old)->getTitle()); - currentMap->setRightMoveMapID(old); + combo->SetValue(world->getMap(old)->getTitle()); + currentMap->setAdjacent(dir, adjacent.type, old); })); } void MapeditFrame::OnSetUpmapType(wxCommandEvent&) { - wxChoice* upmapChoice = (wxChoice*) wxWindow::FindWindowById(UPMAP_TYPE_CHOICE, this); - wxComboCtrl* upmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this); - - Map::MoveType old = currentMap->getUpMoveType(); - Map::MoveType newt = ((MoveTypeCtr*) upmapChoice->GetClientData(upmapChoice->GetSelection()))->type; + wxChoice* choice = (wxChoice*) wxWindow::FindWindowById(UPMAP_TYPE_CHOICE, this); + wxComboCtrl* combo = (wxComboCtrl*) wxChoice::FindWindowById(UPMAP_MAP_CHOICE, this); + Map::MoveDir dir = Map::MoveDir::Up; + Map::Adjacent adjacent = currentMap->getAdjacent(dir); + Map::MoveType newt = ((MoveTypeCtr*) choice->GetClientData(choice->GetSelection()))->type; commitAction(std::make_shared("Set Upmap Action", [=] () { - upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(newt))); - currentMap->setUpMoveType(newt); - upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getUpMoveType())); + choice->SetSelection(choice->FindString(Map::stringForMoveType(newt))); + currentMap->setAdjacent(dir, newt); + combo->Enable(Map::moveTypeTakesMap(newt)); }, [=] () { - upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(old))); - currentMap->setUpMoveType(old); - upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getUpMoveType())); + choice->SetSelection(choice->FindString(Map::stringForMoveType(adjacent.type))); + currentMap->setAdjacent(dir, adjacent.type); + combo->Enable(Map::moveTypeTakesMap(adjacent.type)); })); } void MapeditFrame::OnSetUpmapMap(wxCommandEvent&) { - wxComboCtrl* upmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this); - MapSelectComboPopup* popup = (MapSelectComboPopup*) upmapCombo->GetPopupControl(); - int old = currentMap->getUpMoveMapID(); + wxComboCtrl* combo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this); + Map::MoveDir dir = Map::MoveDir::Up; + + Map::Adjacent adjacent = currentMap->getAdjacent(dir); + MapSelectComboPopup* popup = (MapSelectComboPopup*) combo->GetPopupControl(); + int old = adjacent.map; int newt = popup->GetSelectedMapID(); if (old == newt) return; commitAction(std::make_shared("Set Upmap Map", [=] () { popup->SetSelectedMapID(newt); - upmapCombo->SetValue(world->getMap(newt)->getTitle()); - currentMap->setUpMoveMapID(newt); + combo->SetValue(world->getMap(newt)->getTitle()); + currentMap->setAdjacent(dir, adjacent.type, newt); }, [=] () { popup->SetSelectedMapID(old); - upmapCombo->SetValue(world->getMap(old)->getTitle()); - currentMap->setUpMoveMapID(old); + combo->SetValue(world->getMap(old)->getTitle()); + currentMap->setAdjacent(dir, adjacent.type, old); })); } void MapeditFrame::OnSetDownmapType(wxCommandEvent&) { - wxChoice* downmapChoice = (wxChoice*) wxWindow::FindWindowById(DOWNMAP_TYPE_CHOICE, this); - wxComboCtrl* downmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this); - - Map::MoveType old = currentMap->getDownMoveType(); - Map::MoveType newt = ((MoveTypeCtr*) downmapChoice->GetClientData(downmapChoice->GetSelection()))->type; + wxChoice* choice = (wxChoice*) wxWindow::FindWindowById(DOWNMAP_TYPE_CHOICE, this); + wxComboCtrl* combo = (wxComboCtrl*) wxChoice::FindWindowById(DOWNMAP_MAP_CHOICE, this); + Map::MoveDir dir = Map::MoveDir::Down; + Map::Adjacent adjacent = currentMap->getAdjacent(dir); + Map::MoveType newt = ((MoveTypeCtr*) choice->GetClientData(choice->GetSelection()))->type; commitAction(std::make_shared("Set Downmap Action", [=] () { - downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(newt))); - currentMap->setDownMoveType(newt); - downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getDownMoveType())); + choice->SetSelection(choice->FindString(Map::stringForMoveType(newt))); + currentMap->setAdjacent(dir, newt); + combo->Enable(Map::moveTypeTakesMap(newt)); }, [=] () { - downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(old))); - currentMap->setDownMoveType(old); - downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getDownMoveType())); + choice->SetSelection(choice->FindString(Map::stringForMoveType(adjacent.type))); + currentMap->setAdjacent(dir, adjacent.type); + combo->Enable(Map::moveTypeTakesMap(adjacent.type)); })); } void MapeditFrame::OnSetDownmapMap(wxCommandEvent&) { - wxComboCtrl* downmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this); - MapSelectComboPopup* popup = (MapSelectComboPopup*) downmapCombo->GetPopupControl(); - int old = currentMap->getDownMoveMapID(); + wxComboCtrl* combo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this); + Map::MoveDir dir = Map::MoveDir::Down; + + Map::Adjacent adjacent = currentMap->getAdjacent(dir); + MapSelectComboPopup* popup = (MapSelectComboPopup*) combo->GetPopupControl(); + int old = adjacent.map; int newt = popup->GetSelectedMapID(); if (old == newt) return; commitAction(std::make_shared("Set Downmap Map", [=] () { popup->SetSelectedMapID(newt); - downmapCombo->SetValue(world->getMap(newt)->getTitle()); - currentMap->setDownMoveMapID(newt); + combo->SetValue(world->getMap(newt)->getTitle()); + currentMap->setAdjacent(dir, adjacent.type, newt); }, [=] () { popup->SetSelectedMapID(old); - downmapCombo->SetValue(world->getMap(old)->getTitle()); - currentMap->setDownMoveMapID(old); + combo->SetValue(world->getMap(old)->getTitle()); + currentMap->setAdjacent(dir, adjacent.type, old); })); } @@ -924,20 +936,20 @@ void MapeditFrame::SelectMap(Map* map) wxComboCtrl* upmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this); wxComboCtrl* downmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this); - leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(currentMap->getLeftMoveType()))); - rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(currentMap->getRightMoveType()))); - upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(currentMap->getUpMoveType()))); - downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(currentMap->getDownMoveType()))); + leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(currentMap->getAdjacent(Map::MoveDir::Left).type))); + rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(currentMap->getAdjacent(Map::MoveDir::Right).type))); + upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(currentMap->getAdjacent(Map::MoveDir::Up).type))); + downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(currentMap->getAdjacent(Map::MoveDir::Down).type))); - leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getLeftMoveType())); - rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getRightMoveType())); - upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getUpMoveType())); - downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getDownMoveType())); + leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getAdjacent(Map::MoveDir::Left).type)); + rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getAdjacent(Map::MoveDir::Right).type)); + upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getAdjacent(Map::MoveDir::Up).type)); + downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getAdjacent(Map::MoveDir::Down).type)); - leftmapCombo->SetValue(world->getMap(currentMap->getLeftMoveMapID())->getTitle()); - rightmapCombo->SetValue(world->getMap(currentMap->getRightMoveMapID())->getTitle()); - upmapCombo->SetValue(world->getMap(currentMap->getUpMoveMapID())->getTitle()); - downmapCombo->SetValue(world->getMap(currentMap->getDownMoveMapID())->getTitle()); + leftmapCombo->SetValue(world->getMap(currentMap->getAdjacent(Map::MoveDir::Left).map)->getTitle()); + rightmapCombo->SetValue(world->getMap(currentMap->getAdjacent(Map::MoveDir::Right).map)->getTitle()); + upmapCombo->SetValue(world->getMap(currentMap->getAdjacent(Map::MoveDir::Up).map)->getTitle()); + downmapCombo->SetValue(world->getMap(currentMap->getAdjacent(Map::MoveDir::Down).map)->getTitle()); } wxTreeItemId MapeditFrame::MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newParent) diff --git a/tools/mapedit/src/map.cpp b/tools/mapedit/src/map.cpp index fb675e8..a099e29 100644 --- a/tools/mapedit/src/map.cpp +++ b/tools/mapedit/src/map.cpp @@ -21,14 +21,7 @@ Map::Map(const Map& map) treeItemId = map.treeItemId; children = map.children; hidden = map.hidden; - leftType = map.leftType; - rightType = map.rightType; - upType = map.upType; - downType = map.downType; - leftMap = map.leftMap; - rightMap = map.rightMap; - downMap = map.downMap; - upMap = map.upMap; + adjacents = map.adjacents; } Map::Map(Map&& map) : Map(-1, map.world) @@ -58,14 +51,7 @@ void swap(Map& first, Map& second) std::swap(first.treeItemId, second.treeItemId); std::swap(first.children, second.children); std::swap(first.hidden, second.hidden); - std::swap(first.leftType, second.leftType); - std::swap(first.rightType, second.rightType); - std::swap(first.upType, second.upType); - std::swap(first.downType, second.downType); - std::swap(first.leftMap, second.leftMap); - std::swap(first.rightMap, second.rightMap); - std::swap(first.downMap, second.downMap); - std::swap(first.upMap, second.upMap); + std::swap(first.adjacents, second.adjacents); } std::list Map::listMoveTypes() @@ -78,9 +64,9 @@ std::string Map::stringForMoveType(MoveType type) switch (type) { case MoveType::Wall: return "Wall"; - case MoveType::Warp: return "Warp"; + case MoveType::Warp: return "Teleport"; case MoveType::Wrap: return "Wrap"; - case MoveType::ReverseWarp: return "Reverse Warp"; + case MoveType::ReverseWarp: return "Reverse Teleport"; } } @@ -106,6 +92,17 @@ std::string Map::shortForMoveType(MoveType type) } } +std::string Map::shortForMoveDir(MoveDir dir) +{ + switch (dir) + { + case MoveDir::Left: return "left"; + case MoveDir::Right: return "right"; + case MoveDir::Up: return "up"; + case MoveDir::Down: return "down"; + } +} + Map::MoveType Map::moveTypeForShort(std::string str) { if (str == "wrap") return MoveType::Wrap; @@ -115,6 +112,15 @@ Map::MoveType Map::moveTypeForShort(std::string str) return MoveType::Wall; } +Map::MoveDir Map::moveDirForShort(std::string str) +{ + if (str == "right") return MoveDir::Right; + if (str == "up") return MoveDir::Up; + if (str == "down") return MoveDir::Down; + + return MoveDir::Left; +} + int Map::getID() const { return id; @@ -167,47 +173,21 @@ bool Map::getHidden() const return hidden; } -Map::MoveType Map::getLeftMoveType() const -{ - return leftType; -} - -Map::MoveType Map::getRightMoveType() const -{ - return rightType; -} - -Map::MoveType Map::getUpMoveType() const +const std::map& Map::getAdjacents() const { - return upType; + return adjacents; } -Map::MoveType Map::getDownMoveType() const +const Map::Adjacent& Map::getAdjacent(MoveDir direction) const { - return downType; -} - -int Map::getLeftMoveMapID() const -{ - return leftMap; -} - -int Map::getRightMoveMapID() const -{ - return rightMap; -} - -int Map::getUpMoveMapID() const -{ - return upMap; -} - -int Map::getDownMoveMapID() const -{ - return downMap; + if (adjacents.count(direction) > 0) + { + return adjacents.at(direction); + } else { + return defaultAdjacent; + } } - void Map::setTitle(std::string title, bool dirty) { this->title = title; @@ -279,79 +259,11 @@ void Map::setHidden(bool hid) hidden = hid; } -void Map::setLeftMoveType(Map::MoveType move, bool dirty) -{ - leftType = move; - - if (dirty) - { - world->setDirty(true); - } -} - -void Map::setRightMoveType(Map::MoveType move, bool dirty) -{ - rightType = move; - - if (dirty) - { - world->setDirty(true); - } -} - -void Map::setUpMoveType(Map::MoveType move, bool dirty) -{ - upType = move; - - if (dirty) - { - world->setDirty(true); - } -} - -void Map::setDownMoveType(Map::MoveType move, bool dirty) -{ - downType = move; - - if (dirty) - { - world->setDirty(true); - } -} - -void Map::setLeftMoveMapID(int id, bool dirty) -{ - leftMap = id; - - if (dirty) - { - world->setDirty(true); - } -} - -void Map::setRightMoveMapID(int id, bool dirty) -{ - rightMap = id; - - if (dirty) - { - world->setDirty(true); - } -} - -void Map::setUpMoveMapID(int id, bool dirty) -{ - upMap = id; - - if (dirty) - { - world->setDirty(true); - } -} - -void Map::setDownMoveMapID(int id, bool dirty) +void Map::setAdjacent(MoveDir direction, MoveType type, int map, bool dirty) { - downMap = id; + Adjacent& cur = adjacents[direction]; + cur.type = type; + if (map != -1) cur.map = map; if (dirty) { diff --git a/tools/mapedit/src/map.h b/tools/mapedit/src/map.h index 46e5790..c7f5b30 100644 --- a/tools/mapedit/src/map.h +++ b/tools/mapedit/src/map.h @@ -7,6 +7,7 @@ #include #include #include +#include class MapObject; class World; @@ -64,6 +65,13 @@ class Map { Map& operator= (Map other); friend void swap(Map& first, Map& second); + enum class MoveDir { + Left, + Right, + Up, + Down + }; + enum class MoveType { Wall, Wrap, @@ -71,11 +79,18 @@ class Map { ReverseWarp }; + struct Adjacent { + MoveType type = MoveType::Wall; + int map = 0; + }; + static std::list listMoveTypes(); static std::string stringForMoveType(MoveType type); static bool moveTypeTakesMap(MoveType type); static std::string shortForMoveType(MoveType type); + static std::string shortForMoveDir(MoveDir dir); static MoveType moveTypeForShort(std::string str); + static MoveDir moveDirForShort(std::string str); int getID() const; std::string getTitle() const; @@ -86,14 +101,8 @@ class Map { bool getExpanded() const; World* getWorld() const; bool getHidden() const; - MoveType getLeftMoveType() const; - MoveType getRightMoveType() const; - MoveType getUpMoveType() const; - MoveType getDownMoveType() const; - int getLeftMoveMapID() const; - int getRightMoveMapID() const; - int getUpMoveMapID() const; - int getDownMoveMapID() const; + const std::map& getAdjacents() const; + const Adjacent& getAdjacent(MoveDir direction) const; void setTitle(std::string title, bool dirty = true); void setTileAt(int x, int y, int tile, bool dirty = true); @@ -104,14 +113,7 @@ class Map { void addChild(int id); void setExpanded(bool exp); void setHidden(bool hid); - void setLeftMoveType(MoveType move, bool dirty = true); - void setRightMoveType(MoveType move, bool dirty = true); - void setUpMoveType(MoveType move, bool dirty = true); - void setDownMoveType(MoveType move, bool dirty = true); - void setLeftMoveMapID(int id, bool dirty = true); - void setRightMoveMapID(int id, bool dirty = true); - void setUpMoveMapID(int id, bool dirty = true); - void setDownMoveMapID(int id, bool dirty = true); + void setAdjacent(MoveDir direction, MoveType type, int map = -1, bool dirty = true); private: int id; @@ -123,14 +125,8 @@ class Map { wxTreeItemId treeItemId; bool expanded = false; bool hidden = false; - MoveType leftType = MoveType::Wall; - MoveType rightType = MoveType::Wall; - MoveType upType = MoveType::Wall; - MoveType downType = MoveType::Wall; - int leftMap = 0; - int rightMap = 0; - int upMap = 0; - int downMap = 0; + std::map adjacents; + const Adjacent defaultAdjacent {}; }; class MapPtrCtr : public wxTreeItemData { diff --git a/tools/mapedit/src/widget.cpp b/tools/mapedit/src/widget.cpp index 7f90880..fa0af39 100644 --- a/tools/mapedit/src/widget.cpp +++ b/tools/mapedit/src/widget.cpp @@ -75,30 +75,30 @@ void MapeditWidget::OnPaint(wxPaintEvent&) RenderMap(map, dc, tiles_dc); - if (map->getLeftMoveType() == Map::MoveType::Warp) + if (map->getAdjacent(Map::MoveDir::Left).type == Map::MoveType::Warp) { - auto tomap = map->getWorld()->getMap(map->getLeftMoveMapID()); + auto tomap = map->getWorld()->getMap(map->getAdjacent(Map::MoveDir::Left).map); RenderMap(tomap.get(), dc, tiles_dc, -EDITOR_SPACING_X, EDITOR_SPACING_Y, false); } - if (map->getRightMoveType() == Map::MoveType::Warp) + if (map->getAdjacent(Map::MoveDir::Right).type == Map::MoveType::Warp) { - auto tomap = map->getWorld()->getMap(map->getRightMoveMapID()); + auto tomap = map->getWorld()->getMap(map->getAdjacent(Map::MoveDir::Right).map); RenderMap(tomap.get(), dc, tiles_dc, EDITOR_WIDTH-EDITOR_SPACING_X, EDITOR_SPACING_Y, false); } - if (map->getUpMoveType() == Map::MoveType::Warp) + if (map->getAdjacent(Map::MoveDir::Up).type == Map::MoveType::Warp) { - auto tomap = map->getWorld()->getMap(map->getUpMoveMapID()); + auto tomap = map->getWorld()->getMap(map->getAdjacent(Map::MoveDir::Up).map); RenderMap(tomap.get(), dc, tiles_dc, EDITOR_SPACING_X, -EDITOR_SPACING_Y, false); } - if (map->getDownMoveType() == Map::MoveType::Warp) + if (map->getAdjacent(Map::MoveDir::Down).type == Map::MoveType::Warp) { - auto tomap = map->getWorld()->getMap(map->getDownMoveMapID()); + auto tomap = map->getWorld()->getMap(map->getAdjacent(Map::MoveDir::Down).map); RenderMap(tomap.get(), dc, tiles_dc, EDITOR_SPACING_X, EDITOR_HEIGHT-EDITOR_SPACING_Y, false); } diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index 043cf8a..01225cf 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp @@ -36,43 +36,43 @@ World::World(std::string filename) throw MapLoadException(filename); } + xmlChar* nextmapKey = xmlGetProp(top, (xmlChar*) "nextmap"); + if (nextmapKey != 0) + { + nextMapID = atoi((char*) nextmapKey); + } + xmlFree(nextmapKey); + + xmlChar* lastmapKey = xmlGetProp(top, (xmlChar*) "lastmap"); + if (lastmapKey != 0) + { + lastmap = atoi((char*) lastmapKey); + } + xmlFree(lastmapKey); + + xmlChar* startxKey = xmlGetProp(top, (xmlChar*) "startx"); + if (startxKey == 0) throw MapLoadException(filename); + startingPosition.first = atoi((char*) startxKey); + xmlFree(startxKey); + + xmlChar* startyKey = xmlGetProp(top, (xmlChar*) "starty"); + if (startyKey == 0) throw MapLoadException(filename); + startingPosition.second = atoi((char*) startyKey); + xmlFree(startyKey); + + xmlChar* startmapKey = xmlGetProp(top, (xmlChar*) "startmap"); + if (startxKey == 0) throw MapLoadException(filename); + startingMap = atoi((char*) startmapKey); + xmlFree(startmapKey); + for (xmlNodePtr node = top->xmlChildrenNode; node != NULL; node = node->next) { - if (!xmlStrcmp(node->name, (const xmlChar*) "nextmapid")) - { - xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (key != 0) - { - nextMapID = atoi((char*) key); - } - xmlFree(key); - } else if (!xmlStrcmp(node->name, (const xmlChar*) "lastmap")) + if (!xmlStrcmp(node->name, (const xmlChar*) "root")) { xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (key != 0) - { - lastmap = atoi((char*) key); - } + if (key == 0) throw MapLoadException(filename); + rootChildren.push_back(atoi((char*) key)); xmlFree(key); - } else if (!xmlStrcmp(node->name, (const xmlChar*) "root")) - { - xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (key != 0) - { - rootChildren.push_back(atoi((char*) key)); - } - xmlFree(key); - } else if (!xmlStrcmp(node->name, (const xmlChar*) "startpos")) - { - xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id"); - if (idKey == 0) throw MapLoadException(filename); - startingMap = atoi((char*) idKey); - xmlFree(idKey); - - xmlChar* posKey = xmlGetProp(node, (xmlChar*) "pos"); - if (posKey == 0) throw MapLoadException(filename); - sscanf((char*) posKey, "%d,%d", &startingPosition.first, &startingPosition.second); - xmlFree(posKey); } else if (!xmlStrcmp(node->name, (const xmlChar*) "map")) { xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id"); @@ -82,18 +82,21 @@ World::World(std::string filename) auto map = std::make_shared(id, this); + xmlChar* expandKey = xmlGetProp(node, (xmlChar*) "expanded"); + if ((expandKey != 0) && (!xmlStrcmp(expandKey, (const xmlChar*) "true"))) + { + map->setExpanded(true); + } + xmlFree(expandKey); + + xmlChar* titleKey = xmlGetProp(node, (xmlChar*) "title"); + if (titleKey == 0) throw MapLoadException(filename); + map->setTitle((char*) titleKey, false); + xmlFree(titleKey); + for (xmlNodePtr mapNode = node->xmlChildrenNode; mapNode != NULL; mapNode = mapNode->next) { - if (!xmlStrcmp(mapNode->name, (const xmlChar*) "name")) - { - xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); - if (key != 0) - { - map->setTitle((char*) key, false); - } - - xmlFree(key); - } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment")) + if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment")) { xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); int* mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int)); @@ -104,88 +107,50 @@ World::World(std::string filename) } map->setMapdata(mapdata, false); xmlFree(key); - } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "leftmap")) + } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entity")) { - xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); - if (typeKey == 0) throw MapLoadException(filename); - map->setLeftMoveType(Map::moveTypeForShort((char*) typeKey), false); - xmlFree(typeKey); + auto data = std::make_shared(); - if (Map::moveTypeTakesMap(map->getLeftMoveType())) - { - xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); - if (idKey == 0) throw MapLoadException(filename); - map->setLeftMoveMapID(atoi((char*) idKey), false); - xmlFree(idKey); - } - } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "rightmap")) - { - xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); + xmlChar* typeKey = xmlGetProp(mapNode, (const xmlChar*) "type"); if (typeKey == 0) throw MapLoadException(filename); - map->setRightMoveType(Map::moveTypeForShort((char*) typeKey), false); + data->object = MapObject::getAllObjects().at((char*) typeKey).get(); xmlFree(typeKey); - if (Map::moveTypeTakesMap(map->getRightMoveType())) - { - xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); - if (idKey == 0) throw MapLoadException(filename); - map->setRightMoveMapID(atoi((char*) idKey), false); - xmlFree(idKey); - } - } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "upmap")) - { - xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); - if (typeKey == 0) throw MapLoadException(filename); - map->setUpMoveType(Map::moveTypeForShort((char*) typeKey), false); - xmlFree(typeKey); + xmlChar* xKey = xmlGetProp(mapNode, (const xmlChar*) "x"); + if (xKey == 0) throw MapLoadException(filename); + data->position.first = atoi((char*) xKey); + xmlFree(xKey); - if (Map::moveTypeTakesMap(map->getUpMoveType())) - { - xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); - if (idKey == 0) throw MapLoadException(filename); - map->setUpMoveMapID(atoi((char*) idKey), false); - xmlFree(idKey); - } - } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "downmap")) + xmlChar* yKey = xmlGetProp(mapNode, (const xmlChar*) "y"); + if (yKey == 0) throw MapLoadException(filename); + data->position.second = atoi((char*) yKey); + xmlFree(yKey); + + map->addObject(data, false); + } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "adjacent")) { - xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); + Map::MoveDir direction; + Map::MoveType moveType; + int mapId = 0; + + xmlChar* dirKey = xmlGetProp(mapNode, (const xmlChar*) "dir"); + if (dirKey == 0) throw MapLoadException(filename); + direction = Map::moveDirForShort((char*) dirKey); + xmlFree(dirKey); + + xmlChar* typeKey = xmlGetProp(mapNode, (const xmlChar*) "type"); if (typeKey == 0) throw MapLoadException(filename); - map->setDownMoveType(Map::moveTypeForShort((char*) typeKey), false); + moveType = Map::moveTypeForShort((char*) typeKey); xmlFree(typeKey); - if (Map::moveTypeTakesMap(map->getDownMoveType())) + xmlChar* mapIdKey = xmlGetProp(mapNode, (const xmlChar*) "map"); + if (mapIdKey != 0) { - xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); - if (idKey == 0) throw MapLoadException(filename); - map->setDownMoveMapID(atoi((char*) idKey), false); - xmlFree(idKey); + mapId = atoi((char*) mapIdKey); } - } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entities")) - { - for (xmlNodePtr entityNode = mapNode->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next) - { - if (!xmlStrcmp(entityNode->name, (const xmlChar*) "entity")) - { - auto data = std::make_shared(); + xmlFree(mapIdKey); - 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(); - xmlFree(key); - } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position")) - { - xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1); - sscanf((char*) key, "%d,%d", &data->position.first, &data->position.second); - xmlFree(key); - } - } - - map->addObject(data, false); - } - } + map->setAdjacent(direction, moveType, mapId, false); } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "child")) { xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); @@ -194,13 +159,6 @@ World::World(std::string filename) map->addChild(atoi((char*) key)); } xmlFree(key); - } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "expanded")) - { - xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); - if ((key != 0) && ((char) key[0] == '1')) - { - map->setExpanded(true); - } } } @@ -266,16 +224,24 @@ void World::save(std::string name, wxTreeCtrl* mapTree) rc = xmlTextWriterStartElement(writer, (xmlChar*) "world"); if (rc < 0) throw MapWriteException(name); - // - std::ostringstream nextMap_out; - nextMap_out << nextMapID; - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "nextmapid", (xmlChar*) nextMap_out.str().c_str()); + // nextmap= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "nextmap", "%d", nextMapID); + if (rc < 0) throw MapWriteException(name); + + // lastmap= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "lastmap", "%d", lastmap); + if (rc < 0) throw MapWriteException(name); + + // startx= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "startx", "%d", startingPosition.first); if (rc < 0) throw MapWriteException(name); - // - std::ostringstream lastMap_out; - lastMap_out << lastmap; - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "lastmap", (xmlChar*) lastMap_out.str().c_str()); + // starty= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "starty", "%d", startingPosition.second); + if (rc < 0) throw MapWriteException(name); + + // startmap= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "startmap", "%d", startingMap); if (rc < 0) throw MapWriteException(name); // ASSUMPTION: There will always be at least one child of the invisible root element. i.e. you cannot delete to zero maps. @@ -285,28 +251,10 @@ void World::save(std::string name, wxTreeCtrl* mapTree) { // MapPtrCtr* ctl = (MapPtrCtr*) mapTree->GetItemData(it); - std::ostringstream rootid_out; - rootid_out << ctl->map->getID(); - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "root", (xmlChar*) rootid_out.str().c_str()); + rc = xmlTextWriterWriteFormatElement(writer, (xmlChar*) "root", "%d", ctl->map->getID()); if (rc < 0) throw MapWriteException(name); } - // - rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos"); - if (rc < 0) throw MapWriteException(name); - - // id= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "id", "%d", startingMap); - if (rc < 0) throw MapWriteException(name); - - // pos= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "pos", "%d,%d", startingPosition.first, startingPosition.second); - if (rc < 0) throw MapWriteException(name); - - // - rc = xmlTextWriterEndElement(writer); - if (rc < 0) throw MapWriteException(name); - for (auto mapPair : maps) { Map& map = *mapPair.second; @@ -318,16 +266,33 @@ void World::save(std::string name, wxTreeCtrl* mapTree) if (rc < 0) throw MapWriteException(name); // id= - std::ostringstream id_out; - id_out << map.getID(); - rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "id", (xmlChar*) id_out.str().c_str()); + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "id", "%d", map.getID()); if (rc < 0) throw MapWriteException(name); - // - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "name", (xmlChar*) map.getTitle().c_str()); + // expanded= + wxTreeItemId node = map.getTreeItemId(); + if (mapTree->IsExpanded(node)) + { + rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "expanded", (xmlChar*) "true"); + if (rc < 0) throw MapWriteException(name); + } else { + rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "expanded", (xmlChar*) "false"); + if (rc < 0) throw MapWriteException(name); + } + + // title= + rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "name", (xmlChar*) map.getTitle().c_str()); if (rc < 0) throw MapWriteException(name); - // + // std::ostringstream mapdata_out; for (int y=0; y - rc = xmlTextWriterStartElement(writer, (xmlChar*) "leftmap"); - if (rc < 0) throw MapWriteException(name); - // type= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getLeftMoveType()).c_str()); - if (rc < 0) throw MapWriteException(name); - - if (Map::moveTypeTakesMap(map.getLeftMoveType())) - { - // map= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getLeftMoveMapID()); - if (rc < 0) throw MapWriteException(name); - } - - // + // rc = xmlTextWriterEndElement(writer); if (rc < 0) throw MapWriteException(name); - // - rc = xmlTextWriterStartElement(writer, (xmlChar*) "rightmap"); - if (rc < 0) throw MapWriteException(name); - - // type= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getRightMoveType()).c_str()); - if (rc < 0) throw MapWriteException(name); - - if (Map::moveTypeTakesMap(map.getRightMoveType())) + for (auto object : map.getObjects()) { - // map= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getRightMoveMapID()); + // + rc = xmlTextWriterStartElement(writer, (xmlChar*) "entity"); if (rc < 0) throw MapWriteException(name); - } - - // - rc = xmlTextWriterEndElement(writer); - if (rc < 0) throw MapWriteException(name); - // - rc = xmlTextWriterStartElement(writer, (xmlChar*) "upmap"); - if (rc < 0) throw MapWriteException(name); - - // type= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getUpMoveType()).c_str()); - if (rc < 0) throw MapWriteException(name); - - if (Map::moveTypeTakesMap(map.getUpMoveType())) - { - // map= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getUpMoveMapID()); + // type= + rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "type", (xmlChar*) object->object->getType().c_str()); if (rc < 0) throw MapWriteException(name); - } - - // - rc = xmlTextWriterEndElement(writer); - if (rc < 0) throw MapWriteException(name); - // - rc = xmlTextWriterStartElement(writer, (xmlChar*) "downmap"); - if (rc < 0) throw MapWriteException(name); - - // type= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getDownMoveType()).c_str()); - if (rc < 0) throw MapWriteException(name); + // x= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "x", "%d", object->position.first); + if (rc < 0) throw MapWriteException(name); + + // y= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "y", "%d", object->position.second); + if (rc < 0) throw MapWriteException(name); - if (Map::moveTypeTakesMap(map.getDownMoveType())) - { - // map= - rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getDownMoveMapID()); + // + rc = xmlTextWriterEndElement(writer); if (rc < 0) throw MapWriteException(name); } - // - rc = xmlTextWriterEndElement(writer); - if (rc < 0) throw MapWriteException(name); - - // - rc = xmlTextWriterStartElement(writer, (xmlChar*) "entities"); - if (rc < 0) throw MapWriteException(name); - - for (auto object : map.getObjects()) + for (auto adjacent : map.getAdjacents()) { - // - rc = xmlTextWriterStartElement(writer, (xmlChar*) "entity"); + // + rc = xmlTextWriterStartElement(writer, (xmlChar*) "adjacent"); if (rc < 0) throw MapWriteException(name); - - // - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-type", (xmlChar*) object->object->getType().c_str()); + + // dir= + rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "dir", (xmlChar*) Map::shortForMoveDir(adjacent.first).c_str()); if (rc < 0) throw MapWriteException(name); - - // - std::ostringstream entpos_out; - entpos_out << object->position.first << "," << object->position.second; - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-position", (xmlChar*) entpos_out.str().c_str()); + + // type= + rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "type", (xmlChar*) Map::shortForMoveType(adjacent.second.type).c_str()); if (rc < 0) throw MapWriteException(name); - - // + + // map= + if (Map::moveTypeTakesMap(adjacent.second.type)) + { + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", adjacent.second.map); + if (rc < 0) throw MapWriteException(name); + } + + // rc = xmlTextWriterEndElement(writer); if (rc < 0) throw MapWriteException(name); } - - // - rc = xmlTextWriterEndElement(writer); - if (rc < 0) throw MapWriteException(name); - wxTreeItemId node = map.getTreeItemId(); if (mapTree->ItemHasChildren(node)) { wxTreeItemIdValue cookie2; @@ -455,16 +367,7 @@ void World::save(std::string name, wxTreeCtrl* mapTree) { // MapPtrCtr* ctl = (MapPtrCtr*) mapTree->GetItemData(it); - std::ostringstream childid_out; - childid_out << ctl->map->getID(); - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "child", (xmlChar*) childid_out.str().c_str()); - if (rc < 0) throw MapWriteException(name); - } - - if (mapTree->IsExpanded(node)) - { - // - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "expanded", (xmlChar*) "1"); + rc = xmlTextWriterWriteFormatElement(writer, (xmlChar*) "child", "%d", ctl->map->getID()); if (rc < 0) throw MapWriteException(name); } } -- cgit 1.4.1