diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx
index c0c223d..6f5714f 100644
--- a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx
+++ b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx
@@ -60,3 +60,7 @@ export function ChyronDriver() {
);
}
+
+// export function ChyronDriverStateContainer() {
+
+// }
diff --git a/src/components/Workspaces/Workspace/Workspace.tsx b/src/components/Workspaces/Workspace/Workspace.tsx
index 6f903ef..67d8b63 100644
--- a/src/components/Workspaces/Workspace/Workspace.tsx
+++ b/src/components/Workspaces/Workspace/Workspace.tsx
@@ -41,6 +41,7 @@ export const Workspace = () => {
if (workspaceId == null) return null;
+ const [graphic, controls] = fetchBroadcastGraphic(workspaceId);
return (
{
dimensions={workspaceProperties.previewWindowDimensions}
animatedBG={animatedBG}
>
- {fetchBroadcastGraphic(workspaceId)}
+ {graphic}
+ {controls}
);
diff --git a/src/domain/data/workspaces.ts b/src/domain/data/workspaces.ts
index 1c4db41..85f6c06 100644
--- a/src/domain/data/workspaces.ts
+++ b/src/domain/data/workspaces.ts
@@ -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];
}
}
diff --git a/src/features/broadcast/director/broadcastDirectorSelector.ts b/src/features/broadcast/director/broadcastDirectorSelector.ts
new file mode 100644
index 0000000..2709bf7
--- /dev/null
+++ b/src/features/broadcast/director/broadcastDirectorSelector.ts
@@ -0,0 +1,3 @@
+import { RootState } from "../../../types/state";
+
+export const broadcastDirectorSelector = (state: RootState) => state.broadcastDirector;
diff --git a/src/features/broadcast/director/broadcastDirectorSlice.ts b/src/features/broadcast/director/broadcastDirectorSlice.ts
new file mode 100644
index 0000000..ccdf055
--- /dev/null
+++ b/src/features/broadcast/director/broadcastDirectorSlice.ts
@@ -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) => {
+ const index = findIndex(state.selectedCars, carMatch(action.payload));
+ if (index === -1) {
+ state.selectedCars = state.selectedCars.concat(action.payload);
+ }
+ },
+ selectedCarsSet: (state, action: PayloadAction) => { // Might be removed.
+ state.selectedCars = [action.payload];
+ },
+ selectedCarsRemove: (state, action: PayloadAction) => {
+ 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;
diff --git a/src/features/broadcast/graphics/broadcastGraphicsSelector.ts b/src/features/broadcast/graphics/broadcastGraphicsSelector.ts
new file mode 100644
index 0000000..fce0697
--- /dev/null
+++ b/src/features/broadcast/graphics/broadcastGraphicsSelector.ts
@@ -0,0 +1,3 @@
+import { RootState } from "../../../types/state";
+
+export const broadcastGraphicsSelector = (state: RootState) => state.broadcastGraphics;
diff --git a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts
new file mode 100644
index 0000000..617acd4
--- /dev/null
+++ b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts
@@ -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) => {
+ state.chyrons = action.payload;
+ },
+ chyronsSetOpenState: (state, action: PayloadAction) => {
+ 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;
diff --git a/src/features/event/eventSelector.ts b/src/features/event/eventSelector.ts
new file mode 100644
index 0000000..9ce42d5
--- /dev/null
+++ b/src/features/event/eventSelector.ts
@@ -0,0 +1,3 @@
+import { RootState } from "../../types/state";
+
+export const eventSelector = (state: RootState) => state.event;
diff --git a/src/features/event/eventSlice.ts b/src/features/event/eventSlice.ts
new file mode 100644
index 0000000..5313d6b
--- /dev/null
+++ b/src/features/event/eventSlice.ts
@@ -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) => {
+ state.courseStatus.courseFlag = action.payload;
+ },
+ },
+});
+
+export const {
+ courseFlagSet,
+} = eventSlice.actions;
+export default eventSlice.reducer;
diff --git a/src/store.ts b/src/store.ts
index 5cc2731..6ff2325 100644
--- a/src/store.ts
+++ b/src/store.ts
@@ -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,
}),
});
diff --git a/src/types/state.d.ts b/src/types/state.d.ts
index 0b6e997..89713e6 100644
--- a/src/types/state.d.ts
+++ b/src/types/state.d.ts
@@ -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;
+ 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; // 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;
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;
+}
+
// 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;
// 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;
+ flagMode: FlagMode;
+ showPosFlag: boolean;
+ showDriverNumber: boolean;
+ dimensions: Dimensions;
+ props?: unknown;
+}
+export interface BGChyrons {
+ primary: BGChyron;
+ secondary: Optional;
+ // 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;
+ }
}
diff --git a/src/types/util.d.ts b/src/types/util.d.ts
new file mode 100644
index 0000000..86126fb
--- /dev/null
+++ b/src/types/util.d.ts
@@ -0,0 +1,3 @@
+export type Optional = TEntity | null;
+export type Milliseconds = number;
+export type Seconds = number;