Skip to content

Commit

Permalink
Merge pull request #74 from strakam/refactors
Browse files Browse the repository at this point in the history
refactor: Add FoV toggle to all modes
  • Loading branch information
strakam authored Oct 3, 2024
2 parents 31b122c + a2afa3b commit 29ea017
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions generals/gui/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ def is_click_on_agents_row(self, x: int, y: int, i: int) -> bool:
and (i + 1) * c.GUI_ROW_HEIGHT <= y < (i + 2) * c.GUI_ROW_HEIGHT
)

def toggle_player_fov(self):
agents = self.properties.game.agents
agent_fov = self.properties.agent_fov

x, y = pygame.mouse.get_pos()
for i, agent in enumerate(agents):
if self.is_click_on_agents_row(x, y, i):
agent_fov[agent] = not agent_fov[agent]
break

@abstractmethod
def handle_key_event(self, event: Event) -> Command:
raise NotImplementedError
Expand Down Expand Up @@ -113,14 +123,7 @@ def handle_mouse_event(self) -> None:
"""
Handle mouse clicks in replay mode.
"""
agents = self.properties.game.agents
agent_fov = self.properties.agent_fov

x, y = pygame.mouse.get_pos()
for i, agent in enumerate(agents):
if self.is_click_on_agents_row(x, y, i):
agent_fov[agent] = not agent_fov[agent]
break
self.toggle_player_fov()


class GameEventHandler(EventHandler):
Expand All @@ -132,7 +135,7 @@ def handle_key_event(self, event: Event) -> GameCommand:
raise NotImplementedError

def handle_mouse_event(self) -> None:
raise NotImplementedError
self.toggle_player_fov()


class TrainEventHandler(EventHandler):
Expand All @@ -146,4 +149,4 @@ def handle_key_event(self, event: Event) -> TrainCommand:
return self.command

def handle_mouse_event(self) -> None:
raise NotImplementedError
self.toggle_player_fov()

0 comments on commit 29ea017

Please sign in to comment.