mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user