50 lines
1.7 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
from pydantic import BaseModel
from game.server.controlpoints.models import ControlPointJs
from game.server.flights.models import FlightJs
from game.server.frontlines.models import FrontLineJs
from game.server.leaflet import LeafletPoint
from game.server.mapzones.models import ThreatZoneContainerJs, UnculledZoneJs
from game.server.navmesh.models import NavMeshesJs
from game.server.supplyroutes.models import SupplyRouteJs
from game.server.tgos.models import TgoJs
from game.server.iadsnetwork.models import IadsConnectionJs, IadsNetworkJs
if TYPE_CHECKING:
from game import Game
class GameJs(BaseModel):
control_points: list[ControlPointJs]
tgos: list[TgoJs]
supply_routes: list[SupplyRouteJs]
front_lines: list[FrontLineJs]
flights: list[FlightJs]
iads_network: IadsNetworkJs
threat_zones: ThreatZoneContainerJs
navmeshes: NavMeshesJs
map_center: LeafletPoint | None
unculled_zones: list[UnculledZoneJs]
class Config:
title = "Game"
@staticmethod
def from_game(game: Game) -> GameJs:
return GameJs(
control_points=ControlPointJs.all_in_game(game),
tgos=TgoJs.all_in_game(game),
supply_routes=SupplyRouteJs.all_in_game(game),
front_lines=FrontLineJs.all_in_game(game),
flights=FlightJs.all_in_game(game, with_waypoints=True),
iads_network=IadsNetworkJs.from_network(game.theater.iads_network),
threat_zones=ThreatZoneContainerJs.for_game(game),
navmeshes=NavMeshesJs.from_game(game),
map_center=game.theater.terrain.map_view_default.position.latlng(),
unculled_zones=UnculledZoneJs.from_game(game),
)