diff --git a/game/server/app.py b/game/server/app.py index b503b08c..846d7083 100644 --- a/game/server/app.py +++ b/game/server/app.py @@ -1,9 +1,18 @@ from fastapi import Depends, FastAPI -from . import debuggeometries, eventstream, flights, mapzones, navmesh, waypoints +from . import ( + controlpoints, + debuggeometries, + eventstream, + flights, + mapzones, + navmesh, + waypoints, +) from .security import ApiKeyManager app = FastAPI(dependencies=[Depends(ApiKeyManager.verify)]) +app.include_router(controlpoints.router) app.include_router(debuggeometries.router) app.include_router(eventstream.router) app.include_router(flights.router) diff --git a/game/server/controlpoints/__init__.py b/game/server/controlpoints/__init__.py new file mode 100644 index 00000000..3a27ef1c --- /dev/null +++ b/game/server/controlpoints/__init__.py @@ -0,0 +1 @@ +from .routes import router diff --git a/game/server/controlpoints/models.py b/game/server/controlpoints/models.py new file mode 100644 index 00000000..c67129e5 --- /dev/null +++ b/game/server/controlpoints/models.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +from pydantic import BaseModel + +from game.server.leaflet import LeafletPoint +from game.theater import ControlPoint + + +class ControlPointJs(BaseModel): + id: int + name: str + blue: bool + position: LeafletPoint + mobile: bool + destination: LeafletPoint | None + sidc: str + + @staticmethod + def for_control_point(control_point: ControlPoint) -> ControlPointJs: + destination = None + if control_point.target_position is not None: + destination = control_point.target_position.latlng() + return ControlPointJs( + id=control_point.id, + name=control_point.name, + blue=control_point.captured, + position=control_point.position.latlng(), + mobile=control_point.moveable and control_point.captured, + destination=destination, + sidc=str(control_point.sidc()), + ) diff --git a/game/server/controlpoints/routes.py b/game/server/controlpoints/routes.py new file mode 100644 index 00000000..cd5b7200 --- /dev/null +++ b/game/server/controlpoints/routes.py @@ -0,0 +1,15 @@ +from fastapi import APIRouter, Depends + +from game import Game +from .models import ControlPointJs +from ..dependencies import GameContext + +router: APIRouter = APIRouter(prefix="/control-points") + + +@router.get("/") +def list_control_points(game: Game = Depends(GameContext.get)) -> list[ControlPointJs]: + control_points = [] + for control_point in game.theater.controlpoints: + control_points.append(ControlPointJs.for_control_point(control_point)) + return control_points