Dan Albert 738cf1f381 Reset game state on new turn.
This may not be the way to do this long term, but it is how the old map
works so it's at least not a regression. It might be better to generate
events for the between-turn changes in state instead.

https://github.com/dcs-liberation/dcs_liberation/issues/2039
2022-03-06 00:02:25 -08:00

33 lines
803 B
TypeScript

import { RootState } from "../app/store";
import { gameLoaded, gameUnloaded } from "./actions";
import { createSlice } from "@reduxjs/toolkit";
import { LatLngLiteral } from "leaflet";
interface MapState {
center: LatLngLiteral;
}
const initialState: MapState = {
center: { lat: 0, lng: 0 },
};
const mapSlice = createSlice({
name: "map",
initialState: initialState,
reducers: {},
extraReducers: (builder) => {
builder.addCase(gameLoaded, (state, action) => {
if (action.payload.map_center != null) {
state.center = action.payload.map_center;
}
});
builder.addCase(gameUnloaded, (state) => {
state.center = { lat: 0, lng: 0 };
});
},
});
export const selectMapCenter = (state: RootState) => state.map.center;
export default mapSlice.reducer;