From 56c7efb159c0c43bab8f633bf1b14c4344dcea8d Mon Sep 17 00:00:00 2001 From: Pedro Cruz Date: Sat, 10 Aug 2024 15:08:09 -0300 Subject: [PATCH] fix: go to house with no exit (#92) 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. --- source/house.h | 4 ++++ source/palette_house.cpp | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/source/house.h b/source/house.h index 35664aec..027602eb 100644 --- a/source/house.h +++ b/source/house.h @@ -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; diff --git a/source/palette_house.cpp b/source/palette_house.cpp index 7eb5df85..28012d59 100644 --- a/source/palette_house.cpp +++ b/source/palette_house.cpp @@ -322,10 +322,20 @@ void HousePalettePanel::OnListBoxChange(wxCommandEvent &event) { } void HousePalettePanel::OnListBoxDoubleClick(wxCommandEvent &event) { - House* house = reinterpret_cast(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(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; + } + } } }