mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +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.
36 lines
1008 B
Python
36 lines
1008 B
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
from uuid import UUID
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from game.server.leaflet import LeafletPoint
|
|
from game.utils import nautical_miles
|
|
|
|
if TYPE_CHECKING:
|
|
from game import Game
|
|
from game.theater import FrontLine
|
|
|
|
|
|
class FrontLineJs(BaseModel):
|
|
id: UUID
|
|
extents: list[LeafletPoint]
|
|
|
|
class Config:
|
|
title = "FrontLine"
|
|
|
|
@staticmethod
|
|
def for_front_line(front_line: FrontLine) -> FrontLineJs:
|
|
a = front_line.position.point_from_heading(
|
|
front_line.attack_heading.right.degrees, nautical_miles(2).meters
|
|
)
|
|
b = front_line.position.point_from_heading(
|
|
front_line.attack_heading.left.degrees, nautical_miles(2).meters
|
|
)
|
|
return FrontLineJs(id=front_line.id, extents=[a.latlng(), b.latlng()])
|
|
|
|
@staticmethod
|
|
def all_in_game(game: Game) -> list[FrontLineJs]:
|
|
return [FrontLineJs.for_front_line(f) for f in game.theater.conflicts()]
|