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

Merge remote-tracking branch 'origin/dev' into 108-in-screen-after-a-game-show-cook-icons

# Conflicts:
#	cooperative_cuisine/pygame_2d_vis/drawing.py
parents c9ecf434 9fdf2b47
No related branches found
No related tags found
1 merge request!85Resolve "In screen after a game show cook icons"
Pipeline #48662 passed
...@@ -183,6 +183,7 @@ hook_callbacks: ...@@ -183,6 +183,7 @@ hook_callbacks:
- progress_started - progress_started
- progress_finished - progress_finished
- content_ready - content_ready
- dispenser_item_returned
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder '' callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs: callback_class_kwargs:
......
...@@ -25,3 +25,4 @@ on_item_transition: "$item became $result." ...@@ -25,3 +25,4 @@ on_item_transition: "$item became $result."
progress_started: "Item $item started progressing." progress_started: "Item $item started progressing."
progress_finished: "Item $item finished its progress." progress_finished: "Item $item finished its progress."
content_ready: "Meal $result was created on $before." content_ready: "Meal $result was created on $before."
dispenser_item_returned: "Player $player returned $item to $counter."
\ No newline at end of file
...@@ -68,6 +68,7 @@ from cooperative_cuisine.hooks import ( ...@@ -68,6 +68,7 @@ from cooperative_cuisine.hooks import (
PRE_PLATE_DISPENSER_DROP_OFF, PRE_PLATE_DISPENSER_DROP_OFF,
PRE_PLATE_DISPENSER_PICK_UP, PRE_PLATE_DISPENSER_PICK_UP,
POST_PLATE_DISPENSER_PICK_UP, POST_PLATE_DISPENSER_PICK_UP,
DISPENSER_ITEM_RETURNED,
) )
from cooperative_cuisine.state_representation import CounterState from cooperative_cuisine.state_representation import CounterState
...@@ -511,6 +512,7 @@ class Dispenser(Counter): ...@@ -511,6 +512,7 @@ class Dispenser(Counter):
return return_this return return_this
def drop_off(self, item: Item, player: str = "0") -> Item | None: def drop_off(self, item: Item, player: str = "0") -> Item | None:
self.hook(DISPENSER_ITEM_RETURNED, player=player, counter=self, item=item)
if self.occupied_by.can_combine(item): if self.occupied_by.can_combine(item):
return self.occupied_by.combine(item) return self.occupied_by.combine(item)
......
...@@ -77,6 +77,8 @@ POST_PLATE_DISPENSER_PICK_UP = "post_plate_dispenser_pick_up" ...@@ -77,6 +77,8 @@ POST_PLATE_DISPENSER_PICK_UP = "post_plate_dispenser_pick_up"
PRE_PLATE_DISPENSER_DROP_OFF = "pre_plate_dispenser_drop_off" PRE_PLATE_DISPENSER_DROP_OFF = "pre_plate_dispenser_drop_off"
POST_PLATE_DISPENSER_DROP_OFF = "post_plate_dispenser_drop_off" POST_PLATE_DISPENSER_DROP_OFF = "post_plate_dispenser_drop_off"
DISPENSER_ITEM_RETURNED = "dispenser_item_returned"
CUTTING_BOARD_PROGRESS = "cutting_board_progress" CUTTING_BOARD_PROGRESS = "cutting_board_progress"
CUTTING_BOARD_100 = "cutting_board_100" CUTTING_BOARD_100 = "cutting_board_100"
......
...@@ -22,10 +22,6 @@ from cooperative_cuisine.state_representation import ( ...@@ -22,10 +22,6 @@ from cooperative_cuisine.state_representation import (
EffectState, EffectState,
) )
USE_PLAYER_COOK_SPRITES = True
SHOW_INTERACTION_RANGE = False
SHOW_COUNTER_CENTERS = False
def calc_angle(vec_a: list[float], vec_b: list[float]) -> float: def calc_angle(vec_a: list[float], vec_b: list[float]) -> float:
a = pygame.math.Vector2(vec_a) a = pygame.math.Vector2(vec_a)
...@@ -86,6 +82,22 @@ class Visualizer: ...@@ -86,6 +82,22 @@ class Visualizer:
self.fire_time_steps = 8 self.fire_time_steps = 8
self.observation_screen = None self.observation_screen = None
self.USE_PLAYER_COOK_SPRITES = (
config["Gui"]["use_player_cook_sprites"]
if "Gui" in config and "use_player_cook_sprites" in config["Gui"]
else True
)
self.SHOW_INTERACTION_RANGE = (
config["Gui"]["show_interaction_range"]
if "Gui" in config and "show_interaction_range" in config["Gui"]
else False
)
self.SHOW_COUNTER_CENTERS = (
config["Gui"]["show_counter_centers"]
if "Gui" in config and "show_counter_centers" in config["Gui"]
else False
)
def create_player_colors(self, n) -> None: def create_player_colors(self, n) -> None:
"""Create different colors for the players. The color hues are sampled uniformly in HSV-Space, """Create different colors for the players. The color hues are sampled uniformly in HSV-Space,
then the corresponding colors from the defined colors list are looked up. then the corresponding colors from the defined colors list are looked up.
...@@ -349,7 +361,7 @@ class Visualizer: ...@@ -349,7 +361,7 @@ class Visualizer:
facing = np.array(player_dict["facing_direction"], dtype=float) facing = np.array(player_dict["facing_direction"], dtype=float)
if USE_PLAYER_COOK_SPRITES: if self.USE_PLAYER_COOK_SPRITES:
self.draw_cook( self.draw_cook(
screen, grid_size, pos, colors[self.player_colors[p_idx]], facing screen, grid_size, pos, colors[self.player_colors[p_idx]], facing
) )
...@@ -380,7 +392,7 @@ class Visualizer: ...@@ -380,7 +392,7 @@ class Visualizer:
), ),
) )
if SHOW_INTERACTION_RANGE: if self.SHOW_INTERACTION_RANGE:
pygame.draw.circle( pygame.draw.circle(
screen, screen,
colors["blue"], colors["blue"],
...@@ -765,7 +777,7 @@ class Visualizer: ...@@ -765,7 +777,7 @@ class Visualizer:
item=effect, item=effect,
) )
if SHOW_COUNTER_CENTERS: if self.SHOW_COUNTER_CENTERS:
pos = np.array(counter["pos"]) * grid_size pos = np.array(counter["pos"]) * grid_size
pygame.draw.circle(screen, colors["green1"], pos, 3) pygame.draw.circle(screen, colors["green1"], pos, 3)
pygame.draw.circle(screen, colors["green1"], pos, 3) pygame.draw.circle(screen, colors["green1"], pos, 3)
......
This diff is collapsed.
# colors: https://www.webucator.com/article/python-color-constants-module/ # colors: https://www.webucator.com/article/python-color-constants-module/
Gui:
use_player_cook_sprites: True
show_interaction_range: False
show_counter_centers: False
GameWindow: GameWindow:
screen_margin: 100 screen_margin: 100
min_width: 900 min_width: 900
......
...@@ -219,5 +219,5 @@ def print_recorded_events_human_readable(jsonl_path: Path): ...@@ -219,5 +219,5 @@ def print_recorded_events_human_readable(jsonl_path: Path):
if __name__ == "__main__": if __name__ == "__main__":
json_lines_path: Path = Path(sys.argv[0]) json_lines_path: Path = Path(sys.argv[1])
print_recorded_events_human_readable(json_lines_path) print_recorded_events_human_readable(json_lines_path)
...@@ -4,7 +4,12 @@ import os ...@@ -4,7 +4,12 @@ import os
import yaml import yaml
from cooperative_cuisine import ROOT_DIR from cooperative_cuisine import ROOT_DIR
from cooperative_cuisine.pygame_2d_vis.drawing import calc_angle, Visualizer, main from cooperative_cuisine.pygame_2d_vis.drawing import (
calc_angle,
Visualizer,
main,
save_screenshot,
)
from cooperative_cuisine.pygame_2d_vis.game_colors import RGB, WHITE, colors from cooperative_cuisine.pygame_2d_vis.game_colors import RGB, WHITE, colors
...@@ -37,4 +42,18 @@ def test_visualizer(): ...@@ -37,4 +42,18 @@ def test_visualizer():
with open(ROOT_DIR / "pygame_2d_vis" / "sample_state.json", "r") as file: with open(ROOT_DIR / "pygame_2d_vis" / "sample_state.json", "r") as file:
state = json.load(file) state = json.load(file)
image = vis.get_state_image(40, state) image = vis.get_state_image(40, state)
assert image.shape == (480, 360, 3) assert image.shape == (520, 360, 3)
def test_drawing_debug():
with open(ROOT_DIR / "pygame_2d_vis" / "visualization.yaml", "r") as f:
viz_config = yaml.safe_load(f)
viz_config["Gui"]["use_player_cook_sprites"] = False
viz_config["Gui"]["show_interaction_range"] = True
viz_config["Gui"]["show_counter_centers"] = True
with open(ROOT_DIR / "pygame_2d_vis" / "sample_state.json", "r") as f:
state = json.load(f)
save_screenshot(state, viz_config, ROOT_DIR / "generated" / "screenshot_2.jpg")
assert os.path.exists(os.path.join(ROOT_DIR, "generated", "screenshot_2.jpg"))
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