From 2e5ef1e27b644ef23908e97e42d43ba89f81a25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Schr=C3=B6der?= <fschroeder@techfak.uni-bielefeld.de> Date: Tue, 5 Mar 2024 14:48:41 +0100 Subject: [PATCH] Remove unused variable and add docstrings in environment.py The PAUSED variable, which was unused, has been removed from the codebase to improve readability. Docstrings were added to multiple existing methods and instance variables in the environment.py file for better understanding of their functionalities. This change will make it easier for developers to understand the purpose and usage of the various methods and variables, ultimately smoothing the development process. --- cooperative_cuisine/environment.py | 36 +++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/cooperative_cuisine/environment.py b/cooperative_cuisine/environment.py index 4d562582..4c25ef30 100644 --- a/cooperative_cuisine/environment.py +++ b/cooperative_cuisine/environment.py @@ -93,8 +93,6 @@ class Environment: Handles player movement, collision-detection, counters, cooking processes, recipes, incoming orders, time. """ - PAUSED = None - def __init__( self, env_config: Path | str, @@ -136,9 +134,10 @@ class Environment: ) """The config of the environment. All environment specific attributes is configured here.""" - self.player_view_restricted = self.environment_config["player_config"][ + self.player_view_restricted: bool = self.environment_config["player_config"][ "restricted_view" ] + """If field-of-view of players is restricted in this environment.""" if self.player_view_restricted: self.player_view_angle = self.environment_config["player_config"][ "view_angle" @@ -202,6 +201,7 @@ class Environment: hook=self.hook, random=self.random, ) + """Handles the creation of counters based on their config.""" ( self.counters, @@ -220,6 +220,7 @@ class Environment: dtype=float, ), ) + """Does the movement of players in each step.""" self.progressing_counters = [] """Counters that needs to be called in the step function via the `progress` method.""" @@ -227,6 +228,7 @@ class Environment: self.effect_manager: dict[ str, EffectManager ] = self.counter_factory.setup_effect_manger(self.counters) + """Dict of effect managers. Currently only the fire effect manager.""" self.overwrite_counters(self.counters) @@ -248,6 +250,7 @@ class Environment: order_manager=self.order_manager, do_validation=do_validation, ) + """Validates configs and creates recipe graphs.""" meals_to_be_ordered = self.recipe_validation.validate_environment(self.counters) assert meals_to_be_ordered, "Need possible meals for order generation." @@ -264,6 +267,7 @@ class Environment: log.debug(f"End time: {self.env_time_end}") self.info_msgs_per_player: dict[str, list[InfoMsg]] = defaultdict(list) + """Cache of info messages per player which should be showed in the visualization of each player.""" self.hook( ENV_INITIALIZED, @@ -274,6 +278,24 @@ class Environment: ) def overwrite_counters(self, counters): + """Resets counters. + + Args: + counters: A list of counter objects representing the counters in the system. + + This method takes a list of counter objects representing the counters in the system and updates the counters + attribute of the current object to the provided list. It also updates the counter_positions attribute of the + movement object with the positions of the counters. + + Additionally, it assigns the counter classes with a "progress" attribute to the variable + progress_counter_classes. It does this by filtering the classes in the cooperative_cuisine.counters module + using the inspect module to only keep the classes that have a "progress" attribute. + + Next, it filters the counters based on whether their class is in the progress_counter_classes list and + assigns the filtered counters to the progressing_counters attribute of the current object. + + Finally, it sets the counters for each effect manager in the effect_manager dictionary to the provided counters. + """ self.counters = counters self.movement.counter_positions = np.array([c.pos for c in self.counters]) @@ -496,9 +518,17 @@ class Environment: log.debug(f"Reset env time to {self.env_time}") def register_callback_for_hook(self, hook_ref: str | list[str], callback: Callable): + """Registers a callback function for a given hook reference. + + Args: + hook_ref (str | list[str]): The reference to the hook or hooks for which the callback should be registered. It can be a single string or a list of strings. + callback (Callable): The callback function to be registered for the specified hook(s). The function should accept the necessary parameters and perform the desired actions. + + """ self.hook.register_callback(hook_ref, callback) def extra_setup_functions(self): + """Executes extra setup functions specified in the environment configuration.""" if self.environment_config["extra_setup_functions"]: for function_name, function_def in self.environment_config[ "extra_setup_functions" -- GitLab