mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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
This commit is contained in:
@@ -45,6 +45,7 @@ interface GameUpdateEvents {
|
||||
updated_control_points: number[];
|
||||
reset_on_map_center: LatLng | null;
|
||||
game_unloaded: boolean;
|
||||
new_turn: boolean;
|
||||
}
|
||||
|
||||
export const handleStreamedEvents = (
|
||||
@@ -126,4 +127,8 @@ export const handleStreamedEvents = (
|
||||
if (events.game_unloaded) {
|
||||
dispatch(gameUnloaded());
|
||||
}
|
||||
|
||||
if (events.new_turn) {
|
||||
reloadGameState(dispatch, true);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,5 +11,5 @@ export default interface Game {
|
||||
supply_routes: SupplyRoute[];
|
||||
front_lines: FrontLine[];
|
||||
flights: Flight[];
|
||||
map_center: LatLngLiteral;
|
||||
map_center: LatLngLiteral | null;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ import { gameLoaded, gameUnloaded } from "./actions";
|
||||
import backend from "./backend";
|
||||
import Game from "./game";
|
||||
|
||||
export default function reloadGameState(dispatch: AppDispatch) {
|
||||
export default function reloadGameState(
|
||||
dispatch: AppDispatch,
|
||||
ignoreRecenter: boolean = false
|
||||
) {
|
||||
backend
|
||||
.get("/game")
|
||||
.catch((error) => console.log(`Error fetching game state: ${error}`))
|
||||
@@ -12,6 +15,10 @@ export default function reloadGameState(dispatch: AppDispatch) {
|
||||
dispatch(gameUnloaded());
|
||||
return;
|
||||
}
|
||||
dispatch(gameLoaded(response.data as Game));
|
||||
const game = response.data as Game;
|
||||
if (ignoreRecenter) {
|
||||
game.map_center = null;
|
||||
}
|
||||
dispatch(gameLoaded(game));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ const mapSlice = createSlice({
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder.addCase(gameLoaded, (state, action) => {
|
||||
state.center = action.payload.map_center;
|
||||
if (action.payload.map_center != null) {
|
||||
state.center = action.payload.map_center;
|
||||
}
|
||||
});
|
||||
builder.addCase(gameUnloaded, (state) => {
|
||||
state.center = { lat: 0, lng: 0 };
|
||||
|
||||
Reference in New Issue
Block a user