From 3ed77f3201616abc305b54da45672119d4e2d09b Mon Sep 17 00:00:00 2001 From: fheinrich <fheinrich@techfak.uni-bielefeld.de> Date: Thu, 14 Dec 2023 13:27:38 +0100 Subject: [PATCH] Visualizing meals --- overcooked_simulator/counters.py | 19 ++++++++++++++----- .../{ => game_content}/layouts/empty.layout | 0 overcooked_simulator/main.py | 4 ++-- .../overcooked_environment.py | 5 +++-- overcooked_simulator/pygame_gui/pygame_gui.py | 15 +++++++++------ 5 files changed, 28 insertions(+), 15 deletions(-) rename overcooked_simulator/{ => game_content}/layouts/empty.layout (100%) diff --git a/overcooked_simulator/counters.py b/overcooked_simulator/counters.py index f39b5260..ed6bab57 100644 --- a/overcooked_simulator/counters.py +++ b/overcooked_simulator/counters.py @@ -11,9 +11,7 @@ import numpy.typing as npt from overcooked_simulator.game_items import ( CuttableItem, Item, - ProgressibleItem, Plate, - Tomato, Pot, CookingEquipment, Soup, @@ -129,9 +127,12 @@ class ServingWindow(Counter): return None def can_score(self, item): - if isinstance(item, Plate): + if isinstance(item, Plate) and item.holds is not None: if isinstance(item.holds, Soup): return item.holds.finished + elif item.holds.name == "Salad": + return True + return False def can_drop_off(self, item: Item) -> bool: return self.can_score(item) @@ -189,13 +190,21 @@ class PlateReturn(Counter): class Dispenser(Counter): def __init__(self, pos, dispensing): self.dispensing = dispensing - super().__init__(pos) + super().__init__( + pos, + CuttableItem( + name=self.dispensing, + finished_name=item_loopkup[self.dispensing]["finished_name"], + ), + ) def pick_up(self, on_hands: bool = True): - return CuttableItem( + returned = CuttableItem( name=self.dispensing, finished_name=item_loopkup[self.dispensing]["finished_name"], ) + print(self.occupied_by) + return returned def drop_off(self, item: Item) -> Item | None: return None diff --git a/overcooked_simulator/layouts/empty.layout b/overcooked_simulator/game_content/layouts/empty.layout similarity index 100% rename from overcooked_simulator/layouts/empty.layout rename to overcooked_simulator/game_content/layouts/empty.layout diff --git a/overcooked_simulator/main.py b/overcooked_simulator/main.py index 2433815d..9524338b 100644 --- a/overcooked_simulator/main.py +++ b/overcooked_simulator/main.py @@ -11,10 +11,10 @@ from overcooked_simulator.simulation_runner import Simulator def main(): - simulator = Simulator(Path(ROOT_DIR, "layouts", "basic.layout"), 600) + simulator = Simulator(Path(ROOT_DIR, "game_content/layouts", "basic.layout"), 600) player_one_name = "p1" player_two_name = "p2" - simulator.register_player(Player(player_one_name, np.array([200.0, 200.0]))) + 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]))) # TODO maybe read the player names and keyboard keys from config file? diff --git a/overcooked_simulator/overcooked_environment.py b/overcooked_simulator/overcooked_environment.py index 8d1650e6..4161e1d4 100644 --- a/overcooked_simulator/overcooked_environment.py +++ b/overcooked_simulator/overcooked_environment.py @@ -12,7 +12,7 @@ from overcooked_simulator.counters import ( Counter, CuttingBoard, Trash, - TomatoDispenser, + Dispenser, ServingWindow, PlateReturn, Stove, @@ -66,7 +66,8 @@ class Environment: "B": CuttingBoard, "X": Trash, "W": lambda pos: ServingWindow(pos, self.game_score), - "T": TomatoDispenser, + "T": lambda pos: Dispenser(pos, "Tomato"), + "L": lambda pos: Dispenser(pos, "Lettuce"), "P": PlateReturn, "E": None, "U": Stove, # Stove with pot: U because it looks like a pot diff --git a/overcooked_simulator/pygame_gui/pygame_gui.py b/overcooked_simulator/pygame_gui/pygame_gui.py index 8c6338fc..8baed366 100644 --- a/overcooked_simulator/pygame_gui/pygame_gui.py +++ b/overcooked_simulator/pygame_gui/pygame_gui.py @@ -12,6 +12,7 @@ from overcooked_simulator.game_items import ( Item, CookingEquipment, Meal, + Soup, ) from overcooked_simulator.overcooked_environment import Action from overcooked_simulator.simulation_runner import Simulator @@ -258,12 +259,8 @@ class PyGameGUI: if isinstance(item, CookingEquipment) and item.content: self.draw_item(pos, item.content) - if isinstance(item, Meal) and item.parts: - if ( - isinstance(item, Meal) - and isinstance(item, ProgressibleItem) - and item.parts - ): + if isinstance(item, Soup) and item.parts: + if item.parts: if not item.finished: match len(item.parts): case 1: @@ -287,6 +284,10 @@ class PyGameGUI: rect.center = pos self.screen.blit(image, rect) + if isinstance(item, Meal) and item.parts and not isinstance(item, Soup): + for i, o in enumerate(item.parts): + self.draw_item(np.abs([pos[0], pos[1] - (i * 5)]), o) + def draw_progress_bar(self, pos, current, needed): """Visualize progress of progressing item as a green bar under the item.""" if current != 0: @@ -328,11 +329,13 @@ class PyGameGUI: ) if counter.occupied_by is not None: + # Multiple plates on plate return: if isinstance(counter.occupied_by, list): for i, o in enumerate(counter.occupied_by): self.draw_item( np.abs([counter.pos[0], counter.pos[1] - (i * 3)]), o ) + # All other items: else: self.draw_item(counter.pos, counter.occupied_by) -- GitLab