mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Sync MapZones when changing campaigns
This commit is contained in:
@@ -466,6 +466,7 @@ export type Game = {
|
||||
navmeshes: NavMeshes;
|
||||
map_center?: LatLng;
|
||||
unculled_zones: UnculledZone[];
|
||||
map_zones: MapZones;
|
||||
};
|
||||
export type MapZones = {
|
||||
inclusion: LatLng[][][];
|
||||
|
||||
35
client/src/api/mapZonesSlice.ts
Normal file
35
client/src/api/mapZonesSlice.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { RootState } from "../app/store";
|
||||
import { gameLoaded, gameUnloaded } from "./actions";
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { LatLngLiteral } from "leaflet";
|
||||
import { MapZones } from "./_liberationApi";
|
||||
|
||||
interface MapZonesState {
|
||||
mapZones: MapZones;
|
||||
}
|
||||
|
||||
const initialState: MapZonesState = {
|
||||
mapZones: { inclusion: [], exclusion: [], sea: [] },
|
||||
};
|
||||
|
||||
const mapZonesSlice = createSlice({
|
||||
name: "map",
|
||||
initialState: initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder.addCase(gameLoaded, (state, action) => {
|
||||
if (action.payload != null) {
|
||||
state.mapZones.exclusion = action.payload.map_zones.exclusion;
|
||||
state.mapZones.inclusion = action.payload.map_zones.inclusion;
|
||||
state.mapZones.sea = action.payload.map_zones.sea;
|
||||
}
|
||||
});
|
||||
builder.addCase(gameUnloaded, (state) => {
|
||||
state.mapZones = initialState.mapZones;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const selectMapZones = (state: RootState) => state.mapZones;
|
||||
|
||||
export default mapZonesSlice.reducer;
|
||||
Reference in New Issue
Block a user