From 3fc8e4e28fb55151b63c0c52a36d87d278a3638a Mon Sep 17 00:00:00 2001
From: fheinrich <fheinrich@techfak.uni-bielefeld.de>
Date: Wed, 13 Mar 2024 09:31:15 +0100
Subject: [PATCH] Added hook when returning items to dispensers.

---
 cooperative_cuisine/configs/environment_config.yaml             | 1 +
 cooperative_cuisine/configs/human_readable_print_templates.yaml | 1 +
 cooperative_cuisine/counters.py                                 | 2 ++
 cooperative_cuisine/hooks.py                                    | 2 ++
 cooperative_cuisine/recording.py                                | 2 +-
 5 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/cooperative_cuisine/configs/environment_config.yaml b/cooperative_cuisine/configs/environment_config.yaml
index e63620d0..e9188198 100644
--- a/cooperative_cuisine/configs/environment_config.yaml
+++ b/cooperative_cuisine/configs/environment_config.yaml
@@ -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:
diff --git a/cooperative_cuisine/configs/human_readable_print_templates.yaml b/cooperative_cuisine/configs/human_readable_print_templates.yaml
index b190f6bc..cb9c47e9 100644
--- a/cooperative_cuisine/configs/human_readable_print_templates.yaml
+++ b/cooperative_cuisine/configs/human_readable_print_templates.yaml
@@ -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
diff --git a/cooperative_cuisine/counters.py b/cooperative_cuisine/counters.py
index cd84be94..bf97c26b 100644
--- a/cooperative_cuisine/counters.py
+++ b/cooperative_cuisine/counters.py
@@ -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)
 
diff --git a/cooperative_cuisine/hooks.py b/cooperative_cuisine/hooks.py
index f16b10af..c541562b 100644
--- a/cooperative_cuisine/hooks.py
+++ b/cooperative_cuisine/hooks.py
@@ -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"
 
diff --git a/cooperative_cuisine/recording.py b/cooperative_cuisine/recording.py
index a71cc0b3..2ed4f9ec 100644
--- a/cooperative_cuisine/recording.py
+++ b/cooperative_cuisine/recording.py
@@ -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)
-- 
GitLab