Handle map reset when the game is loaded/unloaded.

https://github.com/dcs-liberation/dcs_liberation/issues/2039

Partial fix for
https://github.com/dcs-liberation/dcs_liberation/issues/2045 (now works
in the new map, old one not fixed yet).
This commit is contained in:
Dan Albert
2022-03-05 18:02:46 -08:00
parent 995e28cb32
commit 73fcfcec7b
37 changed files with 403 additions and 178 deletions

View File

@@ -1,14 +1,4 @@
import backend from "../api/backend";
import { setControlPoints } from "../api/controlPointsSlice";
import { ControlPoint } from "../api/controlpoint";
import { Flight } from "../api/flight";
import { registerFlight } from "../api/flightsSlice";
import { setFrontLines } from "../api/frontLinesSlice";
import FrontLine from "../api/frontline";
import { setSupplyRoutes } from "../api/supplyRoutesSlice";
import SupplyRoute from "../api/supplyroute";
import Tgo from "../api/tgo";
import { setTgos } from "../api/tgosSlice";
import reloadGameState from "../api/gamestate";
import { useAppDispatch } from "../app/hooks";
import { useEffect } from "react";
@@ -19,48 +9,7 @@ import { useEffect } from "react";
export const useInitialGameState = () => {
const dispatch = useAppDispatch();
useEffect(() => {
backend
.get("/control-points")
.catch((error) => console.log(`Error fetching control points: ${error}`))
.then((response) => {
if (response != null) {
dispatch(setControlPoints(response.data as ControlPoint[]));
}
});
backend
.get("/tgos")
.catch((error) => console.log(`Error fetching TGOs: ${error}`))
.then((response) => {
if (response != null) {
dispatch(setTgos(response.data as Tgo[]));
}
});
backend
.get("/supply-routes")
.catch((error) => console.log(`Error fetching supply routes: ${error}`))
.then((response) => {
if (response != null) {
dispatch(setSupplyRoutes(response.data as SupplyRoute[]));
}
});
backend
.get("/front-lines")
.catch((error) => console.log(`Error fetching front-lines: ${error}`))
.then((response) => {
if (response != null) {
dispatch(setFrontLines(response.data as FrontLine[]));
}
});
backend
.get("/flights?with_waypoints=true")
.catch((error) => console.log(`Error fetching flights: ${error}`))
.then((response) => {
if (response != null) {
for (const flight of response.data) {
dispatch(registerFlight(flight as Flight));
}
}
});
reloadGameState(dispatch);
});
};