Skip to content
Snippets Groups Projects

More hook updates

Merged Fabian Heinrich requested to merge more-hook-updates into dev
3 files
+ 33
19
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -34,6 +34,7 @@ The defined counter classes are:
"""
from __future__ import annotations
import copy
import dataclasses
import logging
import uuid
@@ -69,7 +70,7 @@ from cooperative_cuisine.hooks import (
PRE_PLATE_DISPENSER_PICK_UP,
POST_PLATE_DISPENSER_PICK_UP,
DISPENSER_ITEM_RETURNED,
DROP_OFF_ON_COOKING_EQUIPMENT_PLATE_DISPENSER,
DROP_OFF_ON_COOKING_EQUIPMENT_PLATE_DISPENSER, PICK_UP_ON_COOKING_EQUIPMENT,
)
from cooperative_cuisine.state_representation import CounterState
@@ -150,7 +151,7 @@ class Counter:
self.orientation = orientation
def pick_up(
self, on_hands: bool = True, player: str = "0"
self, on_hands: bool = True, player: str = "0", player_holding: Item | None = None,
) -> Item | None | Iterable[Item]:
"""Gets called upon a player performing the pickup action. If the counter can give something to
the player, it does so. In the standard counter this is when an item is on the counter.
@@ -158,6 +159,7 @@ class Counter:
Args:
on_hands: Will the item be put on empty hands or on a cooking equipment.
player: The player name that tries to pick up from the counter.
player_holding: What the player is currently holding.
Returns:
The item which the counter is occupied by. None if nothing is there.
@@ -172,18 +174,20 @@ class Counter:
counter=self,
on_hands=on_hands,
return_this=occupied_by,
player=player
player=player,
player_holding=player_holding,
)
return occupied_by
return None
if self.occupied_by and isinstance(self.occupied_by, CookingEquipment):
return_this = self.occupied_by.release()
self.hook(
POST_COUNTER_PICK_UP,
counter=self,
on_hands=on_hands,
PICK_UP_ON_COOKING_EQUIPMENT,
return_this=return_this,
occupied_by=self.occupied_by,
counter=self,
player=player,
player_holding=player_holding,
)
return return_this
occupied_by = self.occupied_by
@@ -194,6 +198,7 @@ class Counter:
on_hands=on_hands,
return_this=occupied_by,
player=player,
player_holding=player_holding,
)
return occupied_by
@@ -236,12 +241,15 @@ class Counter:
item=item,
)
elif self.occupied_by.can_combine(item):
before_combine = copy.copy(item)
occupied_before_combine = copy.deepcopy(self.occupied_by)
return_this = self.occupied_by.combine(item)
self.hook(
DROP_OFF_ON_COOKING_EQUIPMENT,
item=item,
item=before_combine,
equipment=self.occupied_by,
counter=self,
occupied_before=occupied_before_combine,
player=player,
return_this=return_this,
)
@@ -419,11 +427,12 @@ class CuttingBoard(Counter):
passed_time=passed_time,
)
if self.occupied_by.progress_percentage == 1.0:
item_before = copy.copy(self.occupied_by)
self.occupied_by.reset()
self.occupied_by.name = self.inverted_transition_dict[
self.occupied_by.name
].name
self.hook(CUTTING_BOARD_100, counter=self, item=self.occupied_by, player=player)
self.hook(CUTTING_BOARD_100, counter=self, item=self.occupied_by, player=player, before=item_before)
class ServingWindow(Counter):
@@ -489,7 +498,7 @@ class ServingWindow(Counter):
or (len(item.content_list) == 1 and item.content_list[0].name in self.meals)
)
def pick_up(self, on_hands: bool = True, player: str = "0") -> Item | None:
def pick_up(self, on_hands: bool = True, player: str = "0", player_holding: Item | None = None,) -> Item | None:
pass
def add_plate_dispenser(self, plate_dispenser):
@@ -524,7 +533,7 @@ class Dispenser(Counter):
**kwargs,
)
def pick_up(self, on_hands: bool = True, player: str = "0") -> Item | None:
def pick_up(self, on_hands: bool = True, player: str = "0", player_holding: Item | None = None,) -> Item | None:
self.hook(PRE_DISPENSER_PICK_UP, counter=self, on_hands=on_hands, player=player)
return_this = self.occupied_by
self.occupied_by = self.create_item()
@@ -534,6 +543,7 @@ class Dispenser(Counter):
on_hands=on_hands,
return_this=return_this,
player=player,
player_holding=player_holding,
)
return return_this
@@ -628,7 +638,7 @@ class PlateDispenser(Counter):
"""
def pick_up(self, on_hands: bool = True, player: str = "0") -> Item | None:
def pick_up(self, on_hands: bool = True, player: str = "0", player_holding: Item | None = None,) -> Item | None:
self.hook(
PRE_PLATE_DISPENSER_PICK_UP,
counter=self,
@@ -757,7 +767,7 @@ class Trashcan(Counter):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def pick_up(self, on_hands: bool = True, player: str = "0") -> Item | None:
def pick_up(self, on_hands: bool = True, player: str = "0", player_holding: Item | None = None,) -> Item | None:
pass
def drop_off(self, item: Item, player: str = "0") -> Item | None:
@@ -921,7 +931,7 @@ class Sink(Counter):
self.hook(ADDED_PLATE_TO_SINK, counter=self, item=item, player=player)
return None
def pick_up(self, on_hands: bool = True, player: str = "0") -> Item | None:
def pick_up(self, on_hands: bool = True, player: str = "0", player_holding: Item | None = None,) -> Item | None:
return None
def set_addon(self, sink_addon: SinkAddon):
@@ -947,14 +957,14 @@ class SinkAddon(Counter):
return self.occupied_by and self.occupied_by[-1].can_combine(item)
def drop_off(self, item: Item, player: str = "0") -> Item | None:
self.hook(DROP_ON_SINK_ADDON, counter=self, item=item, player=player)
self.hook(DROP_ON_SINK_ADDON, counter=self, item=item, occupied_by=self.occupied_by[-1], player=player)
return self.occupied_by[-1].combine(item)
def add_clean_plate(self, plate: Plate):
"""Called from the `Sink` after a plate is cleaned / the progress is complete."""
self.occupied_by.appendleft(plate)
def pick_up(self, on_hands: bool = True, player: str = "0") -> Item | None:
def pick_up(self, on_hands: bool = True, player: str = "0", player_holding: Item | None = None,) -> Item | None:
if self.occupied_by:
self.hook(
PICK_UP_FROM_SINK_ADDON,
Loading