From af78587a7d357a95481b360bfc691591dd499037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Schr=C3=B6der?= <fschroeder@techfak.uni-bielefeld.de> Date: Tue, 12 Mar 2024 16:58:21 +0100 Subject: [PATCH] Update pygame visualization settings The visualization settings for the pygame 2d visualization such as 'use_player_cook_sprites', 'show_interaction_range', and 'show_counter_centers' are now part of the configuration in 'visualization.yaml'. If these settings are not defined in the configuration, the program will use default values. This change allows for easier modification of the visualization aspects without directly changing the code each time. --- cooperative_cuisine/pygame_2d_vis/drawing.py | 26 ++++++++++++++----- .../pygame_2d_vis/visualization.yaml | 6 +++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/cooperative_cuisine/pygame_2d_vis/drawing.py b/cooperative_cuisine/pygame_2d_vis/drawing.py index 0c67eaf1..0bdd50c3 100644 --- a/cooperative_cuisine/pygame_2d_vis/drawing.py +++ b/cooperative_cuisine/pygame_2d_vis/drawing.py @@ -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["use_player_cook_sprites"] + if "use_player_cook_sprites" in config + else True + ) + self.SHOW_INTERACTION_RANGE = ( + config["show_interaction_range"] + if "show_interaction_range" in config + else False + ) + self.SHOW_COUNTER_CENTERS = ( + config["show_counter_centers"] + if "show_counter_centers" in config + 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) diff --git a/cooperative_cuisine/pygame_2d_vis/visualization.yaml b/cooperative_cuisine/pygame_2d_vis/visualization.yaml index 0dc39c17..e52e34b0 100644 --- a/cooperative_cuisine/pygame_2d_vis/visualization.yaml +++ b/cooperative_cuisine/pygame_2d_vis/visualization.yaml @@ -1,5 +1,11 @@ # 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 -- GitLab