From a4fe5a075875f928035bb85caaab07f056beeb00 Mon Sep 17 00:00:00 2001
From: annika <annika.oesterdiekhoff@uni-bielefeld.de>
Date: Thu, 15 Feb 2024 11:40:43 +0100
Subject: [PATCH] fix interaction error

---
 .../gui_2d_vis/overcooked_gui.py              | 20 +++++++++----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/overcooked_simulator/gui_2d_vis/overcooked_gui.py b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
index 7e280cf0..cacc5fe4 100644
--- a/overcooked_simulator/gui_2d_vis/overcooked_gui.py
+++ b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
@@ -258,7 +258,6 @@ class PyGameGUI:
                 if np.linalg.norm(move_vec) != 0:
                     move_vec = move_vec / np.linalg.norm(move_vec)
 
-                print("move vector keys", move_vec)
                 action = Action(
                     current_player_name,
                     ActionType.MOVEMENT,
@@ -276,6 +275,7 @@ class PyGameGUI:
         # Axis 1: joy stick left: -1 = up, ~0 = center, 1 = down
         # see control stuff here (at the end of the page): https://www.pygame.org/docs/ref/joystick.html
         for key_set in self.key_sets:
+            current_player_name = str(key_set.current_player)
             # if a joystick is connected for current player
             if joysticks[key_set.joystick]:
                 # Usually axis run in pairs, up/down for one, and left/right for the other. Triggers count as axes.
@@ -297,9 +297,8 @@ class PyGameGUI:
                     if np.linalg.norm(move_vec) != 0:
                         move_vec = move_vec / np.linalg.norm(move_vec)
 
-                    print("move_vec", move_vec)
                     action = Action(
-                        str(key_set.joystick), ActionType.MOVEMENT, move_vec, duration=1 / self.FPS
+                        current_player_name, ActionType.MOVEMENT, move_vec, duration=1 / self.FPS
                     )
                     self.send_action(action)
 
@@ -344,26 +343,25 @@ class PyGameGUI:
         """
 
         for key_set in self.key_sets:
+            current_player_name = str(key_set.current_player)
             # if a joystick is connected for current player
             if joysticks[key_set.joystick]:
                 # pickup = Button A <-> 0
-                if joysticks[key_set.joystick].get_button(0):
-                    action = Action(str(key_set.joystick), ActionType.PUT, "pickup")
+                if joysticks[key_set.joystick].get_button(0) and event.type == pygame.JOYBUTTONDOWN:
+                    action = Action(current_player_name, ActionType.PUT, "pickup")
                     self.send_action(action)
 
-                # FIXME: when clicking X without cutboard and then A to lay it on the cutboard,
-                #  it is automatically cutted when laying down
-                # FIXME: does it work with button up and down?
                 # interact = Button X <-> 2
-                if joysticks[key_set.joystick].get_button(2):
+                if event.button == 2:
                     if event.type == pygame.JOYBUTTONDOWN:
                         action = Action(
-                            str(key_set.joystick), ActionType.INTERACT, InterActionData.START
+                            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(
-                            str(key_set.joystick), ActionType.INTERACT, InterActionData.STOP
+                            current_player_name, ActionType.INTERACT, InterActionData.STOP
                         )
                         self.send_action(action)
 
-- 
GitLab