mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
This allows unique identification across saves. The front-end needs to be able to differentiate the first carrier in game A and the first carrier in game B, but because carriers (and other non-airfield CPs) are assigned IDs sequentially, collisions were to be expected. The front-end can't tell the difference between a reloaded game and a new turn, so we need to ensure different IDs across games. This is a handy cleanup anyway, since callers constructing CPs no longer need to manually track the CP ID counter. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2078.
47 lines
1.2 KiB
Python
47 lines
1.2 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()
|
|
return ControlPointJs(
|
|
id=control_point.id,
|
|
name=control_point.name,
|
|
blue=control_point.captured,
|
|
position=control_point.position.latlng(),
|
|
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
|
|
]
|