Skip to content
Snippets Groups Projects
Commit 60debf46 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Updates

parent 30577473
No related branches found
No related tags found
1 merge request!26Resolve "api"
Pipeline #44557 failed
......@@ -30,16 +30,25 @@ async def lifespan(app: FastAPI):
app = FastAPI(lifespan=lifespan)
WEBSOCKET_URL = "localhost"
WEBSOCKET_PORT = 8000
class OvercookedAPI:
class GameServer:
simulator: Simulator
def __init__(self):
self.setup_game()
self.envs = {int: Simulator}
def create_env(self, n_players: int) -> (int, list[WebSocket]):
pass
def add_player(self, env_id) -> (int, WebSocket):
pass
def setup_game(self):
self.simulator = Simulator(
ROOT_DIR / "game_content" / "environment_config.yaml",
......@@ -80,10 +89,10 @@ class ConnectionManager:
manager = ConnectionManager()
oc_api: OvercookedAPI = OvercookedAPI()
oc_api: GameServer = GameServer()
def parse_action(message: str) -> Action:
def parse_websocket_action(message: str) -> Action:
if message.replace('"', "") != "get_state":
message_dict = json.loads(message)
if message_dict["act_type"] == "movement":
......@@ -111,7 +120,7 @@ def parse_action(message: str) -> Action:
return action
def manage_message(message: str):
def manage_websocket_message(message: str):
if "get_state" in message:
return oc_api.get_state()
......@@ -119,7 +128,7 @@ def manage_message(message: str):
oc_api.reset_game()
return "Reset game."
action = parse_action(message)
action = parse_websocket_action(message)
oc_api.simulator.enter_action(action)
answer = oc_api.get_state()
return answer
......@@ -137,7 +146,7 @@ async def websocket_endpoint(websocket: WebSocket, client_id: int):
try:
while True:
message = await websocket.receive_text()
answer = manage_message(message)
answer = manage_websocket_message(message)
await manager.send_personal_message(answer, websocket)
except WebSocketDisconnect:
......
......@@ -303,7 +303,6 @@ class Environment:
for character in line:
character = character.capitalize()
pos = np.array([current_x, current_y])
print(pos)
counter_class = self.SYMBOL_TO_CHARACTER_MAP[character]
if not isinstance(counter_class, str):
counter = counter_class(pos)
......
......@@ -46,7 +46,6 @@ class Player:
self.facing_point: npt.NDArray[float] = np.zeros(2, float)
self.current_movement: npt.NDArray[2] = np.zeros(2, float)
print(datetime.datetime.min)
self.movement_until: datetime.datetime = datetime.datetime.min
def set_movement(self, move_vector, move_until):
......
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