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

@@ -208,25 +208,25 @@ export type ListControlPointsApiArg = void;
export type GetControlPointByIdApiResponse =
/** status 200 Successful Response */ ControlPoint;
export type GetControlPointByIdApiArg = {
cpId: number;
cpId: string;
};
export type ControlPointDestinationInRangeApiResponse =
/** status 200 Successful Response */ boolean;
export type ControlPointDestinationInRangeApiArg = {
cpId: number;
cpId: string;
lat: number;
lng: number;
};
export type SetControlPointDestinationApiResponse =
/** status 204 Successful Response */ undefined;
export type SetControlPointDestinationApiArg = {
cpId: number;
cpId: string;
body: LatLng;
};
export type ClearControlPointDestinationApiResponse =
/** status 204 Successful Response */ undefined;
export type ClearControlPointDestinationApiArg = {
cpId: number;
cpId: string;
};
export type GetDebugHoldZonesApiResponse =
/** status 200 Successful Response */ HoldZones;
@@ -302,12 +302,12 @@ export type OpenTgoInfoDialogApiArg = {
export type OpenNewControlPointPackageDialogApiResponse =
/** status 204 Successful Response */ undefined;
export type OpenNewControlPointPackageDialogApiArg = {
cpId: number;
cpId: string;
};
export type OpenControlPointInfoDialogApiResponse =
/** status 204 Successful Response */ undefined;
export type OpenControlPointInfoDialogApiArg = {
cpId: number;
cpId: string;
};
export type ListSupplyRoutesApiResponse =
/** status 200 Successful Response */ SupplyRoute[];
@@ -335,7 +335,7 @@ export type LatLng = {
lng: number;
};
export type ControlPoint = {
id: number;
id: string;
name: string;
blue: boolean;
position: LatLng;

View File

@@ -4,7 +4,7 @@ import { ControlPoint } from "./liberationApi";
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
interface ControlPointsState {
controlPoints: { [key: number]: ControlPoint };
controlPoints: { [key: string]: ControlPoint };
}
const initialState: ControlPointsState = {
@@ -23,7 +23,7 @@ export const controlPointsSlice = createSlice({
extraReducers: (builder) => {
builder.addCase(gameLoaded, (state, action) => {
state.controlPoints = action.payload.control_points.reduce(
(acc: { [key: number]: ControlPoint }, curr) => {
(acc: { [key: string]: ControlPoint }, curr) => {
acc[curr.id] = curr;
return acc;
},

View File

@@ -9,7 +9,7 @@ export default function ControlPointsLayer() {
<LayerGroup>
{Object.values(controlPoints.controlPoints).map((controlPoint) => {
return (
<ControlPoint key={controlPoint.name} controlPoint={controlPoint} />
<ControlPoint key={controlPoint.id} controlPoint={controlPoint} />
);
})}
</LayerGroup>