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:
Kyle Geib committed 2022-01-27 13:39:52 -05:00
1 parent ef0b58e98b
commit 5d009a3d70
12 files changed
+254 -21

No files matched your search

@@ -60,3 +60,7 @@ export function ChyronDriver() {
</BaseBackground>
);
}
// export function ChyronDriverStateContainer() {
// }
@@ -41,6 +41,7 @@ export const Workspace = () => {
if (workspaceId == null) return null;
const [graphic, controls] = fetchBroadcastGraphic(workspaceId);
return (
<Stack
gutter="lg"
@@ -53,13 +54,14 @@ export const Workspace = () => {
dimensions={workspaceProperties.previewWindowDimensions}
animatedBG={animatedBG}
>
{fetchBroadcastGraphic(workspaceId)}
{graphic}
<OverlayDisplay
containerDimensions={workspaceProperties.previewWindowDimensions}
/>
</PreviewWindow>
<ControlsContainer>
<WorkspaceControls />
{controls}
</ControlsContainer>
</Stack>
);
+5 -5
View File
@@ -29,7 +29,7 @@ export const workspaces: WorkspaceObject = {
],
previewWindowDimensions: {
width: 750,
height: 200,
height: 300,
},
},
angledFlag: {
@@ -44,11 +44,11 @@ export const workspaces: WorkspaceObject = {
},
};
export function fetchBroadcastGraphic(workspaceId: WorkspaceId): ReactNode {
export function fetchBroadcastGraphic(workspaceId: WorkspaceId): [ReactNode, ReactNode] {
switch(workspaceId) {
case "chyronDriver": return ChyronDriver();
case "angledFlag": return AngledFlagWorkSpace();
default: return null;
case "chyronDriver": return [ChyronDriver(), null];
case "angledFlag": return [AngledFlagWorkSpace(), null];
default: return [null, null];
}
}
@@ -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;
+3
View File
@@ -0,0 +1,3 @@
import { RootState } from "../../types/state";
export const eventSelector = (state: RootState) => state.event;
+58
View File
@@ -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;
+2
View File
@@ -3,11 +3,13 @@ import { configureStore, combineReducers } from "@reduxjs/toolkit";
import pageDimensions from "./features/pageDimensions/pageDimensionsSlice";
import workspace from "./features/workspace/workspaceSlice";
import overlayTool from "./features/overlayTool/overlayToolSlice";
import broadcastGraphics from "./features/broadcast/graphics/broadcastGraphicsSlice";
export const store = configureStore({
reducer: combineReducers({
pageDimensions,
workspace,
overlayTool,
broadcastGraphics,
}),
});
+90 -15
View File
@@ -1,7 +1,12 @@
import { Milliseconds, Optional } from "./util";
export interface RootState {
pageDimensions: PageDimensions;
workspace: Workspace;
overlayTool: OverlayTool;
event: Event,
broadcastDirector: BroadcastDirector;
broadcastGraphics: BroadcastGraphics;
}
// Page Dimensions
@@ -42,14 +47,54 @@ export interface OverlayItem {
opacity: number;
}
// Race State.
// Event State
export interface Event {
trackName: string;
courseStatus: CourseStatus;
mode: EventMode;
progress: EventProgress;
grid: Grid;
}
export interface EventProgress {
startTime: Milliseconds;
timeLimit: Milliseconds;
currentLap: number;
lapCount: number;
}
export type EventMode =
| "race"
| "sprint"
| "p1"
| "p2"
| "p3"
| "q1"
| "q2"
| "q3";
export interface CourseStatus {
courseFlag: CourseFlags;
sectorFlags: Array<CourseFlag>;
safetyCar: SafetyCarStatus;
virtualSafetyCar: VirtualSafetyCarStatus;
}
export type CourseFlag =
| "green"
| "yellow"
| "doubleYellow"
| "chequered"
| "red"
| "white"
| "redYellow";
export type SafetyCarStatus = "clear" | "starting" | "out" | "ending";
export type VirtualSafetyCarStatus = "clear" | "out" | "ending";
export type Grid = Array<Car>; // Grid order does not change.
export interface Car {
position: number;
driver: Driver;
// status: ???;
// status: ???; // retired
// flags: ???, // blue, red, meatball, black/white, black
// notices: ???; // Penalties, warnings, investigations, blue flags, etc
// distance: number;
}
export type Grid = Array<Car>;
export interface Driver {
id: DriverId;
firstName: string;
@@ -126,6 +171,11 @@ export type TeamFullName =
| "Red Bull Racing"
| "Williams Racing";
// Broadcast Director
export interface BroadcastDirector {
selectedCars: Array<Car>;
}
// Broadcast Graphics
export interface BGRelativePos {
top?: string;
@@ -133,34 +183,59 @@ export interface BGRelativePos {
bottom?: string;
left?: string;
}
export interface BGBaseState {
relativePos: BGRelativePos;
openState: OpenState;
}
/**
* -1 closing, 0 closed, 1 open, 2... different states
*/
export type OpenState = number;
export interface BroadcastGraphics {
// timingBoard: BGTimingBoard;
// statusIndicator: BGStatusIndicator;
// indicators: BGIndicators
chyrons: BGChyrons;
chyrons: Optional<BGChyrons>;
// gems: BGGems
// toasts: BGToasts;
}
export interface BGChyrons {
primary: BGChyron;
secondary: BGChyron;
// sponsorGem: BGSponsorGem;
}
// Chyrons
export type FlagMode = "country" | "team";
export type BGChyronMode =
| "driver-basic-small"
| "driver-basic-medium"
| "driver-basic-large";
export interface BGChyron extends BGRelativePos {
export interface BGChyron extends BGBaseState {
mode: BGChyronMode;
cars: Array<Car>;
car: Car;
flagMode: FlagMode;
showPosFlag: boolean;
showDriverNumber: boolean;
dimensions: Dimensions;
props?: unknown;
}
export interface BGChyrons {
primary: BGChyron;
secondary: Optional<BGChyron>;
// sponsorGem: BGSponsorGem;
}
export interface BGChyronMedium extends BGChyron {
mode: "driver-basic-medium";
flag: FlagMode;
showPosFlag: boolean;
showDriverNumber: boolean;
dimensions: {
width: 582;
height: 72;
}
props: {
showPortrait: boolean;
}
}
export interface BGChyronLarge extends BGChyron {
mode: "driver-basic-large";
dimensions: {
width: 638;
height: 98;
}
}
+3
View File
@@ -0,0 +1,3 @@
export type Optional<TEntity> = TEntity | null;
export type Milliseconds = number;
export type Seconds = number;