Dan Albert 7bc35ef7f4 Update most Python dependencies.
A lot of the dependency versions we have pinned don't have wheels for
Python 3.12. Update almost all of them so we can upgrade Python.

The few that weren't upgraded here are black and mypy, since those will
be a bit invasive, and Pillow, which has an API change I don't want to
deal with right now (I've got a commit on another machine that has
already done the migration, so I'll do it later).
2023-11-30 20:24:28 -08:00

57 lines
1.7 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 TheaterGroundObject
class TgoJs(BaseModel):
id: UUID
name: str
control_point_name: str
category: str
blue: bool
position: LeafletPoint
units: list[str] # TODO: Event stream
threat_ranges: list[float] # TODO: Event stream
detection_ranges: list[float] # TODO: Event stream
dead: bool # TODO: Event stream
sidc: str # TODO: Event stream
class Config:
title = "Tgo"
@staticmethod
def for_tgo(tgo: TheaterGroundObject) -> TgoJs:
threat_ranges = [group.max_threat_range().meters for group in tgo.groups]
detection_ranges = [group.max_detection_range().meters for group in tgo.groups]
return TgoJs(
id=tgo.id,
name=tgo.name,
control_point_name=tgo.control_point.name,
category=tgo.category,
blue=tgo.control_point.captured,
position=LeafletPoint.from_pydcs(tgo.position),
units=[unit.display_name for unit in tgo.units],
threat_ranges=threat_ranges,
detection_ranges=detection_ranges,
dead=tgo.is_dead,
sidc=str(tgo.sidc()),
)
@staticmethod
def all_in_game(game: Game) -> list[TgoJs]:
tgos = []
for control_point in game.theater.controlpoints:
for tgo in control_point.connected_objectives:
if not tgo.is_control_point:
tgos.append(TgoJs.for_tgo(tgo))
return tgos