From bf06622cc735f4852003192d6d73fbd2ecfcbe98 Mon Sep 17 00:00:00 2001
From: fheinrich <fheinrich@techfak.uni-bielefeld.de>
Date: Thu, 1 Feb 2024 11:46:09 +0100
Subject: [PATCH] Changed viz of Dispensers

---
 overcooked_simulator/gui_2d_vis/drawing.py    | 80 +++++++++++--------
 .../gui_2d_vis/visualization.yaml             | 19 +++--
 2 files changed, 58 insertions(+), 41 deletions(-)

diff --git a/overcooked_simulator/gui_2d_vis/drawing.py b/overcooked_simulator/gui_2d_vis/drawing.py
index c8a14b92..f136ef80 100644
--- a/overcooked_simulator/gui_2d_vis/drawing.py
+++ b/overcooked_simulator/gui_2d_vis/drawing.py
@@ -242,58 +242,62 @@ class Visualizer:
         """
         for part in parts:
             part_type = part["type"]
+            angle, angle_offset = 0, 0
+
+            draw_pos = pos.copy()
+
+            if orientation is not None:
+                angle_offset = calc_angle(orientation, [0, 1])
+                if "rotate_image" in part.keys():
+                    if part["rotate_image"]:
+                        angle = calc_angle(orientation, [0, 1])
+                else:
+                    angle = angle_offset
+
             match part_type:
                 case "image":
-                    angle, angle_offset = 0, 0
-                    if orientation is not None:
-                        angle_offset = calc_angle(orientation, [0, 1])
-                        if "rotate_image" in part.keys():
-                            if part["rotate_image"]:
-                                angle = calc_angle(orientation, [0, 1])
-                        else:
-                            angle = angle_offset
                     if "center_offset" in part:
                         d = pygame.math.Vector2(part["center_offset"]) * grid_size
                         d.rotate_ip(angle_offset)
-                        pos = np.array(pos)
-                        pos += np.array(d)
-
+                        draw_pos += np.array(d)
                     self.draw_image(
                         screen,
                         part["path"],
                         part["size"] * scale * grid_size,
-                        pos,
+                        draw_pos,
                         rot_angle=angle,
                     )
+
                 case "rect":
+                    if "center_offset" in part:
+                        d = pygame.math.Vector2(part["center_offset"]) * grid_size
+                        d.rotate_ip(angle_offset)
+                        draw_pos += np.array(d)
                     height = part["height"] * grid_size
                     width = part["width"] * grid_size
                     color = part["color"]
-                    if "center_offset" in part:
-                        dx, dy = np.array(part["center_offset"]) * grid_size
-                        rect = pygame.Rect(pos[0] + dx, pos[1] + dy, height, width)
-                        pygame.draw.rect(screen, color, rect)
-                    else:
-                        rect = pygame.Rect(
-                            pos[0] - (height / 2),
-                            pos[1] - (width / 2),
-                            height,
-                            width,
-                        )
+                    rect = pygame.Rect(
+                        draw_pos[0] - (height / 2),
+                        draw_pos[1] - (width / 2),
+                        height,
+                        width,
+                    )
                     pygame.draw.rect(screen, color, rect)
+
                 case "circle":
+                    if "center_offset" in part:
+                        d = pygame.math.Vector2(part["center_offset"]) * grid_size
+                        d.rotate_ip(-angle_offset)
+                        draw_pos += np.array(d)
                     radius = part["radius"] * grid_size
                     color = colors[part["color"]]
-                    if "center_offset" in part:
-                        pygame.draw.circle(
-                            screen,
-                            color,
-                            np.array(pos)
-                            + (np.array(part["center_offset"]) * grid_size),
-                            radius,
-                        )
-                    else:
-                        pygame.draw.circle(screen, color, pos, radius)
+
+                    pygame.draw.circle(
+                        screen,
+                        color,
+                        draw_pos,
+                        radius,
+                    )
 
     def draw_item(
         self,
@@ -329,7 +333,7 @@ class Visualizer:
                     screen=screen,
                     grid_size=grid_size,
                 )
-                #
+
         if "progress_percentage" in item and item["progress_percentage"] > 0.0:
             self.draw_progress_bar(
                 screen, pos, item["progress_percentage"], grid_size=grid_size
@@ -414,6 +418,7 @@ class Visualizer:
                 pos=pos,
                 parts=parts,
                 grid_size=grid_size,
+                orientation=counter_dict["orientation"],
             )
 
     def draw_counter_occupier(
@@ -422,6 +427,7 @@ class Visualizer:
         occupied_by: dict | list,
         grid_size,
         pos: npt.NDArray[float],
+        item_scale: float,
     ):
         # Multiple plates on plate return:
         if isinstance(occupied_by, list):
@@ -431,6 +437,7 @@ class Visualizer:
                     pos=np.abs([pos[0], pos[1] - (i * 3)]),
                     grid_size=grid_size,
                     item=o,
+                    scale=item_scale,
                 )
         # All other items:
         else:
@@ -439,6 +446,7 @@ class Visualizer:
                 grid_size=grid_size,
                 item=occupied_by,
                 screen=screen,
+                scale=item_scale,
             )
 
     def draw_counters(self, screen: pygame, state, grid_size):
@@ -452,6 +460,7 @@ class Visualizer:
         for counter in state["counters"]:
             if counter["occupied_by"]:
                 item_pos = counter["pos"]
+                item_scale = 1.0
 
                 counter_type = counter["type"]
                 if counter_type.endswith("Dispenser"):
@@ -466,12 +475,15 @@ class Visualizer:
                             + 180
                         )
                         item_pos += offset_vec
+                    if "item_scale" in self.config["Dispenser"].keys():
+                        item_scale = self.config["Dispenser"]["item_scale"]
 
                 self.draw_counter_occupier(
                     screen,
                     counter["occupied_by"],
                     grid_size,
                     np.array(item_pos) * grid_size,
+                    item_scale,
                 )
 
             if SHOW_COUNTER_CENTERS:
diff --git a/overcooked_simulator/gui_2d_vis/visualization.yaml b/overcooked_simulator/gui_2d_vis/visualization.yaml
index 3ef2f3a3..a4fea62b 100644
--- a/overcooked_simulator/gui_2d_vis/visualization.yaml
+++ b/overcooked_simulator/gui_2d_vis/visualization.yaml
@@ -88,13 +88,18 @@ Trashcan:
 #      width: 0.8
 
 Dispenser:
-  parts: [ ]
-  #    - color: gray83
-  #      type: rect
-  #      height: 0.8
-  #      width: 0.8
-  item_offset: [ 0, -0.15 ]
+  parts:
+    - type: circle
+      color: gray83
+      radius: 0.3
+      center_offset: [ 0, -0.15 ]
+    - type: circle
+      color: black
+      radius: 0.25
+      center_offset: [ 0, -0.15 ]
 
+  item_offset: [ 0, -0.15 ]
+  item_scale: 0.75
 
 ServingWindow:
   parts:
@@ -282,7 +287,7 @@ Oven:
       color: black
       height: 0.8
       width: 0.3
-      center_offset: [ -0.4, -0.1 ]
+      center_offset: [ 0, -0.1 ]
 
 Basket:
   parts:
-- 
GitLab