mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Draw flight plan paths in the react UI.
https://github.com/dcs-liberation/dcs_liberation/issues/2039
This commit is contained in:
@@ -46,7 +46,9 @@ class GameUpdateEventsJs(BaseModel):
|
||||
navmesh_updates=events.navmesh_updates,
|
||||
unculled_zones_updated=events.unculled_zones_updated,
|
||||
threat_zones_updated=events.threat_zones_updated,
|
||||
new_flights=[FlightJs.for_flight(f) for f in events.new_flights],
|
||||
new_flights=[
|
||||
FlightJs.for_flight(f, with_waypoints=True) for f in events.new_flights
|
||||
],
|
||||
updated_flights=events.updated_flights,
|
||||
deleted_flights=events.deleted_flights,
|
||||
selected_flight=events.selected_flight,
|
||||
|
||||
@@ -7,6 +7,8 @@ from pydantic import BaseModel
|
||||
from game.ato import Flight
|
||||
from game.ato.flightstate import InFlight
|
||||
from game.server.leaflet import LeafletPoint
|
||||
from game.server.waypoints.models import FlightWaypointJs
|
||||
from game.server.waypoints.routes import waypoints_for_flight
|
||||
|
||||
|
||||
class FlightJs(BaseModel):
|
||||
@@ -14,9 +16,10 @@ class FlightJs(BaseModel):
|
||||
blue: bool
|
||||
position: LeafletPoint | None
|
||||
sidc: str
|
||||
waypoints: list[FlightWaypointJs] | None
|
||||
|
||||
@staticmethod
|
||||
def for_flight(flight: Flight) -> FlightJs:
|
||||
def for_flight(flight: Flight, with_waypoints: bool) -> FlightJs:
|
||||
# Don't provide a location for aircraft that aren't in the air. Later we can
|
||||
# expand the model to include the state data for the UI so that it can make its
|
||||
# own decisions about whether or not to draw the aircraft, but for now we'll
|
||||
@@ -24,6 +27,13 @@ class FlightJs(BaseModel):
|
||||
position = None
|
||||
if isinstance(flight.state, InFlight):
|
||||
position = flight.position().latlng()
|
||||
waypoints = None
|
||||
if with_waypoints:
|
||||
waypoints = waypoints_for_flight(flight)
|
||||
return FlightJs(
|
||||
id=flight.id, blue=flight.blue, position=position, sidc=str(flight.sidc())
|
||||
id=flight.id,
|
||||
blue=flight.blue,
|
||||
position=position,
|
||||
sidc=str(flight.sidc()),
|
||||
waypoints=waypoints,
|
||||
)
|
||||
|
||||
@@ -13,19 +13,23 @@ router: APIRouter = APIRouter(prefix="/flights")
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def list_flights(game: Game = Depends(GameContext.get)) -> list[FlightJs]:
|
||||
def list_flights(
|
||||
with_waypoints: bool = False, game: Game = Depends(GameContext.get)
|
||||
) -> list[FlightJs]:
|
||||
flights = []
|
||||
for coalition in game.coalitions:
|
||||
for package in coalition.ato.packages:
|
||||
for flight in package.flights:
|
||||
flights.append(FlightJs.for_flight(flight))
|
||||
flights.append(FlightJs.for_flight(flight, with_waypoints))
|
||||
return flights
|
||||
|
||||
|
||||
@router.get("/{flight_id}")
|
||||
def get_flight(flight_id: UUID, game: Game = Depends(GameContext.get)) -> FlightJs:
|
||||
def get_flight(
|
||||
flight_id: UUID, with_waypoints: bool = False, game: Game = Depends(GameContext.get)
|
||||
) -> FlightJs:
|
||||
flight = game.db.flights.get(flight_id)
|
||||
return FlightJs.for_flight(flight)
|
||||
return FlightJs.for_flight(flight, with_waypoints)
|
||||
|
||||
|
||||
@router.get("/{flight_id}/commit-boundary")
|
||||
|
||||
@@ -5,6 +5,7 @@ from dcs.mapping import LatLng, Point
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from game import Game
|
||||
from game.ato import Flight
|
||||
from game.ato.flightwaypoint import FlightWaypoint
|
||||
from game.ato.flightwaypointtype import FlightWaypointType
|
||||
from game.server import GameContext
|
||||
@@ -15,11 +16,7 @@ from game.utils import meters
|
||||
router: APIRouter = APIRouter(prefix="/waypoints")
|
||||
|
||||
|
||||
@router.get("/{flight_id}", response_model=list[FlightWaypointJs])
|
||||
def all_waypoints_for_flight(
|
||||
flight_id: UUID, game: Game = Depends(GameContext.get)
|
||||
) -> list[FlightWaypointJs]:
|
||||
flight = game.db.flights.get(flight_id)
|
||||
def waypoints_for_flight(flight: Flight) -> list[FlightWaypointJs]:
|
||||
departure = FlightWaypointJs.for_waypoint(
|
||||
FlightWaypoint(
|
||||
"TAKEOFF",
|
||||
@@ -34,6 +31,13 @@ def all_waypoints_for_flight(
|
||||
]
|
||||
|
||||
|
||||
@router.get("/{flight_id}", response_model=list[FlightWaypointJs])
|
||||
def all_waypoints_for_flight(
|
||||
flight_id: UUID, game: Game = Depends(GameContext.get)
|
||||
) -> list[FlightWaypointJs]:
|
||||
return waypoints_for_flight(game.db.flights.get(flight_id))
|
||||
|
||||
|
||||
@router.post("/{flight_id}/{waypoint_idx}/position")
|
||||
def set_position(
|
||||
flight_id: UUID,
|
||||
|
||||
Reference in New Issue
Block a user