mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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
33 lines
803 B
TypeScript
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;
|