Eclipse/Druss99 31c80dfd02 refactor of previous commits
refactor to enum

typing and many other fixes

fix tests

attempt to fix some typescript

more typescript fixes

more typescript test fixes

revert all API changes

update to pydcs

mypy fixes

Use properties to check if player is blue/red/neutral

update requirements.txt

black -_-

bump pydcs and fix mypy

add opponent property

bump pydcs
2025-10-19 19:34:38 +02:00

51 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 = control_point.target_position.latlng()
if control_point.captured.is_blue:
blue = True
else:
blue = False
return ControlPointJs(
id=control_point.id,
name=control_point.name,
blue=blue,
position=control_point.position.latlng(),
mobile=control_point.moveable and control_point.captured.is_blue,
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
]