mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
operation_ids give us better function names when generating the typescript API from the openapi.json. BaseModel.Config.title does the same for type names. Response models (or 204 status codes) need to be explicit or the API will be declared as returning any.
52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from game.server.leaflet import LeafletPoint, LeafletPoly, ShapelyUtil
|
|
from game.theater import ConflictTheater
|
|
from game.threatzones import ThreatZones
|
|
|
|
|
|
class MapZonesJs(BaseModel):
|
|
inclusion: list[LeafletPoly]
|
|
exclusion: list[LeafletPoly]
|
|
sea: list[LeafletPoly]
|
|
|
|
class Config:
|
|
title = "MapZones"
|
|
|
|
|
|
class UnculledZoneJs(BaseModel):
|
|
position: LeafletPoint
|
|
radius: float
|
|
|
|
class Config:
|
|
title = "UnculledZone"
|
|
|
|
|
|
class ThreatZonesJs(BaseModel):
|
|
full: list[LeafletPoly]
|
|
aircraft: list[LeafletPoly]
|
|
air_defenses: list[LeafletPoly]
|
|
radar_sams: list[LeafletPoly]
|
|
|
|
class Config:
|
|
title = "ThreatZones"
|
|
|
|
@classmethod
|
|
def from_zones(cls, zones: ThreatZones, theater: ConflictTheater) -> ThreatZonesJs:
|
|
return ThreatZonesJs(
|
|
full=ShapelyUtil.polys_to_leaflet(zones.all, theater),
|
|
aircraft=ShapelyUtil.polys_to_leaflet(zones.airbases, theater),
|
|
air_defenses=ShapelyUtil.polys_to_leaflet(zones.air_defenses, theater),
|
|
radar_sams=ShapelyUtil.polys_to_leaflet(zones.radar_sam_threats, theater),
|
|
)
|
|
|
|
|
|
class ThreatZoneContainerJs(BaseModel):
|
|
blue: ThreatZonesJs
|
|
red: ThreatZonesJs
|
|
|
|
class Config:
|
|
title = "ThreatZoneContainer"
|