diff --git a/client/src/api/eventstream.tsx b/client/src/api/eventstream.tsx index eeed7485..b5b5a081 100644 --- a/client/src/api/eventstream.tsx +++ b/client/src/api/eventstream.tsx @@ -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); + } }; diff --git a/client/src/api/game.ts b/client/src/api/game.ts index 04ff805e..9aca5749 100644 --- a/client/src/api/game.ts +++ b/client/src/api/game.ts @@ -11,5 +11,5 @@ export default interface Game { supply_routes: SupplyRoute[]; front_lines: FrontLine[]; flights: Flight[]; - map_center: LatLngLiteral; + map_center: LatLngLiteral | null; } diff --git a/client/src/api/gamestate.ts b/client/src/api/gamestate.ts index 3924bc46..25fe3f48 100644 --- a/client/src/api/gamestate.ts +++ b/client/src/api/gamestate.ts @@ -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)); }); } diff --git a/client/src/api/mapSlice.ts b/client/src/api/mapSlice.ts index 9906dccb..9cf74353 100644 --- a/client/src/api/mapSlice.ts +++ b/client/src/api/mapSlice.ts @@ -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 }; diff --git a/game/game.py b/game/game.py index b145d4ee..a81e686b 100644 --- a/game/game.py +++ b/game/game.py @@ -307,6 +307,7 @@ class Game: with logged_duration("Turn initialization"): self.initialize_turn(events) + events.begin_new_turn() EventStream.put_nowait(events) # Autosave progress diff --git a/game/server/eventstream/models.py b/game/server/eventstream/models.py index cde919a1..81d64dd5 100644 --- a/game/server/eventstream/models.py +++ b/game/server/eventstream/models.py @@ -35,6 +35,7 @@ class GameUpdateEventsJs(BaseModel): updated_control_points: set[int] reset_on_map_center: LeafletLatLon | None game_unloaded: bool + new_turn: bool @classmethod def from_events( @@ -85,4 +86,5 @@ class GameUpdateEventsJs(BaseModel): updated_control_points=events.updated_control_points, reset_on_map_center=recenter_map, game_unloaded=events.game_unloaded, + new_turn=events.new_turn, ) diff --git a/game/sim/gameupdateevents.py b/game/sim/gameupdateevents.py index bcd62e85..850850d6 100644 --- a/game/sim/gameupdateevents.py +++ b/game/sim/gameupdateevents.py @@ -36,6 +36,7 @@ class GameUpdateEvents: updated_control_points: set[int] = field(default_factory=set) reset_on_map_center: LatLng | None = None game_unloaded: bool = False + new_turn: bool = False shutting_down: bool = False @property @@ -136,6 +137,10 @@ class GameUpdateEvents: self.game_unloaded = False return self + def begin_new_turn(self) -> GameUpdateEvents: + self.new_turn = True + return self + def shut_down(self) -> GameUpdateEvents: self.shutting_down = True return self