Skip to content

Commit

Permalink
fix: go to house with no exit (#92)
Browse files Browse the repository at this point in the history
Now when you double click a house with no exit, it will take you to the first valid tile.
Makes easier to fix the warning about houses with no exit.
  • Loading branch information
phacUFPE authored Aug 10, 2024
1 parent 78686d7 commit 56c7efb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions source/house.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class House {
uint8_t getEmptyDoorID() const;
Position getDoorPositionByID(uint8_t id) const;

const PositionList &getTiles() const {
return tiles;
}

protected:
Map* map;
PositionList tiles;
Expand Down
18 changes: 14 additions & 4 deletions source/palette_house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,20 @@ void HousePalettePanel::OnListBoxChange(wxCommandEvent &event) {
}

void HousePalettePanel::OnListBoxDoubleClick(wxCommandEvent &event) {
House* house = reinterpret_cast<House*>(event.GetClientData());
// I find it extremly unlikely that one actually wants the exit at 0,0,0, so just treat it as the null value
if (house && house->getExit() != Position(0, 0, 0)) {
g_gui.SetScreenCenterPosition(house->getExit());
if (const auto house = reinterpret_cast<House*>(event.GetClientData())) {
const Position &position = house->getExit();
if (position.isValid()) {
g_gui.SetScreenCenterPosition(position);
return;
}

// find a valid tile position
for (const Position &tilePosition : house->getTiles()) {
if (tilePosition.isValid()) {
g_gui.SetScreenCenterPosition(tilePosition);
break;
}
}
}
}

Expand Down

0 comments on commit 56c7efb

Please sign in to comment.