Replace CP integer ID with a UUID.

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.
This commit is contained in:
Dan Albert
2022-03-20 15:11:58 -07:00
parent 941a7d441c
commit 039ac9ec74
21 changed files with 127 additions and 179 deletions

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from uuid import UUID
from pydantic import BaseModel
@@ -12,7 +13,7 @@ if TYPE_CHECKING:
class ControlPointJs(BaseModel):
id: int
id: UUID
name: str
blue: bool
position: LeafletPoint

View File

@@ -1,3 +1,5 @@
from uuid import UUID
from dcs import Point
from dcs.mapping import LatLng
from fastapi import APIRouter, Body, Depends, HTTPException, status
@@ -25,7 +27,7 @@ def list_control_points(
"/{cp_id}", operation_id="get_control_point_by_id", response_model=ControlPointJs
)
def get_control_point(
cp_id: int, game: Game = Depends(GameContext.require)
cp_id: UUID, game: Game = Depends(GameContext.require)
) -> ControlPointJs:
cp = game.theater.find_control_point_by_id(cp_id)
if cp is None:
@@ -42,7 +44,7 @@ def get_control_point(
response_model=bool,
)
def destination_in_range(
cp_id: int, lat: float, lng: float, game: Game = Depends(GameContext.require)
cp_id: UUID, lat: float, lng: float, game: Game = Depends(GameContext.require)
) -> bool:
cp = game.theater.find_control_point_by_id(cp_id)
if cp is None:
@@ -61,7 +63,7 @@ def destination_in_range(
status_code=status.HTTP_204_NO_CONTENT,
)
def set_destination(
cp_id: int,
cp_id: UUID,
destination: LeafletPoint = Body(..., title="destination"),
game: Game = Depends(GameContext.require),
) -> None:
@@ -96,7 +98,7 @@ def set_destination(
operation_id="clear_control_point_destination",
status_code=status.HTTP_204_NO_CONTENT,
)
def cancel_travel(cp_id: int, game: Game = Depends(GameContext.require)) -> None:
def cancel_travel(cp_id: UUID, game: Game = Depends(GameContext.require)) -> None:
cp = game.theater.find_control_point_by_id(cp_id)
if cp is None:
raise HTTPException(