diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx index e151d84..d001062 100644 --- a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx +++ b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx @@ -21,7 +21,6 @@ import { LastName, NameContainer, NumberContainer, - Spacer, TeamColorBar, TeamName, TextContainer, @@ -29,6 +28,7 @@ import { DriverPortraitContainer, } from "./styles"; import { VenetianBlindsTransition } from "../../Common/VenetianBlindsTransition"; +import { Spacer } from "../../Common/Spacer.styled"; type ChyronDriverProps = { chyronData: BGChyronDriver, diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/styles.ts b/src/components/BroadcastGraphics/Chyrons/Driver/styles.ts index eca70e3..23b5198 100644 --- a/src/components/BroadcastGraphics/Chyrons/Driver/styles.ts +++ b/src/components/BroadcastGraphics/Chyrons/Driver/styles.ts @@ -171,16 +171,6 @@ export const TeamName = styled.div` `; TeamName.displayName = "TeamName"; -type SpacerProps = { - width?: string, - height?: string; -}; -export const Spacer = styled.div` - width: ${({ width = "0" }) => width}; - height: ${({ height = "0" }) => height}; -`; -Spacer.displayName = "Spacer"; - type FlagContainerProps = { height: Px, width: Px, diff --git a/src/components/BroadcastGraphics/Common/Spacer.styled.ts b/src/components/BroadcastGraphics/Common/Spacer.styled.ts new file mode 100644 index 0000000..2bd1888 --- /dev/null +++ b/src/components/BroadcastGraphics/Common/Spacer.styled.ts @@ -0,0 +1,11 @@ +import styled from "styled-components"; + +type SpacerProps = { + width?: string, + height?: string; +}; +export const Spacer = styled.div` + width: ${({ width = "0" }) => width}; + height: ${({ height = "0" }) => height}; +`; +Spacer.displayName = "Spacer"; diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx new file mode 100644 index 0000000..019d694 --- /dev/null +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx @@ -0,0 +1,101 @@ +import { useSelector } from "react-redux"; +import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector"; + +import { eventSelector } from "../../../../features/event/eventSelector"; +import { BGTimingTowerModes, Car, CarStatus } from "../../../../types/state"; +import { orMatch } from "../../../../utils/common"; +import { PositionFlag } from "../../Common/PositionFlag"; +import { Spacer } from "../../Common/Spacer.styled"; + +import { + DriverName, + RowContainer, + RowLeftHalf, + RowLeftHalfLayout, + RowRightHalf, + RowRightHalfLayout, + RowsContainer, +} from "./styles"; + +type TimingTowerProps = { + carsToDisplay?: number, +} +export function TimingTower({ + carsToDisplay = 20, +}: TimingTowerProps) { + + const { grid } = useSelector(eventSelector); + const { timingBoard } = useSelector(broadcastGraphicsSelector); + + const runningCars: Car[] = []; + const retiredCars: Car[] = []; + + grid.forEach((car, index) => { + if (index >= carsToDisplay) return; + if (car.status === CarStatus.Retired) { + retiredCars.push(car); + } else { + runningCars.push(car); + } + }); + + const buildRow = ( + car: Car, + index: number, + count: number, + ) => { + const lastRow = index + 1 === count; + + return ( + + + + + {car.status !== CarStatus.Retired && ( + + )} + + + {car.driver.initials} + + + + + + + + + + ); + }; + + + const rows = runningCars.map((car, index, cars) => buildRow(car, index, cars.length)); + rows.push(...retiredCars.map((car, index, cars) => buildRow(car, index, cars.length))); + + return ( + + {rows} + + ); +} diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/index.ts b/src/components/BroadcastGraphics/TimingBoard/TimingTower/index.ts new file mode 100644 index 0000000..bc5b1b6 --- /dev/null +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/index.ts @@ -0,0 +1 @@ +export * from "./TimingTower"; diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts b/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts new file mode 100644 index 0000000..a98ea5b --- /dev/null +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts @@ -0,0 +1,86 @@ +import styled, { css } from "styled-components"; + +export const RowsContainer = styled.div` +display: flex; +flex-direction: column; + +flex-wrap: nowrap; + +justify-content: flex-start; +align-items: stretch; +`; + + +type RowContainerProps = { + topGap?: boolean, + bottomGap?: boolean, + retired?: boolean, + wide?: boolean, +} +// All the elements in a row should go in here. +export const RowContainer = styled.div` + position: relative; + width: ${({ wide }) => wide ? 255 : 147}px; + height: 36px; // Future will be animated. + + ${({ topGap }) => topGap && css`margin-top: 3px;`} + ${({ bottomGap }) => bottomGap && css`margin-bottom: 3px;`} + ${({ retired }) => retired && css`opacity: 0.4;`} +`; + +type RoundedProp = { + roundedCorner?: boolean; +}; +const Rounded = styled.div` + ${({ roundedCorner }) => roundedCorner && css`border-bottom-right-radius: 5px;`} +`; + +export const RowLeftHalf = styled(Rounded)` + position: absolute; + left: 0; + top: 0; + + width: 147px; // Future will be animated. + height: 36px; + + background-color: #000000cb +`; + +export const RowLeftHalfLayout = styled.div` + width: 100%; + height: 100%; + + display: flex; + + align-items: center; + justify-content: flex-start; +`; + +export const RowRightHalf = styled(Rounded)` + position: absolute; + right: 0; + top: 0; + + width: 108px; // Future will be animated. + height: 36px; + + overflow-x: hidden; + + background-color: #0000007e +`; + +export const RowRightHalfLayout = styled.div` + width: 100%; + height: 100%; + + display: flex; + + align-items: center; + justify-content: flex-end; +`; + +export const DriverName = styled.span` + color: white; + font-family: ${p => p.theme.fonts.f1Bold}; + font-size: 20px; +`; diff --git a/src/components/Workspaces/WorkspacesRoute.tsx b/src/components/Workspaces/WorkspacesRoute.tsx index 34e33e5..b1790fd 100644 --- a/src/components/Workspaces/WorkspacesRoute.tsx +++ b/src/components/Workspaces/WorkspacesRoute.tsx @@ -18,6 +18,7 @@ import { AngledFlagPrototypeControls } from "./PrototypingControls/AngledFlagPro import { ChyronContainer } from "../BroadcastGraphics/Chyrons/Container"; import { VenetianBlindsWorkspace } from "./CustomWorkSpaces/VenetianBlindsWorkspace"; import { VenetianBlindsPrototypeControls } from "./PrototypingControls/VenetianBlindsPrototype"; +import { TimingTower } from "../BroadcastGraphics/TimingBoard/TimingTower"; const WORKSPACE_LIST_WIDTH = 180; @@ -89,6 +90,20 @@ export default function Workspaces() { prototypeControls={} /> } /> + } + prototypeControls={
Timing Tower Full
} + /> + } /> + } + prototypeControls={
Timing Tower Short
} + /> + } /> Unknown Workspace} /> diff --git a/src/domain/data/workspaces.ts b/src/domain/data/workspaces.ts index 4268687..6ad2b9d 100644 --- a/src/domain/data/workspaces.ts +++ b/src/domain/data/workspaces.ts @@ -84,4 +84,26 @@ export const workspaces: WorkspaceObject = { height: 500, }, }, + timingBoardFull: { + name: "Timing Board (Full)", + overlayIds: [ + "timing-board-leader-19.png", + "timing-board-leader-20-out-1.png", + "timing-board-intervals-yellow-flag.png", + ], + previewWindowDimensions: { + width: 350, + height: 820, + }, + }, + timingBoardShort: { + name: "Timing Board (Short)", + overlayIds: [ + "timing-board-portrait-gap.png", + ], + previewWindowDimensions: { + width: 350, + height: 410, + }, + }, }; diff --git a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts index a169905..a11b5da 100644 --- a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts +++ b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts @@ -1,9 +1,29 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { BGChyrons, OpenState, RootState } from "../../../types/state"; +import { + BGChyrons, + BGStatusIndicatorModes, + BGTimingTowerFocusedCarsMode, + BGTimingTowerModes, + OpenState, + RootState, +} from "../../../types/state"; const initialState: RootState["broadcastGraphics"] = { chyrons: null, + timingBoard: { + relativePos: {}, + openState: 0, + statusIndicator: { + mode: BGStatusIndicatorModes.NormalNarrow, + }, + timingTower: { + open: 1, + mode: BGTimingTowerModes.Leader, + focusedCars: [], + focusedCarsMode: BGTimingTowerFocusedCarsMode.None, + }, + }, }; export const broadcastGraphicsSlice = createSlice({ diff --git a/src/features/event/eventSlice.ts b/src/features/event/eventSlice.ts index 4ad46cd..3cea007 100644 --- a/src/features/event/eventSlice.ts +++ b/src/features/event/eventSlice.ts @@ -1,6 +1,6 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { CourseFlag, RootState } from "../../types/state"; +import { CourseFlag, CarStatus, RootState } from "../../types/state"; import { cloneDriver } from "../../utils/dataLookup"; const initialState: RootState["event"] = { @@ -19,26 +19,26 @@ const initialState: RootState["event"] = { lapCount: 10, }, grid: [ - { position: 1, driver: cloneDriver("verstappen") }, - { position: 2, driver: cloneDriver("hamilton") }, - { position: 3, driver: cloneDriver("bottas") }, - { position: 4, driver: cloneDriver("perez") }, - { position: 5, driver: cloneDriver("sainz") }, - { position: 6, driver: cloneDriver("norris") }, - { position: 7, driver: cloneDriver("leclerc") }, - { position: 8, driver: cloneDriver("ricciardo") }, - { position: 9, driver: cloneDriver("gasly") }, - { position: 10, driver: cloneDriver("alonso") }, - { position: 11, driver: cloneDriver("ocon") }, - { position: 12, driver: cloneDriver("vettel") }, - { position: 13, driver: cloneDriver("stroll") }, - { position: 14, driver: cloneDriver("tsunoda") }, - { position: 15, driver: cloneDriver("russell") }, - { position: 16, driver: cloneDriver("raikkonen") }, - { position: 17, driver: cloneDriver("latifi") }, - { position: 18, driver: cloneDriver("giovinazzi") }, - { position: 19, driver: cloneDriver("schumacher") }, - { position: 20, driver: cloneDriver("mazepin") }, + { position: 1, status: CarStatus.Normal, driver: cloneDriver("verstappen") }, + { position: 2, status: CarStatus.Normal, driver: cloneDriver("hamilton") }, + { position: 3, status: CarStatus.Normal, driver: cloneDriver("bottas") }, + { position: 4, status: CarStatus.Retired, driver: cloneDriver("perez") }, + { position: 5, status: CarStatus.Normal, driver: cloneDriver("sainz") }, + { position: 6, status: CarStatus.Retired, driver: cloneDriver("norris") }, + { position: 7, status: CarStatus.Normal, driver: cloneDriver("leclerc") }, + { position: 8, status: CarStatus.Normal, driver: cloneDriver("ricciardo") }, + { position: 9, status: CarStatus.Normal, driver: cloneDriver("gasly") }, + { position: 10, status: CarStatus.Normal, driver: cloneDriver("alonso") }, + { position: 11, status: CarStatus.Normal, driver: cloneDriver("ocon") }, + { position: 12, status: CarStatus.Normal, driver: cloneDriver("vettel") }, + { position: 13, status: CarStatus.Normal, driver: cloneDriver("stroll") }, + { position: 14, status: CarStatus.Normal, driver: cloneDriver("tsunoda") }, + { position: 15, status: CarStatus.Normal, driver: cloneDriver("russell") }, + { position: 16, status: CarStatus.Normal, driver: cloneDriver("raikkonen") }, + { position: 17, status: CarStatus.Normal, driver: cloneDriver("latifi") }, + { position: 18, status: CarStatus.Normal, driver: cloneDriver("giovinazzi") }, + { position: 19, status: CarStatus.Normal, driver: cloneDriver("schumacher") }, + { position: 20, status: CarStatus.Normal, driver: cloneDriver("mazepin") }, ], }; diff --git a/src/public/images/logos/team/astonMartin.svg b/src/public/images/logos/team/astonMartin.svg index 3932789..7938645 100644 --- a/src/public/images/logos/team/astonMartin.svg +++ b/src/public/images/logos/team/astonMartin.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/public/images/overlays/timing-board-intervals-yellow-flag.png b/src/public/images/overlays/timing-board-intervals-yellow-flag.png new file mode 100644 index 0000000..3f731cb Binary files /dev/null and b/src/public/images/overlays/timing-board-intervals-yellow-flag.png differ diff --git a/src/public/images/overlays/timing-board-leader-19.png b/src/public/images/overlays/timing-board-leader-19.png new file mode 100644 index 0000000..95927ec Binary files /dev/null and b/src/public/images/overlays/timing-board-leader-19.png differ diff --git a/src/public/images/overlays/timing-board-leader-20-out-1.png b/src/public/images/overlays/timing-board-leader-20-out-1.png new file mode 100644 index 0000000..7f9ad08 Binary files /dev/null and b/src/public/images/overlays/timing-board-leader-20-out-1.png differ diff --git a/src/public/images/overlays/timing-board-portrait-gap.png b/src/public/images/overlays/timing-board-portrait-gap.png new file mode 100644 index 0000000..47ba903 Binary files /dev/null and b/src/public/images/overlays/timing-board-portrait-gap.png differ diff --git a/src/types/state.d.ts b/src/types/state.d.ts index c01dc92..0f5e112 100644 --- a/src/types/state.d.ts +++ b/src/types/state.d.ts @@ -60,7 +60,7 @@ export interface OverlayTool { visible: boolean; } export type OverlayId = string; -export type OverlayIds = Array; +export type OverlayIds = OverlayId[]; export interface OverlayPosition { x: number; y: number; } export interface OverlayItem { position: OverlayPosition; @@ -92,7 +92,7 @@ export type EventMode = | "q3"; export interface CourseStatus { courseFlag: CourseFlags; - sectorFlags: Array; + sectorFlags: CourseFlag[]; safetyCar: SafetyCarStatus; virtualSafetyCar: VirtualSafetyCarStatus; } @@ -106,11 +106,11 @@ export type CourseFlag = | "redYellow"; export type SafetyCarStatus = "clear" | "starting" | "out" | "ending"; export type VirtualSafetyCarStatus = "clear" | "out" | "ending"; -export type Grid = Array; // Grid order does not change. +export type Grid = Car[]; // Grid order does not change. export interface Car { position: number; driver: Driver; - // status: ???; // retired + status: CarStatus; // flags: ???, // blue, red, meatball, black/white, black // notices: ???; // Penalties, warnings, investigations, blue flags, etc // distance: number; @@ -193,7 +193,7 @@ export type TeamFullName = // Broadcast Director export interface BroadcastDirector { - selectedCars: Array; + selectedCars: Car[]; } // Broadcast Graphics @@ -213,14 +213,33 @@ export interface BGBaseState { export type OpenState = number; export interface BroadcastGraphics { - // timingBoard: BGTimingBoard; - // statusIndicator: BGStatusIndicator; + timingBoard: BGTimingBoard; // indicators: BGIndicators chyrons: Optional; // gems: BGGems // toasts: BGToasts; } +// Timing Board +export interface BGTimingBoard extends BGBaseState { + statusIndicator: BGStatusIndicator; + timingTower: BGTimingTower; +} + +// Status Indicator +export interface BGStatusIndicator { + mode: BGStatusIndicatorModes; +} + +// Timing Tower +export interface BGTimingTower { + open: OpenState; + mode: BGTimingTowerModes; + focusedCars: Car[], + focusedCarsMode: BGTimingTowerFocusedCarsMode, +} + + // Chyrons export type BGChyronMode = string; export type BGChyronSubMode = string; diff --git a/src/types/state.ts b/src/types/state.ts new file mode 100644 index 0000000..020614c --- /dev/null +++ b/src/types/state.ts @@ -0,0 +1,29 @@ +// To support enums https://stackoverflow.com/a/66939542 +export * from "./state.d"; + +export enum CarStatus { + Normal, + Retired, + InPit, + OutLap, + InLap, + DidNotStart, +} + +export enum BGStatusIndicatorModes { + NormalNarrow, // "LAP" above "##/##" lap count. + NormalWide, // "LAP" to the left of "##/##" lap count. +} + +export enum BGTimingTowerModes { + Hidden, // Not on display. + Minimum, // Just the driver name abbrv. + Leader, // Leader timing. + Interval, // Interval timing. + FullName, // Displays full name. +} + +export enum BGTimingTowerFocusedCarsMode { + None, // When no special treatments are made. + Portrait, // When it shows the portrait of the driver. +} diff --git a/src/utils/common.spec.ts b/src/utils/common.spec.ts new file mode 100644 index 0000000..5303783 --- /dev/null +++ b/src/utils/common.spec.ts @@ -0,0 +1,95 @@ +import { andMatch, andWith, orMatch, orWith } from "./common"; + +describe("common", () => { + describe("andMatch", () => { + describe("detects correct matches", () => { + it("works with number", () => { + expect(andMatch(5, 2 + 3, 5 + 0, 6 - 1)).toBe(true); + }); + + it("works with boolean", () => { + expect(andMatch(true, 1 == 1, !false, !!1)).toBe(true); + }); + }); + describe("detects incorrect matches", () => { + it("works with number", () => { + expect(andMatch(5, 4 + 1, 3 + 0)).toBe(false); + }); + + it("works with boolean", () => { + expect(andMatch(true, !true, !!0)).toBe(false); + }); + }); + describe("sensibly handles odd situations", () => { + it("returns truthiness of self when no rights given", () => { + expect(andMatch(5)).toBe(true); + expect(andMatch(0)).toBe(false); + }); + }); + }); + + describe("orMatch", () => { + describe("detects correct matches", () => { + it("works with number", () => { + expect(orMatch(5, 0, 0, 6 - 1)).toBe(true); + }); + + it("works with boolean", () => { + expect(orMatch(true, false, !false)).toBe(true); + }); + }); + describe("detects incorrect matches", () => { + it("works with number", () => { + expect(orMatch(5, 2, 3)).toBe(false); + }); + + it("works with boolean", () => { + expect(orMatch(false, true, !!1)).toBe(false); + }); + }); + describe("sensibly handles odd situations", () => { + it("returns truthiness of self when no rights given", () => { + expect(orMatch(5)).toBe(true); + expect(orMatch(0)).toBe(false); + }); + }); + }); + + + const greaterCompare = (l: number, r: number) => l > r; + describe("andWith", () => { + describe("detects correct matches", () => { + it("works with number", () => { + expect(andWith(10, greaterCompare, 5, 3, 9)).toBe(true); + }); + }); + describe("detects incorrect matches", () => { + it("works with number", () => { + expect(andWith(5, greaterCompare, 4, 10)).toBe(false); + }); + }); + describe("sensibly handles odd situations", () => { + it("returns truthiness of self when no rights given", () => { + expect(andWith(5, greaterCompare)).toBe(true); + }); + }); + }); + + describe("orWith", () => { + describe("detects correct matches", () => { + it("works with number", () => { + expect(orWith(5, greaterCompare, 10, 15, 3)).toBe(true); + }); + }); + describe("detects incorrect matches", () => { + it("works with number", () => { + expect(orWith(5, greaterCompare, 10, 20)).toBe(false); + }); + }); + describe("sensibly handles odd situations", () => { + it("returns truthiness of self when no rights given", () => { + expect(orWith(5, greaterCompare)).toBe(true); + }); + }); + }); +}); diff --git a/src/utils/common.ts b/src/utils/common.ts new file mode 100644 index 0000000..c88f61d --- /dev/null +++ b/src/utils/common.ts @@ -0,0 +1,91 @@ + +/** + * Helpful utility function to save on ugly looking chains of && checks. + * Before: (myObj.modeA === MyModes.On && myObj.modeB === MyModes.On) + * After: andMatch(MyModes.On, myObj.modeA, myObj.modeB) + * Uses strict equals. + * @param left The argument you're checking. + * @param rights n arguments you're checking against. + * @returns True if all match. If no rights given returns truthiness of left. + */ +export function andMatch(left: T, ...rights: T[]): boolean { + if (rights.length === 0) { + return !!left; + } + + for (const right of rights) { + if (left !== right) { + return false; + } + } + return true; +} + +/** + * Helpful utility function to save on ugly looking chains of || checks. + * @param left The argument you're checking. + * @param rights n arguments you're checking against. + * @returns True if any match. If no rights given returns truthiness of left. + */ +export function orMatch(left: T, ...rights: T[]): boolean { + if (rights.length === 0) { + return !!left; + } + + for (const right of rights) { + if (left === right) { + return true; + } + } + return false; +} + +/** + * Helpful function that essentially repackages the functionality of Array.every() + * into a slightly more sensible form. + * @param left The argument you're checking. + * @param func Predicate that returns a boolean. + * @param rights n arguments you're checking against. + * @returns True if all match. If no rights given returns truthiness of left. + */ +export function andWith( + left: T, + func: (l: T, r: T) => boolean, + ...rights: T[] +): boolean { + if (rights.length === 0) { + return !!left; + } + + for (const right of rights) { + if (!func(left, right)) { + return false; + } + } + return true; +} + +/** + * Helpful function that essentially repackages the functionality of Array.some() + * into a slightly more sensible form. + * @param left The argument you're checking. + * @param func Predicate that returns a boolean. + * @param rights n arguments you're checking against. + * @returns True if any match. If no rights given returns truthiness of left. + */ +export function orWith( + left: T, + func: (l: T, r: T) => boolean, + ...rights: T[] +): boolean { + if (rights.length === 0) { + return !!left; + } + + for (const right of rights) { + if (func(left, right)) { + return true; + } + } + return false; +}