diff --git a/overcooked_simulator/main.py b/overcooked_simulator/main.py index ea66b93ab47e97284f48254bf3dc981a2a957e94..8da89c091bdbd7334361024d598f9b63b055228a 100644 --- a/overcooked_simulator/main.py +++ b/overcooked_simulator/main.py @@ -8,10 +8,13 @@ from overcooked_simulator.game_items import Tomato from overcooked_simulator.player import Player from overcooked_simulator.pygame_gui.pygame_gui import PyGameGUI from overcooked_simulator.simulation_runner import Simulator +from root_definition import ROOT_DIR def main(): - simulator = Simulator(Path("overcooked_simulator/layouts/basic.layout"), 600) + simulator = Simulator( + Path(ROOT_DIR + "/overcooked_simulator/layouts/basic.layout"), 600 + ) player_one_name = "p1" player_two_name = "p2" simulator.register_player(Player(player_one_name, np.array([100, 200]))) diff --git a/overcooked_simulator/pygame_gui/pygame_gui.py b/overcooked_simulator/pygame_gui/pygame_gui.py index eff1e36452a21bdddd6c3564f7d3aa7d69c80a2b..8692b0da2b35e7bceca0723d78c772ada52d36e1 100644 --- a/overcooked_simulator/pygame_gui/pygame_gui.py +++ b/overcooked_simulator/pygame_gui/pygame_gui.py @@ -6,6 +6,7 @@ from overcooked_simulator.game_items import ProgressibleItem from overcooked_simulator.game_items import Tomato from overcooked_simulator.overcooked_environment import Action from overcooked_simulator.simulation_runner import Simulator +from root_definition import ROOT_DIR WHITE = (255, 255, 255) GREY = (190, 190, 190) @@ -51,10 +52,10 @@ class PyGameGUI: """Visualisation of the overcooked environmnent and reading keyboard inputs using pygame.""" def __init__( - self, - simulator: Simulator, - player_names: list[str], - player_keys: list[pygame.key], + self, + simulator: Simulator, + player_names: list[str], + player_keys: list[pygame.key], ): self.FPS = 60 self.simulator = simulator @@ -167,11 +168,11 @@ class PyGameGUI: if isinstance(item, Tomato): if item.finished: image = pygame.image.load( - "overcooked_simulator/pygame_gui/images/tomato_cut.png" + ROOT_DIR + "/overcooked_simulator/pygame_gui/images/tomato_cut.png" ).convert_alpha() # or .convert_alpha() else: image = pygame.image.load( - "overcooked_simulator/pygame_gui/images/tomato.png" + ROOT_DIR + "/overcooked_simulator/pygame_gui/images/tomato.png" ).convert_alpha() # or .convert_alpha() rect = image.get_rect() rect.center = pos diff --git a/root_definition.py b/root_definition.py new file mode 100644 index 0000000000000000000000000000000000000000..7e52d60a54ab03adea4906a946949e6a18a072b0 --- /dev/null +++ b/root_definition.py @@ -0,0 +1,3 @@ +import os + +ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) # This is your Project Root diff --git a/tests/test_start.py b/tests/test_start.py index 406ea8a3487908d22695f3fa769facdbf5c61d95..a3897da8180930b619aacca83334d0ab636c82b4 100644 --- a/tests/test_start.py +++ b/tests/test_start.py @@ -8,13 +8,14 @@ from overcooked_simulator.game_items import Tomato from overcooked_simulator.overcooked_environment import Action from overcooked_simulator.player import Player from overcooked_simulator.simulation_runner import Simulator +from root_definition import ROOT_DIR try: - with open("../overcooked_simulator/layouts/basic.layout", "r") as textfile: + with open(ROOT_DIR + "/overcooked_simulator/layouts/basic.layout", "r") as textfile: pass - layouts_folder = Path("../overcooked_simulator/layouts") + layouts_folder = Path(ROOT_DIR + "/overcooked_simulator/layouts") except FileNotFoundError as e: - layouts_folder = Path("overcooked_simulator/layouts") + layouts_folder = Path(ROOT_DIR + "/overcooked_simulator/layouts") def test_player_registration():