Skip to content

Commit

Permalink
Merge pull request #144 from ChrisNeedham24/MCR-141
Browse files Browse the repository at this point in the history
MCR-141 Resolved issue involving jumping to idle settlements while a unit was selected.
  • Loading branch information
ChrisNeedham24 authored Nov 4, 2023
2 parents 9023cca + 8b92c4f commit fa1f256
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/game_management/game_input_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ def on_key_j(game_state: GameState):
# Pressing the J key will jump to an idle settlement, if such a settlement exists.
idle_settlements = [setl for setl in game_state.players[0].settlements if setl.current_work is None]
if idle_settlements:
if game_state.board.overlay.is_unit():
game_state.board.selected_unit = None
game_state.board.overlay.toggle_unit(None)
if game_state.board.selected_settlement is None:
game_state.board.selected_settlement = idle_settlements[0]
game_state.board.overlay.toggle_settlement(game_state.board.selected_settlement, game_state.players[0])
Expand Down
7 changes: 7 additions & 0 deletions source/tests/test_game_input_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,10 +1437,17 @@ def test_j(self):
self.game_state.game_started = True
self.game_state.board.overlay.toggle_settlement = MagicMock()
self.game_state.board.overlay.update_settlement = MagicMock()
self.game_state.board.overlay.toggle_unit = MagicMock()
# Slightly change the order of the settlements to make this test's demonstration simpler.
self.TEST_PLAYER.settlements = [self.TEST_SETTLEMENT, self.TEST_SETTLEMENT_WITH_WORK, self.TEST_SETTLEMENT_2]
# Set up a situation where the player has one of their units selected.
self.game_state.board.overlay.showing = [OverlayType.UNIT]
self.game_state.board.selected_unit = self.TEST_UNIT

on_key_j(self.game_state)
# We firstly expect the selected unit to now be deselected, and the unit overlay removed.
self.assertIsNone(self.game_state.board.selected_unit)
self.game_state.board.overlay.toggle_unit.assert_called_with(None)
# Having not had any settlement selected beforehand, after the first press, the first settlement should be
# selected and centred, with its overlay displayed.
self.assertEqual(self.TEST_SETTLEMENT, self.game_state.board.selected_settlement)
Expand Down

0 comments on commit fa1f256

Please sign in to comment.