mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add threat zone support to the new map.
https://github.com/dcs-liberation/dcs_liberation/issues/2039
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
49
client/src/api/threatZonesSlice.ts
Normal file
49
client/src/api/threatZonesSlice.ts
Normal 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;
|
||||
Reference in New Issue
Block a user