Add threat zone support to the new map.

https://github.com/dcs-liberation/dcs_liberation/issues/2039
This commit is contained in:
Dan Albert
2022-03-06 19:30:23 -08:00
parent 30aebf2546
commit dc4762a03b
12 changed files with 199 additions and 5 deletions

View File

@@ -21,8 +21,10 @@ import {
} from "./frontLinesSlice";
import FrontLine from "./frontline";
import reloadGameState from "./gamestate";
import { liberationApi } from "./liberationApi";
import Tgo from "./tgo";
import { updateTgo } from "./tgosSlice";
import { threatZonesUpdated } from "./threatZonesSlice";
import { LatLng } from "leaflet";
interface GameUpdateEvents {
@@ -68,6 +70,16 @@ export const handleStreamedEvents = (
dispatch(endCombat(id));
}
if (events.threat_zones_updated) {
dispatch(liberationApi.endpoints.getThreatZones.initiate()).then(
(result) => {
if (result.data) {
dispatch(threatZonesUpdated(result.data));
}
}
);
}
for (const flight of events.new_flights) {
dispatch(registerFlight(flight));
}

View File

@@ -1,6 +1,7 @@
import { ControlPoint } from "./controlpoint";
import { Flight } from "./flight";
import FrontLine from "./frontline";
import { ThreatZoneContainer } from "./liberationApi";
import SupplyRoute from "./supplyroute";
import Tgo from "./tgo";
import { LatLngLiteral } from "leaflet";
@@ -11,5 +12,6 @@ export default interface Game {
supply_routes: SupplyRoute[];
front_lines: FrontLine[];
flights: Flight[];
threat_zones: ThreatZoneContainer;
map_center: LatLngLiteral | null;
}

View File

@@ -0,0 +1,49 @@
import { RootState } from "../app/store";
import { gameLoaded, gameUnloaded } from "./actions";
import { ThreatZoneContainer } from "./liberationApi";
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
interface ThreatZonesState {
zones: ThreatZoneContainer;
}
const initialState: ThreatZonesState = {
zones: {
blue: {
full: [],
aircraft: [],
air_defenses: [],
radar_sams: [],
},
red: {
full: [],
aircraft: [],
air_defenses: [],
radar_sams: [],
},
},
};
export const threatZonesSlice = createSlice({
name: "threatZonesState",
initialState,
reducers: {
updated: (state, action: PayloadAction<ThreatZoneContainer>) => {
state.zones = action.payload;
},
},
extraReducers: (builder) => {
builder.addCase(gameLoaded, (state, action) => {
state.zones = action.payload.threat_zones;
});
builder.addCase(gameUnloaded, (state) => {
state.zones = initialState.zones;
});
},
});
export const { updated: threatZonesUpdated } = threatZonesSlice.actions;
export const selectThreatZones = (state: RootState) => state.threatZones;
export default threatZonesSlice.reducer;