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

121 lines
4.7 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
from uuid import UUID
from pydantic import BaseModel
from game.server.combat.models import FrozenCombatJs
from game.server.controlpoints.models import ControlPointJs
from game.server.flights.models import FlightJs
from game.server.frontlines.models import FrontLineJs
from game.server.iadsnetwork.models import IadsConnectionJs
from game.server.leaflet import LeafletPoint
from game.server.mapzones.models import ThreatZonesJs, UnculledZoneJs
from game.server.navmesh.models import NavMeshJs
from game.server.tgos.models import TgoJs
if TYPE_CHECKING:
from game import Game
from game.sim import GameUpdateEvents
class GameUpdateEventsJs(BaseModel):
updated_flight_positions: dict[UUID, LeafletPoint]
new_combats: list[FrozenCombatJs]
updated_combats: list[FrozenCombatJs]
ended_combats: list[UUID]
navmesh_updates: dict[bool, NavMeshJs]
updated_unculled_zones: list[UnculledZoneJs]
threat_zones_updated: dict[bool, ThreatZonesJs]
new_flights: list[FlightJs]
updated_flights: list[FlightJs]
deleted_flights: set[UUID]
selected_flight: UUID | None
deselected_flight: bool
updated_front_lines: list[FrontLineJs]
deleted_front_lines: set[UUID]
updated_tgos: list[TgoJs]
updated_control_points: list[ControlPointJs]
updated_iads: list[IadsConnectionJs]
deleted_iads: set[UUID]
reset_on_map_center: LeafletPoint | None
game_unloaded: bool
new_turn: bool
@classmethod
def from_events(
cls, events: GameUpdateEvents, game: Game | None
) -> GameUpdateEventsJs:
# We still need to be able to send update events when there is no game loaded
# because we need to send the unload event.
new_combats = []
updated_combats = []
updated_navmeshes = {}
updated_threat_zones = {}
updated_unculled_zones = []
updated_iads = []
updated_front_lines = []
if game is not None:
new_combats = [
FrozenCombatJs.for_combat(c, game.theater) for c in events.new_combats
]
updated_combats = [
FrozenCombatJs.for_combat(c, game.theater)
for c in events.updated_combats
]
updated_navmeshes = {
player: NavMeshJs.from_navmesh(mesh, game)
for player, mesh in events.navmesh_updates.items()
}
updated_threat_zones = {
player: ThreatZonesJs.from_zones(zones, game.theater)
for player, zones in events.threat_zones_updated.items()
}
updated_unculled_zones = UnculledZoneJs.from_game(game)
for node in events.updated_iads:
updated_iads.extend(IadsConnectionJs.connections_for_node(node))
updated_front_lines = [
FrontLineJs.for_front_line(game.theater, f)
for f in events.updated_front_lines
]
reset_on_map_center: LeafletPoint | None = None
if events.reset_on_map_center is not None:
reset_on_map_center = LeafletPoint.from_pydcs(events.reset_on_map_center)
return GameUpdateEventsJs(
updated_flight_positions={
f[0].id: LeafletPoint.from_pydcs(f[1])
for f in events.updated_flight_positions
},
new_combats=new_combats,
updated_combats=updated_combats,
ended_combats=[c.id for c in events.ended_combats],
navmesh_updates=updated_navmeshes,
updated_unculled_zones=updated_unculled_zones,
threat_zones_updated=updated_threat_zones,
new_flights=[
FlightJs.for_flight(f, with_waypoints=True) for f in events.new_flights
],
updated_flights=[
FlightJs.for_flight(f, with_waypoints=True)
for f in events.updated_flights
],
deleted_flights=events.deleted_flights,
selected_flight=events.selected_flight,
deselected_flight=events.deselected_flight,
updated_front_lines=updated_front_lines,
deleted_front_lines=events.deleted_front_lines,
updated_tgos=[TgoJs.for_tgo(tgo) for tgo in events.updated_tgos],
updated_control_points=[
ControlPointJs.for_control_point(cp)
for cp in events.updated_control_points
],
updated_iads=updated_iads,
deleted_iads=events.deleted_iads_connections,
reset_on_map_center=reset_on_map_center,
game_unloaded=events.game_unloaded,
new_turn=events.new_turn,
)