Skip to content
Snippets Groups Projects
Commit 3ed77f32 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Visualizing meals

parent 3ba507ea
No related branches found
No related tags found
1 merge request!1340-visualisierungsregeln
...@@ -11,9 +11,7 @@ import numpy.typing as npt ...@@ -11,9 +11,7 @@ import numpy.typing as npt
from overcooked_simulator.game_items import ( from overcooked_simulator.game_items import (
CuttableItem, CuttableItem,
Item, Item,
ProgressibleItem,
Plate, Plate,
Tomato,
Pot, Pot,
CookingEquipment, CookingEquipment,
Soup, Soup,
...@@ -129,9 +127,12 @@ class ServingWindow(Counter): ...@@ -129,9 +127,12 @@ class ServingWindow(Counter):
return None return None
def can_score(self, item): def can_score(self, item):
if isinstance(item, Plate): if isinstance(item, Plate) and item.holds is not None:
if isinstance(item.holds, Soup): if isinstance(item.holds, Soup):
return item.holds.finished return item.holds.finished
elif item.holds.name == "Salad":
return True
return False
def can_drop_off(self, item: Item) -> bool: def can_drop_off(self, item: Item) -> bool:
return self.can_score(item) return self.can_score(item)
...@@ -189,13 +190,21 @@ class PlateReturn(Counter): ...@@ -189,13 +190,21 @@ class PlateReturn(Counter):
class Dispenser(Counter): class Dispenser(Counter):
def __init__(self, pos, dispensing): def __init__(self, pos, dispensing):
self.dispensing = 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): def pick_up(self, on_hands: bool = True):
return CuttableItem( returned = CuttableItem(
name=self.dispensing, name=self.dispensing,
finished_name=item_loopkup[self.dispensing]["finished_name"], finished_name=item_loopkup[self.dispensing]["finished_name"],
) )
print(self.occupied_by)
return returned
def drop_off(self, item: Item) -> Item | None: def drop_off(self, item: Item) -> Item | None:
return None return None
......
...@@ -11,10 +11,10 @@ from overcooked_simulator.simulation_runner import Simulator ...@@ -11,10 +11,10 @@ from overcooked_simulator.simulation_runner import Simulator
def main(): 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_one_name = "p1"
player_two_name = "p2" 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]))) 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? # TODO maybe read the player names and keyboard keys from config file?
......
...@@ -12,7 +12,7 @@ from overcooked_simulator.counters import ( ...@@ -12,7 +12,7 @@ from overcooked_simulator.counters import (
Counter, Counter,
CuttingBoard, CuttingBoard,
Trash, Trash,
TomatoDispenser, Dispenser,
ServingWindow, ServingWindow,
PlateReturn, PlateReturn,
Stove, Stove,
...@@ -66,7 +66,8 @@ class Environment: ...@@ -66,7 +66,8 @@ class Environment:
"B": CuttingBoard, "B": CuttingBoard,
"X": Trash, "X": Trash,
"W": lambda pos: ServingWindow(pos, self.game_score), "W": lambda pos: ServingWindow(pos, self.game_score),
"T": TomatoDispenser, "T": lambda pos: Dispenser(pos, "Tomato"),
"L": lambda pos: Dispenser(pos, "Lettuce"),
"P": PlateReturn, "P": PlateReturn,
"E": None, "E": None,
"U": Stove, # Stove with pot: U because it looks like a pot "U": Stove, # Stove with pot: U because it looks like a pot
......
...@@ -12,6 +12,7 @@ from overcooked_simulator.game_items import ( ...@@ -12,6 +12,7 @@ from overcooked_simulator.game_items import (
Item, Item,
CookingEquipment, CookingEquipment,
Meal, Meal,
Soup,
) )
from overcooked_simulator.overcooked_environment import Action from overcooked_simulator.overcooked_environment import Action
from overcooked_simulator.simulation_runner import Simulator from overcooked_simulator.simulation_runner import Simulator
...@@ -258,12 +259,8 @@ class PyGameGUI: ...@@ -258,12 +259,8 @@ class PyGameGUI:
if isinstance(item, CookingEquipment) and item.content: if isinstance(item, CookingEquipment) and item.content:
self.draw_item(pos, item.content) self.draw_item(pos, item.content)
if isinstance(item, Meal) and item.parts: if isinstance(item, Soup) and item.parts:
if ( if item.parts:
isinstance(item, Meal)
and isinstance(item, ProgressibleItem)
and item.parts
):
if not item.finished: if not item.finished:
match len(item.parts): match len(item.parts):
case 1: case 1:
...@@ -287,6 +284,10 @@ class PyGameGUI: ...@@ -287,6 +284,10 @@ class PyGameGUI:
rect.center = pos rect.center = pos
self.screen.blit(image, rect) 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): def draw_progress_bar(self, pos, current, needed):
"""Visualize progress of progressing item as a green bar under the item.""" """Visualize progress of progressing item as a green bar under the item."""
if current != 0: if current != 0:
...@@ -328,11 +329,13 @@ class PyGameGUI: ...@@ -328,11 +329,13 @@ class PyGameGUI:
) )
if counter.occupied_by is not None: if counter.occupied_by is not None:
# Multiple plates on plate return:
if isinstance(counter.occupied_by, list): if isinstance(counter.occupied_by, list):
for i, o in enumerate(counter.occupied_by): for i, o in enumerate(counter.occupied_by):
self.draw_item( self.draw_item(
np.abs([counter.pos[0], counter.pos[1] - (i * 3)]), o np.abs([counter.pos[0], counter.pos[1] - (i * 3)]), o
) )
# All other items:
else: else:
self.draw_item(counter.pos, counter.occupied_by) self.draw_item(counter.pos, counter.occupied_by)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment