Partial implementation of TGO display.

No threat/detection circles yet.

https://github.com/dcs-liberation/dcs_liberation/issues/2039
This commit is contained in:
Dan Albert
2022-03-02 00:57:58 -08:00
parent 1cd77a4a77
commit 64b01c471b
13 changed files with 216 additions and 0 deletions

23
client/src/api/tgo.ts Normal file
View File

@@ -0,0 +1,23 @@
import { LatLng } from "leaflet";
export enum TgoType {
AIR_DEFENSE = "Air defenses",
FACTORY = "Factories",
SHIP = "Ships",
OTHER = "Other ground objects",
}
export interface Tgo {
name: string;
control_point_name: string;
category: string;
blue: boolean;
position: LatLng;
units: string[];
threat_ranges: number[];
detection_ranges: number[];
dead: boolean;
sidc: string;
}
export default Tgo;

View File

@@ -0,0 +1,51 @@
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import { Tgo, TgoType } from "./tgo";
import { RootState } from "../app/store";
interface TgosState {
tgosByType: { [key: string]: Tgo[] };
}
const initialState: TgosState = {
tgosByType: Object.fromEntries(
Object.values(TgoType).map((key) => [key, []])
),
};
export const tgosSlice = createSlice({
name: "tgos",
initialState,
reducers: {
setTgos: (state, action: PayloadAction<Tgo[]>) => {
state.tgosByType = initialState.tgosByType;
for (const key of Object.values(TgoType)) {
state.tgosByType[key] = [];
}
for (const tgo of action.payload) {
var type;
switch (tgo.category) {
case "aa":
type = TgoType.AIR_DEFENSE;
break;
case "factory":
type = TgoType.FACTORY;
break;
case "ship":
type = TgoType.SHIP;
break;
default:
type = TgoType.OTHER;
break;
}
state.tgosByType[type].push(tgo);
}
},
},
});
export const { setTgos } = tgosSlice.actions;
export const selectTgos = (state: RootState) => state.tgos;
export default tgosSlice.reducer;