Skip to content
Snippets Groups Projects
Commit 6f16f87c authored by Florian Schröder's avatar Florian Schröder
Browse files

Refactor callback registration in OvercookedEnvironment

The refactoring moves the redundant callback registrations from `overcooked_environment.py` to a dedicated function, `add_dummy_callbacks`, in `hooks.py`. This restructure streamlines the code and improves readability by reducing clutter in the Overcooked Environment initialization method.
parent c8c7a773
No related branches found
No related tags found
1 merge request!46Resolve "Hooks"
Pipeline #45361 passed
from collections import defaultdict
from functools import partial
from typing import Callable
# TODO add player_id as kwarg to all hooks -> pass player id to all methods
......@@ -109,3 +110,34 @@ class Hooks:
def print_hook_callback(text, env, **kwargs):
print(env.env_time, text)
def add_dummy_callbacks(env):
env.register_callback_for_hook(
SERVE_NOT_ORDERED_MEAL,
partial(
print_hook_callback,
text="You tried to served a meal that was not ordered!",
),
)
env.register_callback_for_hook(
SINK_START_INTERACT,
partial(
print_hook_callback,
text="You started to use the Sink!",
),
)
env.register_callback_for_hook(
COMPLETED_ORDER,
partial(
print_hook_callback,
text="You completed an order!",
),
)
env.register_callback_for_hook(
TRASHCAN_USAGE,
partial(
print_hook_callback,
text="You used the trashcan!",
),
)
......@@ -8,7 +8,6 @@ import random
import sys
from datetime import timedelta, datetime
from enum import Enum
from functools import partial
from pathlib import Path
from typing import Literal, TypedDict, Callable
......@@ -42,11 +41,7 @@ from overcooked_simulator.hooks import (
ACTION_ON_NOT_REACHABLE_COUNTER,
ACTION_PUT,
ACTION_INTERACT_START,
SERVE_NOT_ORDERED_MEAL,
print_hook_callback,
SINK_START_INTERACT,
COMPLETED_ORDER,
TRASHCAN_USAGE,
add_dummy_callbacks,
)
from overcooked_simulator.order import (
OrderAndScoreManager,
......@@ -135,34 +130,7 @@ class Environment:
# init callbacks here from config
# test:
self.register_callback_for_hook(
SERVE_NOT_ORDERED_MEAL,
partial(
print_hook_callback,
text="You tried to served a meal that was not ordered!",
),
)
self.register_callback_for_hook(
SINK_START_INTERACT,
partial(
print_hook_callback,
text="You started to use the Sink!",
),
)
self.register_callback_for_hook(
COMPLETED_ORDER,
partial(
print_hook_callback,
text="You completed an order!",
),
)
self.register_callback_for_hook(
TRASHCAN_USAGE,
partial(
print_hook_callback,
text="You used the trashcan!",
),
)
add_dummy_callbacks(self)
self.players: dict[str, Player] = {}
"""the player, keyed by their id/name."""
......
......@@ -2,11 +2,11 @@ from datetime import timedelta
import numpy as np
import pytest
from overcooked_simulator.hook import Hooks
from overcooked_simulator import ROOT_DIR
from overcooked_simulator.counters import Counter, CuttingBoard
from overcooked_simulator.game_items import Item, ItemInfo, ItemType
from overcooked_simulator.hooks import Hooks
from overcooked_simulator.overcooked_environment import (
Action,
Environment,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment