mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add an endpoint for listing all control points.
This commit is contained in:
parent
e3adcada52
commit
0056747aee
@ -1,9 +1,18 @@
|
|||||||
from fastapi import Depends, FastAPI
|
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
|
from .security import ApiKeyManager
|
||||||
|
|
||||||
app = FastAPI(dependencies=[Depends(ApiKeyManager.verify)])
|
app = FastAPI(dependencies=[Depends(ApiKeyManager.verify)])
|
||||||
|
app.include_router(controlpoints.router)
|
||||||
app.include_router(debuggeometries.router)
|
app.include_router(debuggeometries.router)
|
||||||
app.include_router(eventstream.router)
|
app.include_router(eventstream.router)
|
||||||
app.include_router(flights.router)
|
app.include_router(flights.router)
|
||||||
|
|||||||
1
game/server/controlpoints/__init__.py
Normal file
1
game/server/controlpoints/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .routes import router
|
||||||
31
game/server/controlpoints/models.py
Normal file
31
game/server/controlpoints/models.py
Normal file
@ -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()),
|
||||||
|
)
|
||||||
15
game/server/controlpoints/routes.py
Normal file
15
game/server/controlpoints/routes.py
Normal file
@ -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
|
||||||
Loading…
x
Reference in New Issue
Block a user