ISSUE-032 - Defined a great number of new state types for use with the race event's state, the broadcast director's controls, and the broadcast graphics states.
Taking a second to make a commit to save my progress so far.
This commit is contained in:
1 parent
ef0b58e98b
commit
5d009a3d70
12 files changed
+254
-21
No files matched your search
@@ -0,0 +1,3 @@
|
||||
import { RootState } from "../../../types/state";
|
||||
|
||||
export const broadcastDirectorSelector = (state: RootState) => state.broadcastDirector;
|
||||
@@ -0,0 +1,46 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { findIndex } from "lodash";
|
||||
|
||||
import { RootState, Car } from "../../../types/state";
|
||||
|
||||
const initialState: RootState["broadcastDirector"] = {
|
||||
selectedCars: [],
|
||||
};
|
||||
|
||||
const carMatch = (targetCar: Car) => (checkedCar: Car) =>
|
||||
checkedCar.driver.id === targetCar.driver.id;
|
||||
|
||||
export const broadcastDirectorSlice = createSlice({
|
||||
name: "broadcastDirector",
|
||||
initialState,
|
||||
reducers: {
|
||||
selectedCarsAdd: (state, action: PayloadAction<Car>) => {
|
||||
const index = findIndex(state.selectedCars, carMatch(action.payload));
|
||||
if (index === -1) {
|
||||
state.selectedCars = state.selectedCars.concat(action.payload);
|
||||
}
|
||||
},
|
||||
selectedCarsSet: (state, action: PayloadAction<Car>) => { // Might be removed.
|
||||
state.selectedCars = [action.payload];
|
||||
},
|
||||
selectedCarsRemove: (state, action: PayloadAction<Car | number>) => {
|
||||
const index = typeof action.payload === "number"
|
||||
? action.payload
|
||||
: findIndex(state.selectedCars, carMatch(action.payload));
|
||||
state.selectedCars = state.selectedCars.slice(0, index).concat(
|
||||
state.selectedCars.slice(index + 1),
|
||||
);
|
||||
},
|
||||
selectedCarsClear: (state) => {
|
||||
state.selectedCars = [];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
selectedCarsAdd,
|
||||
selectedCarsSet,
|
||||
selectedCarsRemove,
|
||||
selectedCarsClear,
|
||||
} = broadcastDirectorSlice.actions;
|
||||
export default broadcastDirectorSlice.reducer;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { RootState } from "../../../types/state";
|
||||
|
||||
export const broadcastGraphicsSelector = (state: RootState) => state.broadcastGraphics;
|
||||
@@ -0,0 +1,34 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
import { BGChyrons, OpenState, RootState } from "../../../types/state";
|
||||
|
||||
const initialState: RootState["broadcastGraphics"] = {
|
||||
chyrons: null,
|
||||
};
|
||||
|
||||
export const broadcastGraphicsSlice = createSlice({
|
||||
name: "broadcastGraphics",
|
||||
initialState,
|
||||
reducers: {
|
||||
chyronsLaunch: (state, action: PayloadAction<BGChyrons>) => {
|
||||
state.chyrons = action.payload;
|
||||
},
|
||||
chyronsSetOpenState: (state, action: PayloadAction<OpenState>) => {
|
||||
if (state.chyrons == null) return;
|
||||
state.chyrons.primary.openState = action.payload;
|
||||
|
||||
if (state.chyrons.secondary != null) {
|
||||
state.chyrons.secondary.openState = action.payload;
|
||||
}
|
||||
},
|
||||
chyronsClear: (state) => {
|
||||
state.chyrons = null;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
chyronsLaunch,
|
||||
chyronsClear,
|
||||
} = broadcastGraphicsSlice.actions;
|
||||
export default broadcastGraphicsSlice.reducer;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { RootState } from "../../types/state";
|
||||
|
||||
export const eventSelector = (state: RootState) => state.event;
|
||||
@@ -0,0 +1,58 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
import { CourseFlag, RootState } from "../../types/state";
|
||||
import { getDriver } from "../../utils/dataLookup";
|
||||
|
||||
const initialState: RootState["event"] = {
|
||||
trackName: "Melbourne",
|
||||
courseStatus: {
|
||||
courseFlag: "green",
|
||||
sectorFlags: ["green", "green", "green"],
|
||||
safetyCar: "clear",
|
||||
virtualSafetyCar: "clear",
|
||||
},
|
||||
mode: "race",
|
||||
progress: {
|
||||
startTime: Date.now(),
|
||||
timeLimit: 60 * 60 * 2 * 1000,
|
||||
currentLap: 1,
|
||||
lapCount: 10,
|
||||
},
|
||||
grid: [
|
||||
{ position: 1, driver: getDriver("verstappen") },
|
||||
{ position: 3, driver: getDriver("hamilton") },
|
||||
{ position: 2, driver: getDriver("bottas") },
|
||||
{ position: 4, driver: getDriver("perez") },
|
||||
{ position: 5, driver: getDriver("sainz") },
|
||||
{ position: 6, driver: getDriver("norris") },
|
||||
{ position: 7, driver: getDriver("leclerc") },
|
||||
{ position: 8, driver: getDriver("ricciardo") },
|
||||
{ position: 9, driver: getDriver("gasly") },
|
||||
{ position: 10, driver: getDriver("alonso") },
|
||||
{ position: 11, driver: getDriver("ocon") },
|
||||
{ position: 12, driver: getDriver("vettel") },
|
||||
{ position: 13, driver: getDriver("stroll") },
|
||||
{ position: 14, driver: getDriver("tsunoda") },
|
||||
{ position: 15, driver: getDriver("russell") },
|
||||
{ position: 16, driver: getDriver("raikkonen") },
|
||||
{ position: 17, driver: getDriver("latifi") },
|
||||
{ position: 18, driver: getDriver("giovinazzi") },
|
||||
{ position: 19, driver: getDriver("schumacher") },
|
||||
{ position: 20, driver: getDriver("mazepin") },
|
||||
],
|
||||
};
|
||||
|
||||
export const eventSlice = createSlice({
|
||||
name: "event",
|
||||
initialState,
|
||||
reducers: {
|
||||
courseFlagSet: (state, action: PayloadAction<CourseFlag>) => {
|
||||
state.courseStatus.courseFlag = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
courseFlagSet,
|
||||
} = eventSlice.actions;
|
||||
export default eventSlice.reducer;
|
||||
Reference in new issue
Block a user