Integrated WS server
This commit is contained in:
@ -1,11 +1,22 @@
|
||||
from hopper.engine import GameEngine, GameEngineFactory
|
||||
from typing import Optional
|
||||
|
||||
game_engine: GameEngine
|
||||
from hopper.engine import GameEngine, GameEngineFactory
|
||||
from hopper.ws_server import WSServer
|
||||
|
||||
game_engine: Optional[GameEngine] = None
|
||||
|
||||
|
||||
def create_game_engine() -> GameEngine:
|
||||
global game_engine
|
||||
game_engine = GameEngineFactory.create_default()
|
||||
|
||||
if game_engine:
|
||||
raise RuntimeError("Can't call create_game_engine() more than once!")
|
||||
|
||||
ws_server = WSServer(daemon=True)
|
||||
ws_server.start()
|
||||
|
||||
game_engine = GameEngineFactory.create_default(ws_server=ws_server)
|
||||
|
||||
return game_engine
|
||||
|
||||
|
||||
|
||||
@ -15,7 +15,6 @@ from hopper.api.dto import (
|
||||
from hopper.engine import GameEngine
|
||||
from hopper.enums import Direction, PlayerMoveResult
|
||||
from hopper.errors import Collision, PositionOutOfBounds
|
||||
from hopper.ws_client import ws_send_game_state
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user