Handle map reset when the game is loaded/unloaded.

https://github.com/dcs-liberation/dcs_liberation/issues/2039

Partial fix for
https://github.com/dcs-liberation/dcs_liberation/issues/2045 (now works
in the new map, old one not fixed yet).
This commit is contained in:
Dan Albert
2022-03-05 18:02:46 -08:00
parent 995e28cb32
commit 73fcfcec7b
37 changed files with 403 additions and 178 deletions

View File

@@ -1,15 +1,19 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from uuid import UUID
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
if TYPE_CHECKING:
from game import Game
from game.ato import Flight
class FlightJs(BaseModel):
id: UUID
@@ -37,3 +41,12 @@ class FlightJs(BaseModel):
sidc=str(flight.sidc()),
waypoints=waypoints,
)
@staticmethod
def all_in_game(game: Game, with_waypoints: bool) -> 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, with_waypoints))
return flights

View File

@@ -14,19 +14,16 @@ router: APIRouter = APIRouter(prefix="/flights")
@router.get("/")
def list_flights(
with_waypoints: bool = False, game: Game = Depends(GameContext.get)
with_waypoints: bool = False, game: Game = Depends(GameContext.require)
) -> 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, with_waypoints))
return flights
return FlightJs.all_in_game(game, with_waypoints)
@router.get("/{flight_id}")
def get_flight(
flight_id: UUID, with_waypoints: bool = False, game: Game = Depends(GameContext.get)
flight_id: UUID,
with_waypoints: bool = False,
game: Game = Depends(GameContext.require),
) -> FlightJs:
flight = game.db.flights.get(flight_id)
return FlightJs.for_flight(flight, with_waypoints)
@@ -34,7 +31,7 @@ def get_flight(
@router.get("/{flight_id}/commit-boundary")
def commit_boundary(
flight_id: UUID, game: Game = Depends(GameContext.get)
flight_id: UUID, game: Game = Depends(GameContext.require)
) -> LeafletPoly:
flight = game.db.flights.get(flight_id)
if not isinstance(flight.flight_plan, PatrollingFlightPlan):