From d9912cacad5ec6e9f9430124aaf1e4b9a8eb5f87 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 11 Dec 2020 18:17:59 +0100 Subject: [PATCH] Listen to mouse clicks in the main loop --- squirrelbattle/enums.py | 6 ++---- squirrelbattle/game.py | 13 ++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/squirrelbattle/enums.py b/squirrelbattle/enums.py index 5784568..11f5c17 100644 --- a/squirrelbattle/enums.py +++ b/squirrelbattle/enums.py @@ -50,10 +50,8 @@ class KeyValues(Enum): """ Translate the raw string key into an enum value that we can use. """ - if key == "KEY_MOUSE": - return KeyValues.MOUSE - elif key in (settings.KEY_DOWN_SECONDARY, - settings.KEY_DOWN_PRIMARY): + if key in (settings.KEY_DOWN_SECONDARY, + settings.KEY_DOWN_PRIMARY): return KeyValues.DOWN elif key in (settings.KEY_LEFT_PRIMARY, settings.KEY_LEFT_SECONDARY): diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index 0758e19..a37f1d2 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -68,8 +68,12 @@ class Game: screen.refresh() self.display_actions(DisplayActions.REFRESH) key = screen.getkey() - self.handle_key_pressed( - KeyValues.translate_key(key, self.settings), key) + if key == "KEY_MOUSE": + _ignored1, x, y, _ignored2, _ignored3 = curses.getmouse() + self.display_actions(DisplayActions.MOUSE, y, x) + else: + self.handle_key_pressed( + KeyValues.translate_key(key, self.settings), key) def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str = '')\ -> None: @@ -82,11 +86,6 @@ class Game: self.display_actions(DisplayActions.REFRESH) return - if key == KeyValues.MOUSE: - _ignored1, x, y, _ignored2, _ignored3 = curses.getmouse() - self.display_actions(DisplayActions.MOUSE, y, x) - return - if self.state == GameMode.PLAY: self.handle_key_pressed_play(key) elif self.state == GameMode.INVENTORY: