From 6d6c804d15cd13d264b6bb160d6be27731d8e657 Mon Sep 17 00:00:00 2001
From: fheinrich <fheinrich@techfak.uni-bielefeld.de>
Date: Mon, 4 Mar 2024 10:50:00 +0100
Subject: [PATCH] Fix gui when not using the study server

---
 cooperative_cuisine/game_server.py       |  3 ++-
 cooperative_cuisine/pygame_2d_vis/gui.py | 25 ++++++++++++------------
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/cooperative_cuisine/game_server.py b/cooperative_cuisine/game_server.py
index 5f87ac98..0497f1c9 100644
--- a/cooperative_cuisine/game_server.py
+++ b/cooperative_cuisine/game_server.py
@@ -39,6 +39,7 @@ from cooperative_cuisine.utils import (
     url_and_port_arguments,
     add_list_of_manager_ids_arguments,
     disable_websocket_logging_arguments,
+    setup_logging,
 )
 
 log = logging.getLogger(__name__)
@@ -767,7 +768,7 @@ async def websocket_player_endpoint(websocket: WebSocket, client_id: str):
 def main(
     host: str, port: int, manager_ids: list[str], enable_websocket_logging: bool = False
 ):
-    # setup_logging(enable_websocket_logging)
+    setup_logging(enable_websocket_logging)
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
     environment_handler.extend_allowed_manager(manager_ids)
diff --git a/cooperative_cuisine/pygame_2d_vis/gui.py b/cooperative_cuisine/pygame_2d_vis/gui.py
index a8db7686..bb5d31e6 100644
--- a/cooperative_cuisine/pygame_2d_vis/gui.py
+++ b/cooperative_cuisine/pygame_2d_vis/gui.py
@@ -189,6 +189,8 @@ class PyGameGUI:
 
         self.last_state: StateRepresentation
 
+        self.player_info = {"0": {"name": "0"}}
+        self.level_info = {"name": "Level", "recipe_graphs": []}
         self.last_level = False
         self.beeped_once = False
         self.all_completed_meals = []
@@ -1023,13 +1025,12 @@ class PyGameGUI:
         if self.CONNECT_WITH_STUDY_SERVER:
             self.send_level_done()
         else:
-            self.stop_game_on_server("finished_button_pressed")
+            pass
+            # self.stop_game_on_server("finished_button_pressed")
         self.disconnect_websockets()
 
         self.update_postgame_screen(self.last_state)
         self.update_screen_elements()
-        for el in self.last_completed_meals:
-            el.show()
         self.beeped_once = False
 
     def draw_game_screen_frame(self):
@@ -1145,8 +1146,7 @@ class PyGameGUI:
             environment_config = file.read()
         num_players = 1 if tutorial else self.number_players
 
-        seed = 1234
-        print("GUI MANAGER ID", self.manager_id)
+        seed = int(random.random() * 100000)
         creation_json = CreateEnvironmentConfig(
             manager_id=self.manager_id,
             number_players=num_players,
@@ -1164,6 +1164,8 @@ class PyGameGUI:
         )
         if env_info.status_code == 403:
             raise ValueError(f"Forbidden Request: {env_info.json()['detail']}")
+        elif env_info.status_code == 409:
+            print("CONFLICT")
         env_info = env_info.json()
         assert isinstance(env_info, dict), "Env info must be a dictionary"
         self.current_env_id = env_info["env_id"]
@@ -1549,18 +1551,17 @@ class PyGameGUI:
         _ = requests.post(f"{self.request_url}/level_done/{self.participant_id}").json()
 
     def button_continue_postgame_pressed(self):
-        if not self.CONNECT_WITH_STUDY_SERVER:
+        if self.CONNECT_WITH_STUDY_SERVER:
+            if not self.last_level:
+                self.get_game_connection(tutorial=False)
+        else:
             self.current_layout_idx += 1
+            self.create_env_on_game_server(tutorial=False)
             if self.current_layout_idx == len(self.layout_file_paths) - 1:
                 self.last_level = True
             else:
                 log.debug(f"LEVEL: {self.layout_file_paths[self.current_layout_idx]}")
-        else:
-            if not self.last_level:
-                if self.CONNECT_WITH_STUDY_SERVER:
-                    self.get_game_connection(tutorial=False)
-                else:
-                    self.create_env_on_game_server(tutorial=False)
+
         self.menu_state = MenuStates.PreGame
 
     def manage_button_event(self, event):
-- 
GitLab