diff --git a/overcooked_simulator/game_content/item_combinations.yaml b/overcooked_simulator/game_content/item_combinations.yaml new file mode 100644 index 0000000000000000000000000000000000000000..33830b1dbef755c308fb4fb5589d165bc748bc94 --- /dev/null +++ b/overcooked_simulator/game_content/item_combinations.yaml @@ -0,0 +1,23 @@ +Tomato: + type: Cuttable + finished_name: ChoppedTomato + +Lettuce: + type: Cuttable + finished_name: ChoppedLettuce + +RawPatty: + type: Cuttable + needs: RawSteak + +Burger: + type: Meal + needs: [ Bun, CutLettuce, CutTomato, CookedPatty ] + +CookedTomatoSoup: + type: [ Soup, Meal ] + needs: [ CutTomato, CutTomato, CutTomato ] + +Salad: + type: Meal + needs: [ ChoppedLettuce, ChoppedTomato ] diff --git a/overcooked_simulator/pygame_gui/pygame_gui.py b/overcooked_simulator/pygame_gui/pygame_gui.py index 0393c8c3e23cac3d5645ddb32b9bceaca2408071..8c6338fced0a88d25b03f2876769a7e991fad188 100644 --- a/overcooked_simulator/pygame_gui/pygame_gui.py +++ b/overcooked_simulator/pygame_gui/pygame_gui.py @@ -24,7 +24,7 @@ WHITE = (255, 255, 255) BACKGROUND_COLOR = (190, 190, 190) BACKGROUND_LINES_COLOR = (200, 200, 200) -PLAYER_DEBUG_VIZ = True +PLAYER_DEBUG_VIZ = False class PlayerKeySet: @@ -193,6 +193,49 @@ class PyGameGUI: holding_item_pos = player.pos + (20 * player.facing_direction) self.draw_item(holding_item_pos, player.holding) + def draw_thing(self, pos, parts): + for part in parts: + part_type = part["type"] + if part_type == "image": + image = pygame.image.load( + ROOT_DIR / Path("pygame_gui") / parts[0]["path"] + ).convert_alpha() + + size = parts[0]["size"] + image = pygame.transform.scale(image, (size, size)) + + rect = image.get_rect() + rect.center = pos + self.screen.blit(image, rect) + elif part_type == "rect": + height = part["height"] + width = part["width"] + color = part["color"] + if "center_offset" in part: + dx, dy = part["center_offset"] + rect = pygame.Rect(pos[0] + dx, pos[1] + dy, height, width) + pygame.draw.rect(self.screen, color, rect) + else: + rect = pygame.Rect( + pos[0] - (height / 2), + pos[1] - (width / 2), + height, + width, + ) + pygame.draw.rect(self.screen, color, rect) + elif part_type == "circle": + radius = part["radius"] + color = part["color"] + if "center_offset" in part: + pygame.draw.circle( + self.screen, + color, + pos + np.array(part["center_offset"]), + radius, + ) + else: + pygame.draw.circle(self.screen, color, pos, radius) + def draw_item(self, pos, item: Item): """Visualisation of an item at the specified position. On a counter or in the hands of the player. The visual composition of the item is read in from visualization.yaml file, where it is specified as @@ -202,22 +245,9 @@ class PyGameGUI: item: The item do be drawn in the game. """ - if item.name == "Tomato": - print(item) - if not isinstance(item, Meal): - image = pygame.image.load( - ROOT_DIR - / Path("pygame_gui") - / self.visualization_config[item.name]["parts"][0]["path"] - ).convert_alpha() - - size = self.visualization_config[item.name]["parts"][0]["size"] - image = pygame.transform.scale(image, (size, size)) - - rect = image.get_rect() - rect.center = pos - self.screen.blit(image, rect) + if item.name in self.visualization_config: + self.draw_thing(pos, self.visualization_config[item.name]["parts"]) if isinstance(item, ProgressibleItem) and not item.finished: self.draw_progress_bar(pos, item.progressed_steps, item.steps_needed) @@ -243,15 +273,19 @@ class PyGameGUI: case 3: pygame.draw.circle(self.screen, RED, pos, 12) else: - image = pygame.image.load( - ROOT_DIR - / Path("pygame_gui") - / self.visualization_config[item.name]["parts"][0]["path"] - ).convert_alpha() - image = pygame.transform.scale(image, (24, 24)) - rect = image.get_rect() - rect.center = pos - self.screen.blit(image, rect) + if item.name in self.visualization_config: + image = pygame.image.load( + ROOT_DIR + / Path("pygame_gui") + / self.visualization_config[item.name]["parts"][0]["path"] + ).convert_alpha() + + size = self.visualization_config[item.name]["parts"][0]["size"] + image = pygame.transform.scale(image, (size, size)) + + rect = image.get_rect() + rect.center = pos + self.screen.blit(image, rect) def draw_progress_bar(self, pos, current, needed): """Visualize progress of progressing item as a green bar under the item.""" @@ -283,28 +317,15 @@ class PyGameGUI: ) pygame.draw.rect(self.screen, COUNTER_COLOR, counter_rect_outline) - for part in self.visualization_config[counter.__class__.__name__]["parts"]: - if part["type"] == "rect": - height = part["height"] - width = part["width"] - color = part["color"] - if "center_offset" in part: - dx, dy = part["center_offset"] - rect = pygame.Rect(counter.pos[0] + dx, counter.pos[1] + dy, 5, 20) - pygame.draw.rect(self.screen, color, rect) - else: - rect = pygame.Rect( - counter.pos[0] - (height / 2), - counter.pos[1] - (width / 2), - height, - width, - ) - pygame.draw.rect(self.screen, color, rect) - - elif part["type"] == "circle": - radius = part["radius"] - color = part["color"] - pygame.draw.circle(self.screen, color, counter.pos, radius) + if str(counter) in self.visualization_config: + self.draw_thing( + counter.pos, self.visualization_config[str(counter)]["parts"] + ) + else: + self.draw_thing( + counter.pos, + self.visualization_config[counter.__class__.__name__]["parts"], + ) if counter.occupied_by is not None: if isinstance(counter.occupied_by, list): diff --git a/overcooked_simulator/pygame_gui/visualization.yaml b/overcooked_simulator/pygame_gui/visualization.yaml index dc200b30a00b90ee40ee1ed664f24a9448457e06..b5997fd97f6bca79dc5d2718c4e180dd86b12e54 100644 --- a/overcooked_simulator/pygame_gui/visualization.yaml +++ b/overcooked_simulator/pygame_gui/visualization.yaml @@ -40,6 +40,13 @@ TomatoDispenser: height: 32 width: 32 +LettuceDispenser: + parts: + - color: [ 0, 255, 0 ] + type: "rect" + height: 32 + width: 32 + ServingWindow: parts: - color: [ 255, 255, 0 ] @@ -64,6 +71,40 @@ Tomato: path: "images/tomato.png" size: 40 +Lettuce: + parts: + - type: "circle" + radius: 12 + color: [ 0, 0, 0 ] + - type: "circle" + radius: 10 + color: [ 0, 255, 0 ] + +ChoppedLettuce: + parts: + - type: "circle" + radius: 12 + color: [ 0, 0, 0 ] + center_offset: [ -5, 0 ] + - type: "circle" + radius: 10 + color: [ 0, 255, 0 ] + center_offset: [ -5, 0 ] + - type: "circle" + radius: 12 + color: [ 0, 0, 0 ] + - type: "circle" + radius: 10 + color: [ 0, 255, 0 ] + - type: "circle" + radius: 12 + color: [ 0, 0, 0 ] + center_offset: [ 5, 0 ] + - type: "circle" + radius: 10 + color: [ 0, 255, 0 ] + center_offset: [ 5, 0 ] + ChoppedTomato: parts: - type: "image"