From 712f049a5da6a2e245b3fb20ef5696de7d117c1d Mon Sep 17 00:00:00 2001
From: fheinrich <fheinrich@techfak.uni-bielefeld.de>
Date: Mon, 18 Dec 2023 16:27:48 +0100
Subject: [PATCH] Changed viz configs to [0, 1] relative to counter size. Added
 environment config yaml

---
 .../game_content/environment_config.yaml      |  3 +
 overcooked_simulator/main.py                  |  4 +-
 .../overcooked_environment.py                 | 13 ++-
 overcooked_simulator/pygame_gui/pygame_gui.py | 19 ++--
 .../pygame_gui/visualization.yaml             | 90 +++++++++----------
 5 files changed, 72 insertions(+), 57 deletions(-)
 create mode 100644 overcooked_simulator/game_content/environment_config.yaml

diff --git a/overcooked_simulator/game_content/environment_config.yaml b/overcooked_simulator/game_content/environment_config.yaml
new file mode 100644
index 00000000..e70b00e2
--- /dev/null
+++ b/overcooked_simulator/game_content/environment_config.yaml
@@ -0,0 +1,3 @@
+kitchen:
+  layout_path: layouts/basic.layout
+  counter_side_length: 40
\ No newline at end of file
diff --git a/overcooked_simulator/main.py b/overcooked_simulator/main.py
index 6b1de7e3..df0ac19b 100644
--- a/overcooked_simulator/main.py
+++ b/overcooked_simulator/main.py
@@ -9,10 +9,10 @@ from overcooked_simulator.simulation_runner import Simulator
 
 
 def main():
-    simulator = Simulator(ROOT_DIR / "game_content" / "layouts" / "basic.layout", 600)
+    simulator = Simulator(ROOT_DIR / "game_content" / "environment_config.yaml", 600)
     # simulator.register_player(Player(player_one_name, np.array([350.0, 200.0])))
     # simulator.register_player(Player(player_two_name, np.array([100.0, 200.0])))
-    number_player = 2
+    number_player = 20
     for i in range(number_player):
         simulator.register_player(Player(f"p{i}"))
 
diff --git a/overcooked_simulator/overcooked_environment.py b/overcooked_simulator/overcooked_environment.py
index 0d4702f2..b3602c33 100644
--- a/overcooked_simulator/overcooked_environment.py
+++ b/overcooked_simulator/overcooked_environment.py
@@ -22,6 +22,7 @@ from overcooked_simulator.counters import (
     ServingWindow,
     Stove,
 )
+from overcooked_simulator import ROOT_DIR
 
 
 class GameScore:
@@ -60,10 +61,16 @@ class Environment:
     # TODO Abstract base class for different environments
     """
 
-    def __init__(self, layout_path, item_info_path):
+    def __init__(self, env_config_path: Path, item_info_path: Path):
         self.players: dict[str, Player] = {}
-        self.counter_side_length: int = 40
-        self.layout_path: Path = layout_path
+
+        with open(env_config_path, "r") as file:
+            environment_config = yaml.safe_load(file)
+        self.layout_path: Path = Path(
+            ROOT_DIR / "game_content" / environment_config["kitchen"]["layout_path"]
+        )
+        self.counter_side_length = environment_config["kitchen"]["counter_side_length"]
+
         self.item_info_path: Path = item_info_path
         self.item_info = self.load_item_info()
 
diff --git a/overcooked_simulator/pygame_gui/pygame_gui.py b/overcooked_simulator/pygame_gui/pygame_gui.py
index 0ebc909a..df6c622e 100644
--- a/overcooked_simulator/pygame_gui/pygame_gui.py
+++ b/overcooked_simulator/pygame_gui/pygame_gui.py
@@ -213,7 +213,7 @@ class PyGameGUI:
         for p_idx, player in enumerate(state["players"].values()):
             if USE_PLAYER_COOK_SPRITES:
                 pos = player.pos
-                size = player.radius
+                size = player.radius * self.counter_size
                 color1 = self.player_colors[p_idx]
                 color2 = colors["white"]
 
@@ -236,7 +236,10 @@ class PyGameGUI:
                 img_path = self.visualization_config["Cook"]["parts"][0]["path"]
                 rel_x, rel_y = player.facing_direction
                 angle = -np.rad2deg(math.atan2(rel_y, rel_x)) + 90
-                size = self.visualization_config["Cook"]["parts"][0]["size"]
+                size = (
+                    self.visualization_config["Cook"]["parts"][0]["size"]
+                    * self.counter_size
+                )
                 self.draw_image(img_path, size, player.pos, angle)
 
             if SHOW_INTERACTION_RANGE:
@@ -261,13 +264,15 @@ class PyGameGUI:
         for part in parts:
             part_type = part["type"]
             if part_type == "image":
-                self.draw_image(parts[0]["path"], parts[0]["size"] * scale, pos)
+                self.draw_image(
+                    parts[0]["path"], parts[0]["size"] * scale * self.counter_size, pos
+                )
             elif part_type == "rect":
-                height = part["height"]
-                width = part["width"]
+                height = part["height"] * self.counter_size
+                width = part["width"] * self.counter_size
                 color = part["color"]
                 if "center_offset" in part:
-                    dx, dy = part["center_offset"]
+                    dx, dy = np.array(part["center_offset"]) * self.counter_size
                     rect = pygame.Rect(pos[0] + dx, pos[1] + dy, height, width)
                     pygame.draw.rect(self.screen, color, rect)
                 else:
@@ -279,7 +284,7 @@ class PyGameGUI:
                     )
                 pygame.draw.rect(self.screen, color, rect)
             elif part_type == "circle":
-                radius = part["radius"]
+                radius = part["radius"] * self.counter_size
                 color = colors[part["color"]]
                 if "center_offset" in part:
                     pygame.draw.circle(
diff --git a/overcooked_simulator/pygame_gui/visualization.yaml b/overcooked_simulator/pygame_gui/visualization.yaml
index db40a373..df6f702c 100644
--- a/overcooked_simulator/pygame_gui/visualization.yaml
+++ b/overcooked_simulator/pygame_gui/visualization.yaml
@@ -5,124 +5,124 @@ Kitchen:
 Counter:
   parts:
     - type: rect
-      height: 40
-      width: 40
+      height: 1
+      width: 1
       color: whitesmoke
 
 CuttingBoard:
   parts:
     - type: rect
-      height: 30
-      width: 30
+      height: 0.75
+      width: 0.75
       color: burlywood1
     - type: rect
-      height: 5
-      width: 20
-      center_offset: [ +6, -8 ]
+      height: 0.125
+      width: 0.5
+      center_offset: [ +0.15, -0.2 ]
       color: silver
 
 PlateDispenser:
   parts:
     - type: rect
-      height: 38
-      width: 38
+      height: 0.95
+      width: 0.95
       color: cadetblue1
 
 Trash:
   parts:
     - type: circle
-      radius: 16
+      radius: 0.4
       color: black
     - type: circle
-      radius: 15
+      radius: 0.375
       color: gray33
 
 TomatoDispenser:
   parts:
     - color: orangered1
       type: rect
-      height: 32
-      width: 32
+      height: 0.8
+      width: 0.8
 
 LettuceDispenser:
   parts:
     - color: palegreen3
       type: rect
-      height: 32
-      width: 32
+      height: 0.8
+      width: 0.8
 
 OnionDispenser:
   parts:
     - color: palegreen3
       type: rect
-      height: 32
-      width: 32
+      height: 0.8
+      width: 0.8
 
 
 ServingWindow:
   parts:
     - color: darkgoldenrod1
       type: rect
-      height: 33
-      width: 33
+      height: 0.85
+      width: 0.85
 
 Stove:
   parts:
     - color: black
       type: rect
-      height: 35
-      width: 25
+      height: 0.875
+      width: 0.625
     - color: flesh
       type: circle
-      radius: 10
+      radius: 0.25
 
 # Items
 Tomato:
   parts:
     - type: image
       path: images/tomato.png
-      size: 40
+      size: 1
 
 Onion:
   parts:
     - type: circle
-      radius: 12
+      radius: 0.3
       color: black
     - type: circle
-      radius: 10
+      radius: 0.25
       color: deeppink4
 
 Lettuce:
   parts:
     - type: circle
-      radius: 12
+      radius: 0.3
       color: black
     - type: circle
-      radius: 10
+      radius: 0.25
       color: emeraldgreen
 
 ChoppedLettuce:
   parts:
     - type: circle
-      radius: 12
+      radius: 0.3
       color: black
       center_offset: [ -5, 0 ]
     - type: circle
-      radius: 10
+      radius: 0.25
       color: emeraldgreen
       center_offset: [ -5, 0 ]
     - type: circle
-      radius: 12
+      radius: 0.3
       color: black
     - type: circle
-      radius: 10
+      radius: 0.25
       color: emeraldgreen
     - type: circle
-      radius: 12
+      radius: 0.3
       color: black
       center_offset: [ 5, 0 ]
     - type: circle
-      radius: 10
+      radius: 0.25
       color: emeraldgreen
       center_offset: [ 5, 0 ]
 
@@ -130,30 +130,30 @@ ChoppedTomato:
   parts:
     - type: image
       path: images/tomato_cut.png
-      size: 40
+      size: 1
 
 ChoppedOnion:
   parts:
     - type: circle
-      radius: 12
+      radius: 0.3
       color: black
       center_offset: [ -5, 0 ]
     - type: circle
-      radius: 10
+      radius: 0.25
       color: deeppink4
       center_offset: [ -5, 0 ]
     - type: circle
-      radius: 12
+      radius: 0.3
       color: black
     - type: circle
-      radius: 10
+      radius: 0.25
       color: deeppink4
     - type: circle
-      radius: 12
+      radius: 0.3
       color: black
       center_offset: [ 5, 0 ]
     - type: circle
-      radius: 10
+      radius: 0.25
       color: deeppink4
       center_offset: [ 5, 0 ]
 
@@ -161,28 +161,28 @@ TomatoSoup:
   parts:
     - type: image
       path: images/tomato_soup.png
-      size: 24
+      size: 0.6
 
 OnionSoup:
   parts:
     - type: image
       path: images/tomato_soup.png
-      size: 24
+      size: 0.6
 
 Cook:
   parts:
     - type: image
       path: images/pixel_cook.png
-      size: 40
+      size: 1
 
 Plate:
   parts:
     - type: image
       path: images/plate.png
-      size: 40
+      size: 1
 
 Pot:
   parts:
     - type: image
       path: images/pot.png
-      size: 32
+      size: 0.8
-- 
GitLab