mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +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
25 lines
658 B
TypeScript
25 lines
658 B
TypeScript
import { AppDispatch } from "../app/store";
|
|
import { gameLoaded, gameUnloaded } from "./actions";
|
|
import backend from "./backend";
|
|
import Game from "./game";
|
|
|
|
export default function reloadGameState(
|
|
dispatch: AppDispatch,
|
|
ignoreRecenter: boolean = false
|
|
) {
|
|
backend
|
|
.get("/game")
|
|
.catch((error) => console.log(`Error fetching game state: ${error}`))
|
|
.then((response) => {
|
|
if (response == null || response.data == null) {
|
|
dispatch(gameUnloaded());
|
|
return;
|
|
}
|
|
const game = response.data as Game;
|
|
if (ignoreRecenter) {
|
|
game.map_center = null;
|
|
}
|
|
dispatch(gameLoaded(game));
|
|
});
|
|
}
|