Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • scs/cocosy/cooperative-cuisine
1 result
Show changes
Commits on Source (6)
......@@ -183,6 +183,7 @@ hook_callbacks:
- progress_started
- progress_finished
- content_ready
- dispenser_item_returned
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
......
......@@ -25,3 +25,4 @@ on_item_transition: "$item became $result."
progress_started: "Item $item started progressing."
progress_finished: "Item $item finished its progress."
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 (
PRE_PLATE_DISPENSER_DROP_OFF,
PRE_PLATE_DISPENSER_PICK_UP,
POST_PLATE_DISPENSER_PICK_UP,
DISPENSER_ITEM_RETURNED,
)
from cooperative_cuisine.state_representation import CounterState
......@@ -511,6 +512,7 @@ class Dispenser(Counter):
return return_this
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):
return self.occupied_by.combine(item)
......
......@@ -77,6 +77,8 @@ POST_PLATE_DISPENSER_PICK_UP = "post_plate_dispenser_pick_up"
PRE_PLATE_DISPENSER_DROP_OFF = "pre_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_100 = "cutting_board_100"
......
......@@ -22,10 +22,6 @@ from cooperative_cuisine.state_representation import (
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:
a = pygame.math.Vector2(vec_a)
......@@ -86,6 +82,22 @@ class Visualizer:
self.fire_time_steps = 8
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:
"""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.
......@@ -329,7 +341,7 @@ class Visualizer:
facing = np.array(player_dict["facing_direction"], dtype=float)
if USE_PLAYER_COOK_SPRITES:
if self.USE_PLAYER_COOK_SPRITES:
pygame.draw.circle(
screen,
colors[self.player_colors[p_idx]],
......@@ -368,7 +380,7 @@ class Visualizer:
),
)
if SHOW_INTERACTION_RANGE:
if self.SHOW_INTERACTION_RANGE:
pygame.draw.circle(
screen,
colors["blue"],
......@@ -753,7 +765,7 @@ class Visualizer:
item=effect,
)
if SHOW_COUNTER_CENTERS:
if self.SHOW_COUNTER_CENTERS:
pos = np.array(counter["pos"]) * grid_size
pygame.draw.circle(screen, colors["green1"], pos, 3)
pygame.draw.circle(screen, colors["green1"], pos, 3)
......
# 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:
screen_margin: 100
min_width: 900
......
......@@ -219,5 +219,5 @@ def print_recorded_events_human_readable(jsonl_path: Path):
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)
......@@ -4,7 +4,12 @@ import os
import yaml
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
......@@ -37,4 +42,18 @@ def test_visualizer():
with open(ROOT_DIR / "pygame_2d_vis" / "sample_state.json", "r") as file:
state = json.load(file)
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"))