diff --git a/client/src/App.tsx b/client/src/App.tsx index e4862003..b6ed4c2b 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,12 +1,12 @@ import "./App.css"; -import { ControlPoint } from "./game/controlpoint"; -import { Flight } from "./game/flight"; +import { ControlPoint } from "./api/controlpoint"; +import { Flight } from "./api/flight"; import { LatLng } from "leaflet"; -import { LiberationMap } from "./map/liberationmap/LiberationMap"; +import LiberationMap from "./components/liberationmap"; import axios from "axios"; -import { registerFlight } from "./game/ato/atoSlice"; -import { setControlPoints } from "./game/theater/theaterSlice"; +import { registerFlight } from "./api/flightsSlice"; +import { setControlPoints } from "./api/controlPointsSlice"; import { useAppDispatch } from "./app/hooks"; import { useEffect } from "react"; diff --git a/client/src/api/controlPointsSlice.ts b/client/src/api/controlPointsSlice.ts new file mode 100644 index 00000000..3d0e8377 --- /dev/null +++ b/client/src/api/controlPointsSlice.ts @@ -0,0 +1,22 @@ +import { PayloadAction, createSlice } from "@reduxjs/toolkit"; + +import { ControlPoint } from "./controlpoint"; +import { RootState } from "../app/store"; + +const initialState: ControlPoint[] = []; + +export const controlPointsSlice = createSlice({ + name: "controlPoints", + initialState, + reducers: { + setControlPoints: (state, action: PayloadAction) => { + state = action.payload; + }, + }, +}); + +export const { setControlPoints } = controlPointsSlice.actions; + +export const selectControlPoints = (state: RootState) => state.controlPoints; + +export default controlPointsSlice.reducer; diff --git a/client/src/game/controlpoint.ts b/client/src/api/controlpoint.ts similarity index 100% rename from client/src/game/controlpoint.ts rename to client/src/api/controlpoint.ts diff --git a/client/src/game/flight.ts b/client/src/api/flight.ts similarity index 100% rename from client/src/game/flight.ts rename to client/src/api/flight.ts diff --git a/client/src/game/ato/atoSlice.ts b/client/src/api/flightsSlice.ts similarity index 65% rename from client/src/game/ato/atoSlice.ts rename to client/src/api/flightsSlice.ts index 4563f986..ff8fbea8 100644 --- a/client/src/game/ato/atoSlice.ts +++ b/client/src/api/flightsSlice.ts @@ -1,20 +1,20 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit"; -import { Flight } from "../flight"; -import { RootState } from "../../app/store"; +import { Flight } from "./flight"; +import { RootState } from "../app/store"; -interface AtoState { +interface FlightsState { blue: { [id: string]: Flight }; red: { [id: string]: Flight }; } -const initialState: AtoState = { +const initialState: FlightsState = { blue: {}, red: {}, }; -export const atoSlice = createSlice({ - name: "ato", +export const flightsSlice = createSlice({ + name: "flights", initialState, reducers: { clearFlights: (state) => { @@ -23,11 +23,11 @@ export const atoSlice = createSlice({ }, registerFlight: (state, action: PayloadAction) => { const flight = action.payload; - const ato = flight.blue ? state.blue : state.red; - if (flight.id in ato) { + const coalitionFlights = flight.blue ? state.blue : state.red; + if (flight.id in coalitionFlights) { console.log(`Overriding flight with ID: ${flight.id}`); } - ato[flight.id] = flight; + coalitionFlights[flight.id] = flight; }, unregisterFlight: (state, action: PayloadAction) => { const id = action.payload; @@ -46,8 +46,8 @@ export const atoSlice = createSlice({ }); export const { clearFlights, registerFlight, unregisterFlight } = - atoSlice.actions; + flightsSlice.actions; -export const selectAtos = (state: RootState) => state.atos; +export const selectFlights = (state: RootState) => state.flights; -export default atoSlice.reducer; +export default flightsSlice.reducer; diff --git a/client/src/game/waypoint.ts b/client/src/api/waypoint.ts similarity index 100% rename from client/src/game/waypoint.ts rename to client/src/api/waypoint.ts diff --git a/client/src/app/store.ts b/client/src/app/store.ts index b399b4de..baeca6dc 100644 --- a/client/src/app/store.ts +++ b/client/src/app/store.ts @@ -1,12 +1,12 @@ import { Action, ThunkAction, configureStore } from "@reduxjs/toolkit"; -import atoReducer from "../game/ato/atoSlice"; -import theaterReducer from "../game/theater/theaterSlice"; +import controlPointsReducer from "../api/controlPointsSlice"; +import flightsReducer from "../api/flightsSlice"; export const store = configureStore({ reducer: { - atos: atoReducer, - theater: theaterReducer, + flights: flightsReducer, + controlPoints: controlPointsReducer, }, }); diff --git a/client/src/map/controlpoint/ControlPoint.tsx b/client/src/components/controlpoints/ControlPoint.tsx similarity index 82% rename from client/src/map/controlpoint/ControlPoint.tsx rename to client/src/components/controlpoints/ControlPoint.tsx index 8ae70df4..1aa770a2 100644 --- a/client/src/map/controlpoint/ControlPoint.tsx +++ b/client/src/components/controlpoints/ControlPoint.tsx @@ -1,6 +1,7 @@ import { Icon, Point } from "leaflet"; import { Marker, Popup } from "react-leaflet"; -import { ControlPoint as ControlPointModel } from "../../game/controlpoint"; + +import { ControlPoint as ControlPointModel } from "../../api/controlpoint"; import { Symbol as MilSymbol } from "milsymbol"; function iconForControlPoint(cp: ControlPointModel) { @@ -19,7 +20,7 @@ interface ControlPointProps { controlPoint: ControlPointModel; } -export function ControlPoint(props: ControlPointProps) { +export default function ControlPoint(props: ControlPointProps) { return ( diff --git a/client/src/components/controlpointslayer/index.ts b/client/src/components/controlpointslayer/index.ts new file mode 100644 index 00000000..dfc5a263 --- /dev/null +++ b/client/src/components/controlpointslayer/index.ts @@ -0,0 +1 @@ +export { default } from "./ControlPointsLayer"; diff --git a/client/src/map/flightplan/FlightPlan.tsx b/client/src/components/flightplan/FlightPlan.tsx similarity index 78% rename from client/src/map/flightplan/FlightPlan.tsx rename to client/src/components/flightplan/FlightPlan.tsx index 0c2ecd5f..0674c70e 100644 --- a/client/src/map/flightplan/FlightPlan.tsx +++ b/client/src/components/flightplan/FlightPlan.tsx @@ -1,4 +1,4 @@ -import { Flight } from "../../game/flight"; +import { Flight } from "../../api/flight"; import { Polyline } from "react-leaflet"; const BLUE_PATH = "#0084ff"; @@ -9,7 +9,7 @@ interface FlightPlanProps { selected: boolean; } -export function FlightPlanPath(props: FlightPlanProps) { +function FlightPlanPath(props: FlightPlanProps) { const color = props.flight.blue ? BLUE_PATH : RED_PATH; const waypoints = props.flight.waypoints; if (waypoints == null) { @@ -24,7 +24,7 @@ export function FlightPlanPath(props: FlightPlanProps) { ); } -export function FlightPlan(props: FlightPlanProps) { +export default function FlightPlan(props: FlightPlanProps) { return ( <> diff --git a/client/src/components/flightplan/index.ts b/client/src/components/flightplan/index.ts new file mode 100644 index 00000000..b741ce96 --- /dev/null +++ b/client/src/components/flightplan/index.ts @@ -0,0 +1 @@ +export { default } from "./FlightPlan"; diff --git a/client/src/map/flightplanslayer/FlightPlansLayer.tsx b/client/src/components/flightplanslayer/FlightPlansLayer.tsx similarity index 64% rename from client/src/map/flightplanslayer/FlightPlansLayer.tsx rename to client/src/components/flightplanslayer/FlightPlansLayer.tsx index 136d8272..e094064c 100644 --- a/client/src/map/flightplanslayer/FlightPlansLayer.tsx +++ b/client/src/components/flightplanslayer/FlightPlansLayer.tsx @@ -1,14 +1,14 @@ -import { FlightPlan } from "../flightplan/FlightPlan"; +import FlightPlan from "../flightplan"; import { LayerGroup } from "react-leaflet"; -import { selectAtos } from "../../game/ato/atoSlice"; +import { selectFlights } from "../../api/flightsSlice"; import { useAppSelector } from "../../app/hooks"; interface FlightPlansLayerProps { blue: boolean; } -export function FlightPlansLayer(props: FlightPlansLayerProps) { - const atos = useAppSelector(selectAtos); +export default function FlightPlansLayer(props: FlightPlansLayerProps) { + const atos = useAppSelector(selectFlights); const flights = props.blue ? atos.blue : atos.red; return ( diff --git a/client/src/components/flightplanslayer/index.ts b/client/src/components/flightplanslayer/index.ts new file mode 100644 index 00000000..56248f03 --- /dev/null +++ b/client/src/components/flightplanslayer/index.ts @@ -0,0 +1 @@ +export { default } from "./FlightPlansLayer"; diff --git a/client/src/map/liberationmap/LiberationMap.css b/client/src/components/liberationmap/LiberationMap.css similarity index 100% rename from client/src/map/liberationmap/LiberationMap.css rename to client/src/components/liberationmap/LiberationMap.css diff --git a/client/src/map/liberationmap/LiberationMap.tsx b/client/src/components/liberationmap/LiberationMap.tsx similarity index 69% rename from client/src/map/liberationmap/LiberationMap.tsx rename to client/src/components/liberationmap/LiberationMap.tsx index 38eb1c77..db92f495 100644 --- a/client/src/map/liberationmap/LiberationMap.tsx +++ b/client/src/components/liberationmap/LiberationMap.tsx @@ -1,15 +1,16 @@ -import { MapContainer } from "react-leaflet"; -import { BasemapLayer } from "react-esri-leaflet"; -import { ControlPointsLayer } from "../controlpointslayer/ControlPointsLayer"; import "./LiberationMap.css"; + +import { BasemapLayer } from "react-esri-leaflet"; +import ControlPointsLayer from "../controlpointslayer"; +import FlightPlansLayer from "../flightplanslayer"; import { LatLng } from "leaflet"; -import { FlightPlansLayer } from "../flightplanslayer/FlightPlansLayer"; +import { MapContainer } from "react-leaflet"; interface GameProps { mapCenter: LatLng; } -export function LiberationMap(props: GameProps) { +export default function LiberationMap(props: GameProps) { return ( diff --git a/client/src/components/liberationmap/index.ts b/client/src/components/liberationmap/index.ts new file mode 100644 index 00000000..82e6d029 --- /dev/null +++ b/client/src/components/liberationmap/index.ts @@ -0,0 +1 @@ +export { default } from "./LiberationMap"; diff --git a/client/src/game/theater/theaterSlice.ts b/client/src/game/theater/theaterSlice.ts deleted file mode 100644 index d8eae4ae..00000000 --- a/client/src/game/theater/theaterSlice.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { RootState } from "../../app/store"; -import { ControlPoint } from "../controlpoint"; - -interface TheaterState { - controlPoints: ControlPoint[]; -} - -const initialState: TheaterState = { - controlPoints: [], -}; - -export const theaterSlice = createSlice({ - name: "theater", - initialState, - reducers: { - setControlPoints: (state, action: PayloadAction) => { - state.controlPoints = action.payload; - }, - }, -}); - -export const { setControlPoints } = theaterSlice.actions; - -export const selectControlPoints = (state: RootState) => - state.theater.controlPoints; - -export default theaterSlice.reducer;