diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx new file mode 100644 index 0000000..c620450 --- /dev/null +++ b/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx @@ -0,0 +1,17 @@ +import { theme } from "../../../shared/theme"; +import { MockupBlock } from "../../Common/MockupBlock.styled"; +import { TimingBoardLayout } from "./styles"; +import { TimingTower } from "./TimingTower"; + +export function TimingBoard() { + return ( + + + + + ); +} diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx index da69f2a..52a565b 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx @@ -35,7 +35,7 @@ import { export function TimingTower() { - const { lastUpdate, grid, trackLength, leaderGridSpot } = useSelector(eventSelector); + const { lastUpdate, grid, trackLength } = useSelector(eventSelector); const { timingBoard: { timingTower }, timingBoard: { timingTower: { splitsMode } } } = useSelector( broadcastGraphicsSelector, ); diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts b/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts index 513df0a..f59d8c0 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts @@ -56,6 +56,7 @@ const Rounded = styled.div` roundedCornerTop && css`border-top-right-radius: ${roundedCornerTop}px;`} ${({ roundedCornerBottom }) => roundedCornerBottom && css`border-bottom-right-radius: ${roundedCornerBottom}px;`} + transition: border-top-right-radius 500ms, border-bottom-right-radius 500ms; `; export const RowLeftHalf = styled(Rounded)` diff --git a/src/components/BroadcastGraphics/TimingBoard/index.ts b/src/components/BroadcastGraphics/TimingBoard/index.ts new file mode 100644 index 0000000..f1f5bb2 --- /dev/null +++ b/src/components/BroadcastGraphics/TimingBoard/index.ts @@ -0,0 +1 @@ +export * from "./TimingBoard"; diff --git a/src/components/BroadcastGraphics/TimingBoard/styles.ts b/src/components/BroadcastGraphics/TimingBoard/styles.ts new file mode 100644 index 0000000..480b8a2 --- /dev/null +++ b/src/components/BroadcastGraphics/TimingBoard/styles.ts @@ -0,0 +1,10 @@ +import styled from "styled-components"; + +export const TimingBoardLayout = styled.div` + position: relative; + + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: flex-start; +`; diff --git a/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx index 31f5c44..908f8fe 100644 --- a/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx +++ b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx @@ -1,33 +1,93 @@ import { InlineCluster } from "@bedrock-layout/inline-cluster"; +import { PadBox } from "@bedrock-layout/padbox"; +import { Split } from "@bedrock-layout/split"; import { useDispatch, useSelector } from "react-redux"; +import { broadcastDirectorSelector } from "../../../../features/broadcast/director/broadcastDirectorSelector"; + import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector"; import { setTimingTowerSplitsMode } from "../../../../features/broadcast/graphics/broadcastGraphicsSlice"; - -import { refreshRunningOrder } from "../../../../features/event/eventSlice"; -import { BGTimingTowerSplitsMode } from "../../../../types/state"; +import { eventSelector } from "../../../../features/event/eventSelector"; +import { increaseDistance, refreshRunningOrder, setCarStatus } from "../../../../features/event/eventSlice"; +import { BGTimingTowerSplitsMode, CarStatus } from "../../../../types/state"; +import { GridSelection } from "../GridSelection"; import { ClickSpan } from "./styles"; export function TimingTowerPrototypeControls() { const dispatch = useDispatch(); + const { selectedCars } = useSelector(broadcastDirectorSelector); const { timingBoard: { timingTower: { splitsMode } } } = useSelector(broadcastGraphicsSelector); + const { grid } = useSelector(eventSelector); return ( - - dispatch(refreshRunningOrder())}> + + + dispatch(refreshRunningOrder())}> Refresh Running Order - - { - if (splitsMode === BGTimingTowerSplitsMode.Interval) { - dispatch(setTimingTowerSplitsMode(BGTimingTowerSplitsMode.Leader)); - } else { - dispatch(setTimingTowerSplitsMode(BGTimingTowerSplitsMode.Interval)); - } - }} - > + + { + if (splitsMode === BGTimingTowerSplitsMode.Interval) { + dispatch(setTimingTowerSplitsMode(BGTimingTowerSplitsMode.Leader)); + } else { + dispatch(setTimingTowerSplitsMode(BGTimingTowerSplitsMode.Interval)); + } + }} + > Splits Mode = {BGTimingTowerSplitsMode[splitsMode]} - - + + { + dispatch(increaseDistance({ + cars: selectedCars, + distance: 200, + randomness: 0, + usePerformance: false, + })); + dispatch(refreshRunningOrder()); + }} + > + +200m to cars + + { + dispatch(increaseDistance({ + cars: grid, + distance: 100, + randomness: 0.05, + usePerformance: true, + })); + dispatch(refreshRunningOrder()); + }} + > + +100m performance to all + + { + dispatch(setCarStatus({ + cars: selectedCars, + status: CarStatus.Retired, + })); + dispatch(refreshRunningOrder()); + }} + > + Retire cars + + { + dispatch(setCarStatus({ + cars: selectedCars, + status: CarStatus.Normal, + })); + dispatch(refreshRunningOrder()); + }} + > + Un-retire cars + + + + + + ); } diff --git a/src/components/Workspaces/WorkspacesRoute.tsx b/src/components/Workspaces/WorkspacesRoute.tsx index 4788fd4..9b00cb2 100644 --- a/src/components/Workspaces/WorkspacesRoute.tsx +++ b/src/components/Workspaces/WorkspacesRoute.tsx @@ -18,7 +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"; +import { TimingBoard } from "../BroadcastGraphics/TimingBoard"; import { TimingTowerPrototypeControls } from "./PrototypingControls/TimingTowerPrototype"; const WORKSPACE_LIST_WIDTH = 180; @@ -94,7 +94,7 @@ export default function Workspaces() { } + previewContent={} prototypeControls={} bleedover={500} /> diff --git a/src/domain/data/teams.ts b/src/domain/data/teams.ts index 65ef0ec..9ffbd8e 100644 --- a/src/domain/data/teams.ts +++ b/src/domain/data/teams.ts @@ -13,60 +13,70 @@ export const teams: {[id: string]: Team} = { shortName: "Alfa Romeo", fullName: "Alfa Romeo F1 Team ORLEN", nationality: "CHE", + performance: 1.007, }, alphaTauri: { id: "alphaTauri", shortName: "AlphaTauri", fullName: "Scuderia AlphaTauri", nationality: "ITA", + performance: 1.016, }, alpine: { id: "alpine", shortName: "Alpine", fullName: "Alpine F1 Team", nationality: "FRA", + performance: 1.014, }, astonMartin: { id: "astonMartin", shortName: "Aston Martin", fullName: "Aston Martin Cognizant Formula One Team", nationality: "GBR", + performance: 1.012, }, ferrari: { id: "ferrari", shortName: "Ferrari", fullName: "Scuderia Ferrari", nationality: "ITA", + performance: 1.021, }, haas: { id: "haas", shortName: "Haas F1 Team", fullName: "Uralkali Haas F1 Team", nationality: "USA", + performance: 1.000, }, mclaren: { id: "mclaren", shortName: "McLaren", fullName: "McLaren F1 Team", nationality: "GBR", + performance: 1.020, }, mercedes: { id: "mercedes", shortName: "Mercedes", fullName: "Mercedes-AMG Petronas Formula One Team", nationality: "DEU", + performance: 1.025, }, redBull: { id: "redBull", shortName: "Red Bull Racing", fullName: "Red Bull Racing", nationality: "AUT", + performance: 1.024, }, williams: { id: "williams", shortName: "Williams", fullName: "Williams Racing", nationality: "GBR", + performance: 1.008, }, }; @@ -84,6 +94,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, // TBD initials: "ALB", nationality: "THA", + performance: 1.000, }, alonso: { id: "alonso", @@ -94,6 +105,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "ALO", nationality: "ESP", + performance: 1.003, }, bottas: { id: "bottas", @@ -104,6 +116,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "BOT", nationality: "FIN", + performance: 1.000, }, gasly: { id: "gasly", @@ -114,6 +127,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "GAS", nationality: "FRA", + performance: 1.020, }, giovinazzi: { id: "giovinazzi", @@ -124,6 +138,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "GIO", nationality: "ITA", + performance: 1.000, }, hamilton: { id: "hamilton", @@ -134,6 +149,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "HAM", nationality: "GBR", + performance: 1.010, }, kubica: { id: "kubica", @@ -144,6 +160,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "KUB", nationality: "POL", + performance: 0.980, }, latifi: { id: "latifi", @@ -154,6 +171,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "LAT", nationality: "CAN", + performance: 1.000, }, leclerc: { id: "leclerc", @@ -164,6 +182,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "LEC", nationality: "MCO", + performance: 1.005, }, mazepin: { id: "mazepin", @@ -174,6 +193,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "MAZ", nationality: "RAF", + performance: 1.000, }, norris: { id: "norris", @@ -184,6 +204,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "NOR", nationality: "GBR", + performance: 1.009, }, ocon: { id: "ocon", @@ -194,6 +215,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "OCO", nationality: "FRA", + performance: 1.000, }, perez: { id: "perez", @@ -204,6 +226,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "PER", nationality: "MEX", + performance: 1.000, }, raikkonen: { id: "raikkonen", @@ -214,6 +237,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "RAI", nationality: "FIN", + performance: 1.002, }, ricciardo: { id: "ricciardo", @@ -224,6 +248,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "RIC", nationality: "AUS", + performance: 1.000, }, russell: { id: "russell", @@ -234,6 +259,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "RUS", nationality: "GBR", + performance: 1.016, }, sainz: { id: "sainz", @@ -244,6 +270,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "SAI", nationality: "ESP", + performance: 1.000, }, schumacher: { id: "schumacher", @@ -254,6 +281,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "MSC", nationality: "DEU", + performance: 1.025, }, stroll: { id: "stroll", @@ -264,6 +292,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "STR", nationality: "CAN", + performance: 1.000, }, tsunoda: { id: "tsunoda", @@ -274,6 +303,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "TSU", nationality: "JPN", + performance: 1.000, }, verstappen: { id: "verstappen", @@ -284,6 +314,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: false, initials: "VER", nationality: "NLD", + performance: 1.020, }, vettel: { id: "vettel", @@ -294,6 +325,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "VET", nationality: "DEU", + performance: 1.003, }, zhou: { id: "zhou", @@ -304,6 +336,7 @@ export const drivers: {[lastName: string]: Driver} = { yellowTCam: true, initials: "ZHO", nationality: "CHN", + performance: 1.000, }, }; diff --git a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts index 07ff80a..9d1eb55 100644 --- a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts +++ b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts @@ -16,7 +16,7 @@ const initialState: RootState["broadcastGraphics"] = { relativePos: {}, openState: 0, statusIndicator: { - mode: BGStatusIndicatorModes.NormalNarrow, + mode: BGStatusIndicatorModes.LapNarrow, }, timingTower: { open: 1, diff --git a/src/features/event/eventSlice.ts b/src/features/event/eventSlice.ts index bb688c3..849fb66 100644 --- a/src/features/event/eventSlice.ts +++ b/src/features/event/eventSlice.ts @@ -1,7 +1,22 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; +import { random } from "lodash"; -import { CourseFlag, CarStatus, RootState, Tyre, TyreCompound, CarNotice } from "../../types/state"; -import { cloneDriver } from "../../utils/dataLookup"; +import { + CourseFlag, + CarStatus, + RootState, + Tyre, + TyreCompound, + CarNotice, + EventMode, + SectorFlag, + SafetyCarStatus, + VirtualSafetyCarStatus, + Car, +} from "../../types/state"; +import { Meters } from "../../types/util"; +import { cloneDriver, getTeam } from "../../utils/dataLookup"; +import { driverToGridMap } from "../../utils/event"; const DEFAULT_TYRE: Tyre = { compound: TyreCompound.Medium, @@ -9,16 +24,19 @@ const DEFAULT_TYRE: Tyre = { new: true, }; +const GRID_POSITION_GAP: Meters = 8; +const POLE_TO_START: Meters = 10; + const initialState: RootState["event"] = { trackName: "Circuit de Spa-Franchorchamps", trackLength: 7004, courseStatus: { - courseFlag: "green", - sectorFlags: ["green", "green", "green"], - safetyCar: "clear", - virtualSafetyCar: "clear", + courseFlag: CourseFlag.Green, + sectorFlags: [SectorFlag.Green, SectorFlag.Green, SectorFlag.Green], + safetyCar: SafetyCarStatus.Clear, + virtualSafetyCar: VirtualSafetyCarStatus.Clear, }, - mode: "race", + mode: EventMode.Race, progress: { startTime: Date.now(), timeLimit: 60 * 60 * 2 * 1000, @@ -32,7 +50,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [CarNotice.FastestLap], - distance: 2000 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 0, driver: cloneDriver("verstappen"), }, { @@ -40,7 +58,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 1900 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 1, driver: cloneDriver("hamilton"), }, { @@ -48,7 +66,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 1800 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 2, driver: cloneDriver("bottas"), }, { @@ -56,7 +74,7 @@ const initialState: RootState["event"] = { status: CarStatus.Retired, tyre: DEFAULT_TYRE, notices: [], - distance: 1700 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 3, driver: cloneDriver("perez"), }, { @@ -64,7 +82,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 1600 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 4, driver: cloneDriver("sainz"), }, { @@ -72,7 +90,7 @@ const initialState: RootState["event"] = { status: CarStatus.Retired, tyre: DEFAULT_TYRE, notices: [], - distance: 1500 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 5, driver: cloneDriver("norris"), }, { @@ -80,7 +98,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 1400 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 6, driver: cloneDriver("leclerc"), }, { @@ -88,15 +106,15 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 1300 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 7, driver: cloneDriver("ricciardo"), }, { position: 9, - status: CarStatus.DidNotStart, + status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 1200 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 8, driver: cloneDriver("gasly"), }, { @@ -104,7 +122,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 1100 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 9, driver: cloneDriver("alonso"), }, { @@ -112,7 +130,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 1000 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 10, driver: cloneDriver("ocon"), }, { @@ -120,7 +138,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 900 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 11, driver: cloneDriver("vettel"), }, { @@ -128,7 +146,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 800 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 12, driver: cloneDriver("stroll"), }, { @@ -136,7 +154,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 700 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 13, driver: cloneDriver("tsunoda"), }, { @@ -144,7 +162,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 600 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 14, driver: cloneDriver("russell"), }, { @@ -152,7 +170,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 500 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 15, driver: cloneDriver("raikkonen"), }, { @@ -160,7 +178,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 400 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 16, driver: cloneDriver("latifi"), }, { @@ -168,7 +186,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 300 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 17, driver: cloneDriver("giovinazzi"), }, { @@ -176,7 +194,7 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 200 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 18, driver: cloneDriver("schumacher"), }, { @@ -184,13 +202,25 @@ const initialState: RootState["event"] = { status: CarStatus.Normal, tyre: DEFAULT_TYRE, notices: [], - distance: 100 * 4, + distance: POLE_TO_START - GRID_POSITION_GAP * 19, driver: cloneDriver("mazepin"), }, ], lastUpdate: Date.now(), }; +interface IncreaseDistanceAction { + cars: Car[]; + distance: Meters; + randomness: number; + usePerformance: boolean; +} + +interface SetCarStatusAction { + cars: Car[]; + status: CarStatus; +} + export const eventSlice = createSlice({ name: "event", initialState, @@ -226,11 +256,57 @@ export const eventSlice = createSlice({ state.leaderGridSpot = sortingGrid[0].gridSpot; state.lastUpdate = Date.now(); }, + increaseDistance: (state, action: PayloadAction) => { + const gridMap = driverToGridMap(state.grid); + + const { cars, distance, randomness, usePerformance } = action.payload; + + cars.forEach(car => { + let addedDistance = distance; + + if (randomness !== 0){ + addedDistance *= random(1 - randomness, 1 + randomness); + } + if (usePerformance) { + addedDistance *= + getTeam(car.driver.team.id).performance + car.driver.performance; + } + state.grid[gridMap[car.driver.id]].distance += addedDistance; + }); + state.lastUpdate = Date.now(); + }, + awardFastestLap: (state, action: PayloadAction) => { + // Awards fastest lap to provided car. Removes fastest lap from anyone else. + state.grid.forEach((car, index) => { + const fastestLapNoticeIndex = car.notices.findIndex( + notice => notice === CarNotice.FastestLap, + ); + if (car.driver.id === action.payload.driver.id) { + if (fastestLapNoticeIndex === -1) { + state.grid[index].notices.push(CarNotice.FastestLap); + } + } else if (fastestLapNoticeIndex !== -1) { + state.grid[index].notices.splice(fastestLapNoticeIndex, 1); + } + }); + state.lastUpdate = Date.now(); + }, + setCarStatus: (state, action: PayloadAction) => { + const gridMap = driverToGridMap(state.grid); + const { cars, status } = action.payload; + cars.forEach(car => { + state.grid[gridMap[car.driver.id]].status = status; + }); + state.lastUpdate = Date.now(); + }, }, }); export const { setCourseFlag, refreshRunningOrder, + increaseDistance, + awardFastestLap, + setCarStatus, } = eventSlice.actions; export default eventSlice.reducer; diff --git a/src/types/state.ts b/src/types/state.ts index 97a1a1b..9c95c0f 100644 --- a/src/types/state.ts +++ b/src/types/state.ts @@ -74,7 +74,7 @@ export interface Event { courseStatus: CourseStatus; mode: EventMode; progress: EventProgress; - leaderGridSpot: GridSpot; + leaderGridSpot: GridSpot; // Might be removed. grid: Grid; // gridPositions: GridSpot[]; lastUpdate: number; @@ -85,39 +85,49 @@ export interface EventProgress { currentLap: number; lapCount: number; } -export type EventMode = - | "race" - | "sprint" - | "p1" - | "p2" - | "p3" - | "q1" - | "q2" - | "q3"; +export enum EventMode { + Race, + Sprint, + Practice1, + Practice2, + Practice3, + Qualifying1, + Qualifying2, + Qualifying3, +} export interface CourseStatus { courseFlag: CourseFlag; - sectorFlags: CourseFlag[]; + sectorFlags: SectorFlag[]; 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 enum CourseFlag { + Green, + Yellow, + Chequered, + Red, +} + +export enum SectorFlag { + Green, + Yellow, + DoubleYellow, + White, + RedYellow, +} + +export enum SafetyCarStatus { Clear, Starting, Out, Ending } +export enum VirtualSafetyCarStatus { Clear, Active, Ending } export type Grid = Car[]; // Grid order does not change. export type GridSpot = number; export interface Car { - position: number; + position: number; // Position is DERIVED from distance and status. driver: Driver; status: CarStatus; tyre: Tyre; - // flags: ???, // blue, red, meatball, black/white, black + // tyreHistory: Tyre[]; + // pitsCompleted: number; notices: CarNotice[]; distance: Meters; } @@ -130,6 +140,7 @@ export interface Driver { yellowTCam: boolean; initials: string; nationality: string; // ISO 3166-1 alpha-3 codes + performance: Fraction; // Versus teammate } export type DriverId = | "albon" @@ -199,6 +210,7 @@ export interface Team { shortName: TeamShortName; fullName: TeamFullName; nationality: string; // ISO 3166-1 alpha-3 codes + performance: Fraction; // logo: string; } export type TeamId = @@ -275,8 +287,8 @@ export interface BGStatusIndicator { mode: BGStatusIndicatorModes; } export enum BGStatusIndicatorModes { - NormalNarrow, // "LAP" above "##/##" lap count. - NormalWide, // "LAP" to the left of "##/##" lap count. + LapNarrow, // "LAP" above "##/##" lap count. + LapWide, // "LAP" to the left of "##/##" lap count. } // Timing Tower diff --git a/src/utils/dataLookup.ts b/src/utils/dataLookup.ts index f39b9b9..33cc73f 100644 --- a/src/utils/dataLookup.ts +++ b/src/utils/dataLookup.ts @@ -1,6 +1,6 @@ import { cloneDeep } from "lodash"; import { drivers, teams, teamNumberStyles, teamFlagStyles, teamGemStyles } from "../domain/data/teams"; -import { DriverId, Team, TeamId } from "../types/state"; +import { DriverId, TeamId } from "../types/state"; /** * Prefer getting data from teams.ts through these simple getter functions. diff --git a/src/utils/event.ts b/src/utils/event.ts index 6208d66..18cb8d6 100644 --- a/src/utils/event.ts +++ b/src/utils/event.ts @@ -1,4 +1,3 @@ -import { random } from "lodash"; import { Car, Grid } from "../types/state"; import { Meters } from "../types/util"; @@ -13,7 +12,7 @@ export function timeDiff( * 61.015 m/s average. So, let's do that. */ - return random(0.95, 1.05) * ((front - back) / 61.015); + return (front - back) / 61.015; } @@ -27,3 +26,18 @@ export function getCarAtPos( } return foundCar; } + +/** + * Helper function returns a map of driver ids to their index in the Grid. This + * removes the need for repeating find functions over and over again when making + * bulk changes to a list of cars. + * @param grid Master list of cars + * @returns + */ +export function driverToGridMap(grid: Grid) { + const gridMap: { [driverId: string]: number } = {}; + grid.forEach((car, index) => { + gridMap[car.driver.id] = index; + }); + return gridMap; +}