From 2bed7e6cbf5abd1b9d6d35863e3b045d6a3597cb Mon Sep 17 00:00:00 2001 From: annika <annika.oesterdiekhoff@uni-bielefeld.de> Date: Thu, 15 Feb 2024 12:05:07 +0100 Subject: [PATCH] fix switching multiple times in one frame --- .../gui_2d_vis/overcooked_gui.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/overcooked_simulator/gui_2d_vis/overcooked_gui.py b/overcooked_simulator/gui_2d_vis/overcooked_gui.py index ecf7a54a..796e94e4 100644 --- a/overcooked_simulator/gui_2d_vis/overcooked_gui.py +++ b/overcooked_simulator/gui_2d_vis/overcooked_gui.py @@ -348,20 +348,19 @@ class PyGameGUI: self.send_action(action) # interact = Button X <-> 2 - if event.button == 2: - if event.type == pygame.JOYBUTTONDOWN: - action = Action( - current_player_name, ActionType.INTERACT, InterActionData.START - ) - self.send_action(action) + if joysticks[key_set.joystick].get_button(2) and event.type == pygame.JOYBUTTONDOWN: + action = Action( + current_player_name, ActionType.INTERACT, InterActionData.START + ) + self.send_action(action) # stop interaction if last pressed button was X <-> 2 - elif event.type == pygame.JOYBUTTONUP: - action = Action( - current_player_name, ActionType.INTERACT, InterActionData.STOP - ) - self.send_action(action) + if event.button == 2 and event.type == pygame.JOYBUTTONUP: + action = Action( + current_player_name, ActionType.INTERACT, InterActionData.STOP + ) + self.send_action(action) # switch button Y <-> 3 - if event.button == 3 and not CONNECT_WITH_STUDY_SERVER: + if joysticks[key_set.joystick].get_button(3) and not CONNECT_WITH_STUDY_SERVER: if event.type == pygame.JOYBUTTONDOWN: key_set.next_player() -- GitLab