Skip to content

Commit

Permalink
Make GetGameInterface() const-correct
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaau committed Dec 16, 2024
1 parent c3195d0 commit 871ac27
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions libs/s25main/GameInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ class GameInterface
virtual void GI_BuildRoad() = 0;

virtual Cheats& GI_GetCheats() = 0;
const Cheats& GI_GetCheats() const { return const_cast<GameInterface&>(*this).GI_GetCheats(); }
};
3 changes: 2 additions & 1 deletion libs/s25main/world/GameWorldBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class GameWorldBase : public World
// Remaining initialization after loading (BQ...)
void InitAfterLoad();

GameInterface* GetGameInterface() const { return gi; }
GameInterface* GetGameInterface() { return gi; }
const GameInterface* GetGameInterface() const { return gi; }
void SetGameInterface(GameInterface* const gi) { this->gi = gi; }

/// Get the economy mode handler if set.
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/world/GameWorldViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ BuildingQuality GameWorldViewer::GetBQ(const MapPoint& pt) const

Visibility GameWorldViewer::GetVisibility(const MapPoint pt) const
{
auto* const gi = GetWorld().GetGameInterface();
const auto* const gi = GetWorld().GetGameInterface();
if(gi && gi->GI_GetCheats().isAllVisible())
return Visibility::Visible;

Expand Down
4 changes: 3 additions & 1 deletion tests/s25Main/integration/testCheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ MOCK_BASE_CLASS(MockGameInterface, GameInterface)
MOCK_METHOD(GI_StartRoadBuilding, 2)
MOCK_METHOD(GI_CancelRoadBuilding, 0)
MOCK_METHOD(GI_BuildRoad, 0)
MOCK_METHOD(GI_GetCheats, 0)
// clang-format off
MOCK_METHOD(GI_GetCheats, 0, Cheats&(void))
// clang-format on
// LCOV_EXCL_STOP
};
} // namespace
Expand Down

0 comments on commit 871ac27

Please sign in to comment.