Dan Albert f7141a9882 Fix a few more Pydantic conversions.
One of the newer versions got a lot more strict. It now only expects
dicts that match the model, or objects of the model. Previously it also
accepted objects which had the same properties as the model. Convert a
few more LatLngs to LeafletPoints.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/3279.
2023-12-02 12:25:01 -08:00

47 lines
1.3 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
from uuid import UUID
from pydantic import BaseModel
from game.server.leaflet import LeafletPoint
if TYPE_CHECKING:
from game import Game
from game.theater import ControlPoint
class ControlPointJs(BaseModel):
id: UUID
name: str
blue: bool
position: LeafletPoint
mobile: bool
destination: LeafletPoint | None
sidc: str
class Config:
title = "ControlPoint"
@staticmethod
def for_control_point(control_point: ControlPoint) -> ControlPointJs:
destination = None
if control_point.target_position is not None:
destination = LeafletPoint.from_pydcs(control_point.target_position)
return ControlPointJs(
id=control_point.id,
name=control_point.name,
blue=control_point.captured,
position=LeafletPoint.from_pydcs(control_point.position),
mobile=control_point.moveable and control_point.captured,
destination=destination,
sidc=str(control_point.sidc()),
)
@staticmethod
def all_in_game(game: Game) -> list[ControlPointJs]:
return [
ControlPointJs.for_control_point(cp) for cp in game.theater.controlpoints
]