mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix FastAPI doc pages.
We can't directly use frozen dataclasses from pydcs in our interface because pydantic can't process them. Pydantic is able to automatically convert to our modelview type from the pydcs type though.
This commit is contained in:
parent
45e76e12b6
commit
d6e82d44fc
@ -2,10 +2,9 @@ from __future__ import annotations
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
from dcs.mapping import LatLng
|
||||
from pydantic import BaseModel
|
||||
|
||||
from game.server.leaflet import LeafletPoly, ShapelyUtil
|
||||
from game.server.leaflet import LeafletPoint, LeafletPoly, ShapelyUtil
|
||||
from game.sim.combat import FrozenCombat
|
||||
from game.sim.combat.aircombat import AirCombat
|
||||
from game.sim.combat.atip import AtIp
|
||||
@ -15,8 +14,8 @@ from game.theater import ConflictTheater
|
||||
|
||||
class FrozenCombatJs(BaseModel):
|
||||
id: UUID
|
||||
flight_position: LatLng | None
|
||||
target_positions: list[LatLng] | None
|
||||
flight_position: LeafletPoint | None
|
||||
target_positions: list[LeafletPoint] | None
|
||||
footprint: list[LeafletPoly] | None
|
||||
|
||||
@staticmethod
|
||||
|
||||
@ -2,17 +2,17 @@ from __future__ import annotations
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
from dcs.mapping import LatLng
|
||||
from pydantic import BaseModel
|
||||
|
||||
from game.ato import Flight
|
||||
from game.ato.flightstate import InFlight
|
||||
from game.server.leaflet import LeafletPoint
|
||||
|
||||
|
||||
class FlightJs(BaseModel):
|
||||
id: UUID
|
||||
blue: bool
|
||||
position: LatLng | None
|
||||
position: LeafletPoint | None
|
||||
|
||||
@staticmethod
|
||||
def for_flight(flight: Flight) -> FlightJs:
|
||||
|
||||
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
from typing import Union
|
||||
|
||||
from dcs import Point
|
||||
from pydantic import BaseModel
|
||||
from shapely.geometry import LineString, MultiLineString, MultiPolygon, Polygon
|
||||
|
||||
from game.theater import ConflictTheater
|
||||
@ -11,6 +12,14 @@ LeafletLatLon = list[float]
|
||||
LeafletPoly = list[LeafletLatLon]
|
||||
|
||||
|
||||
class LeafletPoint(BaseModel):
|
||||
lat: float
|
||||
lng: float
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class ShapelyUtil:
|
||||
@staticmethod
|
||||
def poly_to_leaflet(poly: Polygon, theater: ConflictTheater) -> LeafletPoly:
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dcs.mapping import LatLng
|
||||
from pydantic import BaseModel
|
||||
|
||||
from game.server.leaflet import LeafletPoly, ShapelyUtil
|
||||
from game.server.leaflet import LeafletPoint, LeafletPoly, ShapelyUtil
|
||||
from game.theater import ConflictTheater
|
||||
from game.threatzones import ThreatZones
|
||||
|
||||
@ -15,7 +14,7 @@ class MapZonesJs(BaseModel):
|
||||
|
||||
|
||||
class UnculledZoneJs(BaseModel):
|
||||
position: LatLng
|
||||
position: LeafletPoint
|
||||
radius: float
|
||||
|
||||
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dcs.mapping import LatLng
|
||||
from pydantic.dataclasses import dataclass
|
||||
from pydantic import BaseModel
|
||||
|
||||
from game.ato import FlightWaypoint
|
||||
from game.ato.flightwaypointtype import FlightWaypointType
|
||||
from game.server.leaflet import LeafletPoint
|
||||
|
||||
|
||||
@dataclass
|
||||
class FlightWaypointJs:
|
||||
class FlightWaypointJs(BaseModel):
|
||||
name: str
|
||||
position: LatLng
|
||||
position: LeafletPoint
|
||||
altitude_ft: float
|
||||
altitude_reference: str
|
||||
is_movable: bool
|
||||
|
||||
@ -8,6 +8,7 @@ from game import Game
|
||||
from game.ato.flightwaypoint import FlightWaypoint
|
||||
from game.ato.flightwaypointtype import FlightWaypointType
|
||||
from game.server import GameContext
|
||||
from game.server.leaflet import LeafletPoint
|
||||
from game.server.waypoints.models import FlightWaypointJs
|
||||
from game.utils import meters
|
||||
|
||||
@ -37,7 +38,7 @@ def all_waypoints_for_flight(
|
||||
def set_position(
|
||||
flight_id: UUID,
|
||||
waypoint_idx: int,
|
||||
position: LatLng,
|
||||
position: LeafletPoint,
|
||||
game: Game = Depends(GameContext.get),
|
||||
) -> None:
|
||||
flight = game.db.flights.get(flight_id)
|
||||
@ -45,7 +46,9 @@ def set_position(
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
waypoint = flight.flight_plan.waypoints[waypoint_idx - 1]
|
||||
waypoint.position = Point.from_latlng(position, game.theater.terrain)
|
||||
waypoint.position = Point.from_latlng(
|
||||
LatLng(position.lat, position.lng), game.theater.terrain
|
||||
)
|
||||
package_model = (
|
||||
GameContext.get_model()
|
||||
.ato_model_for(flight.blue)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user