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/AngledFlag/styles.ts b/src/components/BroadcastGraphics/Common/AngledFlag/styles.ts index 763873a..1d3012c 100644 --- a/src/components/BroadcastGraphics/Common/AngledFlag/styles.ts +++ b/src/components/BroadcastGraphics/Common/AngledFlag/styles.ts @@ -98,7 +98,7 @@ type TeamFlagDivProps = { style: TeamFlagStyle, bottomFlag?: boolean, }; -export const TeamFlagDiv = styled(FlagDivBase) ` +export const TeamFlagDiv = styled(FlagDivBase)` height: ${({ height }) => `${height}px`}; width: ${({ width }) => `${width}px`}; diff --git a/src/components/BroadcastGraphics/Common/PositionFlag/PositionFlag.tsx b/src/components/BroadcastGraphics/Common/PositionFlag/PositionFlag.tsx index 7903f6a..e70f099 100644 --- a/src/components/BroadcastGraphics/Common/PositionFlag/PositionFlag.tsx +++ b/src/components/BroadcastGraphics/Common/PositionFlag/PositionFlag.tsx @@ -1,15 +1,16 @@ -import { Px } from "../../../../types/style"; +import { Fraction, Px } from "../../../../types/style"; import { PositionFlagBox, PositionNumber } from "./styles"; type PositionFlagProps = { size: Px, number: number, + numberSizeFraction?: Fraction, }; -export function PositionFlag({ size, number }: PositionFlagProps) { +export function PositionFlag({ size, number, numberSizeFraction = 0.64 }: PositionFlagProps) { return ( - + {number} diff --git a/src/components/BroadcastGraphics/Common/PositionFlag/styles.ts b/src/components/BroadcastGraphics/Common/PositionFlag/styles.ts index d9cfbbe..e9ffc4c 100644 --- a/src/components/BroadcastGraphics/Common/PositionFlag/styles.ts +++ b/src/components/BroadcastGraphics/Common/PositionFlag/styles.ts @@ -23,7 +23,7 @@ type PositionNumberProps = { }; export const PositionNumber = styled.span` font-family: ${p => p.theme.fonts.f1Regular}; - font-size: ${({ size }) => `${size * 0.64}px`}; + font-size: ${({ size }) => size}px; margin-top: 2px; `; PositionNumber.displayName = "PositionNumber"; 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/Common/TeamGem/TeamGem.tsx b/src/components/BroadcastGraphics/Common/TeamGem/TeamGem.tsx new file mode 100644 index 0000000..c567b1a --- /dev/null +++ b/src/components/BroadcastGraphics/Common/TeamGem/TeamGem.tsx @@ -0,0 +1,26 @@ +import { TeamId } from "../../../../types/state"; +import { Px } from "../../../../types/style"; +import { getTeamGemStyle } from "../../../../utils/dataLookup"; +import { GemColorDiv, GemContainer, GemLogoDiv } from "./styles"; + +const teamLogos = require.context("../../../../public/images/logos/team", true); + +type TeamGemProps = { + height: Px, + team: TeamId, +}; +export function TeamGem({ height, team }: TeamGemProps) { + return ( + + + + + ); +} diff --git a/src/components/BroadcastGraphics/Common/TeamGem/index.ts b/src/components/BroadcastGraphics/Common/TeamGem/index.ts new file mode 100644 index 0000000..af964e0 --- /dev/null +++ b/src/components/BroadcastGraphics/Common/TeamGem/index.ts @@ -0,0 +1 @@ +export * from "./TeamGem"; diff --git a/src/components/BroadcastGraphics/Common/TeamGem/styles.ts b/src/components/BroadcastGraphics/Common/TeamGem/styles.ts new file mode 100644 index 0000000..02ad60b --- /dev/null +++ b/src/components/BroadcastGraphics/Common/TeamGem/styles.ts @@ -0,0 +1,60 @@ +import styled from "styled-components"; +import { TeamGemStyle } from "../../../../domain/data/teams"; +import { Px } from "../../../../types/style"; + + +const GEM_WIDTH_RATIO = 1.21; + +type GemContainerProps = { + height: Px, +}; +export const GemContainer = styled.div` + position: relative; + height: ${({ height }) => height}px; + width: ${({ height }) => height * GEM_WIDTH_RATIO}px; + + overflow: hidden; + background-color: black; + border-bottom-right-radius: 3px; + + mask-image: linear-gradient(to left, black 0%, black 80%, transparent 100%); + clip-path: polygon(40% 0, 100% 0, 100% 100%, 0 100%, 0 50%); +`; +GemContainer.displayName = "GemContainer"; + +type GemColorDivProps = { + height: Px, + gemStyle: TeamGemStyle, +}; +export const GemColorDiv = styled.div` + position: absolute; + height: 100%; + width: 100%; + + background-image: radial-gradient( + circle at 120% 160%, + ${({ gemStyle: { backgroundColor } }) => backgroundColor} 50%, + black 100% + ); + background-size: 100%; + background-repeat: no-repeat; +`; + +type GemLogoDivProps = { + height: Px, + gemStyle: TeamGemStyle, + src: string, +}; +export const GemLogoDiv = styled.div` + position: absolute; + height: 100%; + width: 100%; + + background-image: url(${({ src }) => src}); + background-size: ${({ gemStyle: { imageSize } }) => imageSize}%; + background-position: ${({ height, gemStyle: { imagePos: { x, y } } }) => ( + `${height * GEM_WIDTH_RATIO * x}px ${height * y}px` + )}; + background-repeat: no-repeat; +`; +GemLogoDiv.displayName = "GemDiv"; diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx new file mode 100644 index 0000000..da69f2a --- /dev/null +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTower.tsx @@ -0,0 +1,165 @@ +import { useEffect, useState } from "react"; +import { useSelector } from "react-redux"; + +import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector"; +import { eventSelector } from "../../../../features/event/eventSelector"; +import { theme } from "../../../../shared/theme"; +import { + BGTimingTowerDisplayModes, + BGTimingTowerSplitsMode, + Car, + CarNotice, + CarStatus, +} from "../../../../types/state"; +import { Fraction } from "../../../../types/style"; +import { orMatch } from "../../../../utils/common"; +import { getCarAtPos, timeDiff } from "../../../../utils/event"; +import { formatTime } from "../../../../utils/styling"; + +import { PositionFlag } from "../../Common/PositionFlag"; +import { TeamGem } from "../../Common/TeamGem"; + +import { + DriverName, + FastestLapGem, + AnimatedRowContainer, + RowLeftHalf, + RowLeftHalfGemContainer, + RowLeftHalfLayout, + RowRightHalf, + RowRightHalfLayout, + RowsContainer, + TimeDiff, +} from "./styles"; + + +export function TimingTower() { + + const { lastUpdate, grid, trackLength, leaderGridSpot } = useSelector(eventSelector); + const { timingBoard: { timingTower }, timingBoard: { timingTower: { splitsMode } } } = useSelector( + broadcastGraphicsSelector, + ); + + const [startingCarsCount, setStartingCarsCount] = useState(0); + const [retiredCarsCount, setRetiredCarsCount] = useState(0); + const [rows, setRows] = useState([]); + + useEffect(() => { + // Filter away cars that are marked as not starting so they don't appear. + const startingGrid = grid.filter(car => car.status !== CarStatus.DidNotStart); + setStartingCarsCount(startingGrid.length); + + let retiredCount = 0; + startingGrid.forEach(car => { + if (car.status === CarStatus.Retired) { + ++retiredCount; + } + }); + setRetiredCarsCount(retiredCount); + + setRows(startingGrid.map(car => buildRow(car, startingGrid.length, retiredCount))); + }, [lastUpdate, splitsMode]); + + + const buildRow = ( + car: Car, + startingCarsCount: number, + retiredCarsCount: number, + ) => { + const bottomRounded = car.status === CarStatus.Retired ? ( + car.position === startingCarsCount + ) : ( + car.position === startingCarsCount - retiredCarsCount + ); + + let rightHalfContent = ""; + let xScale: Fraction = 1.0; + let yScale: Fraction = 1.0; + + if (car.position === 1) { + rightHalfContent = splitsMode === BGTimingTowerSplitsMode.Leader + ? "Leader" : splitsMode === BGTimingTowerSplitsMode.Interval + ? "Interval" : ""; + } else if (car.status === CarStatus.Retired) { + rightHalfContent = "OUT"; + } else { + const deltaCar = getCarAtPos( + grid, + splitsMode === BGTimingTowerSplitsMode.Leader ? 1 : car.position - 1, + ); + + const plusLaps = Math.floor((deltaCar.distance - car.distance) / trackLength); + + rightHalfContent = + splitsMode === BGTimingTowerSplitsMode.Leader && plusLaps > 0 + ? `+${plusLaps} LAP${plusLaps > 1 ? "S" : ""}` + : `+${formatTime(timeDiff(deltaCar.distance, car.distance), 60)}`; + + xScale = rightHalfContent.includes(":") ? 0.75 : 0.9; + yScale = rightHalfContent.includes("+") ? 1.1 : 1.0; + } + + return ( + + {car.notices.includes(CarNotice.FastestLap) && ( + + )} + + + {car.status !== CarStatus.Retired && ( + + )} + + {car.driver.initials} + + + + + + + + + + {rightHalfContent} + + + + + ); + }; + + return ( + 0} + > + {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..513df0a --- /dev/null +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts @@ -0,0 +1,160 @@ +import styled, { css } from "styled-components"; +import { animated } from "@react-spring/web"; + +import { Fraction, Px } from "../../../../types/style"; + +import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg"; + +type RowsContainerProps = { + carsToDisplay: number, + retiredCarsPresent: boolean, +}; +export const RowsContainer = styled.div` + position: relative; + + width: ${p => + p.theme.design.timingTower.rowLeftHalfWidthPx + + p.theme.design.timingTower.rowRightHalfWidthPx}px; + height: ${({ theme, carsToDisplay, retiredCarsPresent }) => + theme.design.timingTower.rowHeightPx * carsToDisplay + (retiredCarsPresent ? 3 : 0)}px; + + overflow-y: clip; // hidden doesn't work for some reason. +`; +RowsContainer.displayName = "RowsContainer"; + +type AnimatedRowContainerProps = { + retired?: boolean, + wide?: boolean, + top: Px, +}; +// All the elements in a row should go in here. +export const AnimatedRowContainer = animated(styled.div.attrs(({ + top, + retired, +}) => ({ + style: { + top: `${top + (retired ? 3 : 0)}px`, + }, +}))` + position: absolute; + left: 0; + transition: top 500ms; + + width: ${({ wide }) => wide ? 255 : 147}px; + height: ${p => p.theme.design.timingTower.rowHeightPx}px; // Future will be animated. + + ${({ retired }) => retired && css`opacity: 0.7;`} +`); +AnimatedRowContainer.displayName = "AnimatedRowContainer"; + +type RoundedProp = { + roundedCornerTop?: Px, + roundedCornerBottom?: Px, +}; +const Rounded = styled.div` + ${({ roundedCornerTop }) => + roundedCornerTop && css`border-top-right-radius: ${roundedCornerTop}px;`} + ${({ roundedCornerBottom }) => + roundedCornerBottom && css`border-bottom-right-radius: ${roundedCornerBottom}px;`} +`; + +export const RowLeftHalf = styled(Rounded)` + position: absolute; + left: 0; + top: 0; + + width: ${p => p.theme.design.timingTower.rowLeftHalfWidthPx}px; // Future will be animated. + height: ${p => p.theme.design.timingTower.rowHeightPx}px; + + background-color: #000000e5 +`; +RowLeftHalf.displayName = "RowLeftHalf"; + +export const RowLeftHalfLayout = styled.div` + position: relative; + width: 100%; + height: 100%; + + display: flex; + padding-left: 3px; + + align-items: center; + justify-content: flex-start; +`; +RowLeftHalfLayout.displayName = "RowLeftHalfLayout"; + +export const RowLeftHalfGemContainer = styled.div` + position: absolute; + right: 0; + top: 0; + margin-top: 2px; +`; +RowLeftHalfGemContainer.displayName = "RowLeftHalfGemContainer"; + +export const RowRightHalf = styled(Rounded)` + position: absolute; + right: 0; + top: 0; + + width: ${p => p.theme.design.timingTower.rowRightHalfWidthPx}px; // Future will be animated. + height: ${p => p.theme.design.timingTower.rowHeightPx}px; + + overflow-x: hidden; + + background-color: #0000007e +`; +RowRightHalf.displayName = "RowRightHalf"; + +export const RowRightHalfLayout = styled.div` + width: 100%; + height: 100%; + + display: flex; + + align-items: center; + justify-content: flex-end; + padding-right: 8px; +`; +RowRightHalfLayout.displayName = "RowRightHalfLayout"; + +export const DriverName = styled.span` + color: white; + font-family: ${p => p.theme.fonts.f1Bold}; + font-size: 20px; + margin-left: 14px; +`; +DriverName.displayName = "DriverName"; + +type TimeDiffProps = { + xScale: Fraction, + yScale: Fraction, +}; +export const TimeDiff = styled.span` + color: white; + font-family: ${p => p.theme.fonts.f1Regular}; + font-size: 20px; + + text-align: end; + + font-feature-settings: 'tnum' 1; + transform-origin: top right; + transform: scale(${({ xScale, yScale }) => `${xScale}, ${yScale}`}); +`; +TimeDiff.displayName = "TimeDiff"; + +export const FastestLapGem = styled.div` + position: absolute; + + height: ${p => p.theme.design.timingTower.rowHeightPx}px; + width: ${p => p.theme.design.timingTower.rowHeightPx - 2}px; + + left: ${p => -p.theme.design.timingTower.rowHeightPx + 2}px; + top: 0; + + background-color: ${p => p.theme.colors.laps.purple}; + background-image: url(${fastestLapIcon}); + background-repeat: no-repeat; + background-size: 89%; + background-position: center 40%; +`; +FastestLapGem.displayName = "FastestLapGem"; diff --git a/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx b/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx index 4a0107d..7046b91 100644 --- a/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx +++ b/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx @@ -5,6 +5,8 @@ import useMeasure from "react-use-measure"; import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector"; import { setPosition } from "../../../features/overlayTool/overlayToolSlice"; +import { Px } from "../../../types/style"; + import { OverlayImage, OverlayImageContainer, @@ -16,10 +18,10 @@ const overlayImages = require.context("../../../public/images/overlays", true); type OverlayDisplayProps = { containerDimensions: { - width: number, - height: number, + width: Px, + height: Px, }, - bleedover?: number, + bleedover?: Px, }; export function OverlayDisplay({ containerDimensions: { width: containerWidth, height: containerHeight }, diff --git a/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx new file mode 100644 index 0000000..31f5c44 --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx @@ -0,0 +1,33 @@ +import { InlineCluster } from "@bedrock-layout/inline-cluster"; +import { useDispatch, useSelector } from "react-redux"; +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 { ClickSpan } from "./styles"; + +export function TimingTowerPrototypeControls() { + const dispatch = useDispatch(); + const { timingBoard: { timingTower: { splitsMode } } } = useSelector(broadcastGraphicsSelector); + + return ( + + dispatch(refreshRunningOrder())}> + Refresh Running Order + + { + if (splitsMode === BGTimingTowerSplitsMode.Interval) { + dispatch(setTimingTowerSplitsMode(BGTimingTowerSplitsMode.Leader)); + } else { + dispatch(setTimingTowerSplitsMode(BGTimingTowerSplitsMode.Interval)); + } + }} + > + Splits Mode = {BGTimingTowerSplitsMode[splitsMode]} + + + ); +} diff --git a/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/index.ts b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/index.ts new file mode 100644 index 0000000..957fa28 --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/index.ts @@ -0,0 +1 @@ +export * from "./TimingTowerPrototypeControls"; diff --git a/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/styles.ts b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/styles.ts new file mode 100644 index 0000000..886a9ad --- /dev/null +++ b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/styles.ts @@ -0,0 +1,7 @@ +import styled from "styled-components"; + +export const ClickSpan = styled.span` + font-family: ${p => p.theme.fonts.f1Bold}; + font-size: 0.9em; + cursor: pointer; +`; diff --git a/src/components/Workspaces/Workspace/Workspace.tsx b/src/components/Workspaces/Workspace/Workspace.tsx index 98c02cd..af6bc3a 100644 --- a/src/components/Workspaces/Workspace/Workspace.tsx +++ b/src/components/Workspaces/Workspace/Workspace.tsx @@ -8,24 +8,27 @@ import { updateWorkspace } from "../../../features/workspace/workspaceSlice"; import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector"; import { newWorkspace } from "../../../features/overlayTool/overlayToolSlice"; +import { Px } from "../../../types/style"; +import { workspaces } from "../../../domain/data/workspaces"; +import { WorkspaceId } from "../../../types/state"; + import { PreviewWindow, H2, ControlsContainer } from "./styles"; import { WorkspaceControls } from "../WorkspaceControls"; import { OverlayDisplay } from "../../OverlayTool"; -import { workspaces } from "../../../domain/data/workspaces"; -import { WorkspaceId } from "../../../types/state"; - type WorkspaceProps = { workspaceId: WorkspaceId, previewContent: ReactNode, prototypeControls: ReactNode, showAnimationSpeedSelector?: boolean, + bleedover?: Px, }; export const Workspace = ({ workspaceId, previewContent, prototypeControls, showAnimationSpeedSelector = false, + bleedover, }: WorkspaceProps) => { const dispatch = useDispatch(); const { animatedBG, darkBG, workspaceProperties } = useSelector(workspaceSelector); @@ -63,6 +66,7 @@ export const Workspace = ({ {previewContent} diff --git a/src/components/Workspaces/WorkspacesRoute.tsx b/src/components/Workspaces/WorkspacesRoute.tsx index 34e33e5..4788fd4 100644 --- a/src/components/Workspaces/WorkspacesRoute.tsx +++ b/src/components/Workspaces/WorkspacesRoute.tsx @@ -18,6 +18,8 @@ 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 { TimingTowerPrototypeControls } from "./PrototypingControls/TimingTowerPrototype"; const WORKSPACE_LIST_WIDTH = 180; @@ -89,6 +91,14 @@ export default function Workspaces() { prototypeControls={} /> } /> + } + prototypeControls={} + bleedover={500} + /> + } /> Unknown Workspace} /> diff --git a/src/domain/data/teams.ts b/src/domain/data/teams.ts index bee40f2..65ef0ec 100644 --- a/src/domain/data/teams.ts +++ b/src/domain/data/teams.ts @@ -496,3 +496,64 @@ export const teamFlagStyles: { [teamId: string]: TeamFlagStyle } = { subFlagModifier: { x: 1, y: 1, scale: .98 }, }, }; + +export type TeamGemStyle = { + backgroundColor: string, + imageSize: Percent, + imagePos: { + x: number, + y: number, + }, +}; +export const teamGemStyles: { [teamId: string]: TeamGemStyle } = { + alfaRomeo: { + backgroundColor: "#660000", + imageSize: 65, + imagePos: { x: .28, y: .15 }, + }, + alphaTauri: { + backgroundColor: "#232c3b", + imageSize: 75, + imagePos: { x: .26, y: .07 }, + }, + alpine: { + backgroundColor: "black", + imageSize: 82, + imagePos: { x: .13, y: 0 }, + }, + astonMartin: { + backgroundColor: "#037356", + imageSize: 130, + imagePos: { x: .05, y: -.22 }, + }, + ferrari: { + backgroundColor: "#dc0000", + imageSize: 65, + imagePos: { x: .3, y: .18 }, + }, + haas: { + backgroundColor: "#f0f0f0", + imageSize: 65, + imagePos: { x: .25, y: .12 }, + }, + mclaren: { + backgroundColor: "#545459", + imageSize: 67, + imagePos: { x: .25, y: .1 }, + }, + mercedes: { + backgroundColor: "#1ee0ad", + imageSize: 63, + imagePos: { x: .31, y: .16 }, + }, + redBull: { + backgroundColor: "#413ae2", + imageSize: 130, + imagePos: { x: .20, y: .05 }, + }, + williams: { + backgroundColor: "#12a0cb", + imageSize: 65, + imagePos: { x: .3, y: .12 }, + }, +}; diff --git a/src/domain/data/workspaces.ts b/src/domain/data/workspaces.ts index 4268687..7c2be15 100644 --- a/src/domain/data/workspaces.ts +++ b/src/domain/data/workspaces.ts @@ -84,4 +84,17 @@ export const workspaces: WorkspaceObject = { height: 500, }, }, + timingBoard: { + name: "Timing Board", + overlayIds: [ + "timing-board-leader-19.png", + "timing-board-leader-20-out-1.png", + "timing-board-intervals-yellow-flag.png", + "timing-board-portrait-gap.png", + ], + previewWindowDimensions: { + width: 700, + height: 900, + }, + }, }; diff --git a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts index a169905..07ff80a 100644 --- a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts +++ b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts @@ -1,9 +1,31 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { BGChyrons, OpenState, RootState } from "../../../types/state"; +import { + BGChyrons, + BGStatusIndicatorModes, + BGTimingTowerDisplayModes, + BGTimingTowerFocusedCarsMode, + BGTimingTowerSplitsMode, + OpenState, + RootState, +} from "../../../types/state"; const initialState: RootState["broadcastGraphics"] = { chyrons: null, + timingBoard: { + relativePos: {}, + openState: 0, + statusIndicator: { + mode: BGStatusIndicatorModes.NormalNarrow, + }, + timingTower: { + open: 1, + displayMode: BGTimingTowerDisplayModes.LeftAndRight, + splitsMode: BGTimingTowerSplitsMode.Leader, + focusedCars: [], + focusedCarsMode: BGTimingTowerFocusedCarsMode.None, + }, + }, }; export const broadcastGraphicsSlice = createSlice({ @@ -32,6 +54,11 @@ export const broadcastGraphicsSlice = createSlice({ clearChyrons: (state) => { state.chyrons = null; }, + + // Timing Board + setTimingTowerSplitsMode: (state, action: PayloadAction) => { + state.timingBoard.timingTower.splitsMode = action.payload; + }, }, }); @@ -40,5 +67,6 @@ export const { setChyronsOpenState, incrementChyronsOpenState, clearChyrons, + setTimingTowerSplitsMode, } = broadcastGraphicsSlice.actions; export default broadcastGraphicsSlice.reducer; diff --git a/src/features/event/eventSlice.ts b/src/features/event/eventSlice.ts index 4ad46cd..bb688c3 100644 --- a/src/features/event/eventSlice.ts +++ b/src/features/event/eventSlice.ts @@ -1,10 +1,17 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { CourseFlag, RootState } from "../../types/state"; +import { CourseFlag, CarStatus, RootState, Tyre, TyreCompound, CarNotice } from "../../types/state"; import { cloneDriver } from "../../utils/dataLookup"; +const DEFAULT_TYRE: Tyre = { + compound: TyreCompound.Medium, + age: 0, + new: true, +}; + const initialState: RootState["event"] = { - trackName: "Melbourne", + trackName: "Circuit de Spa-Franchorchamps", + trackLength: 7004, courseStatus: { courseFlag: "green", sectorFlags: ["green", "green", "green"], @@ -18,28 +25,170 @@ const initialState: RootState["event"] = { currentLap: 1, lapCount: 10, }, + leaderGridSpot: 0, 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, + tyre: DEFAULT_TYRE, + notices: [CarNotice.FastestLap], + distance: 2000 * 4, + driver: cloneDriver("verstappen"), + }, + { + position: 2, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1900 * 4, + driver: cloneDriver("hamilton"), + }, + { + position: 3, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1800 * 4, + driver: cloneDriver("bottas"), + }, + { + position: 4, + status: CarStatus.Retired, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1700 * 4, + driver: cloneDriver("perez"), + }, + { + position: 5, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1600 * 4, + driver: cloneDriver("sainz"), + }, + { + position: 6, + status: CarStatus.Retired, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1500 * 4, + driver: cloneDriver("norris"), + }, + { + position: 7, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1400 * 4, + driver: cloneDriver("leclerc"), + }, + { + position: 8, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1300 * 4, + driver: cloneDriver("ricciardo"), + }, + { + position: 9, + status: CarStatus.DidNotStart, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1200 * 4, + driver: cloneDriver("gasly"), + }, + { + position: 10, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1100 * 4, + driver: cloneDriver("alonso"), + }, + { + position: 11, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 1000 * 4, + driver: cloneDriver("ocon"), + }, + { + position: 12, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 900 * 4, + driver: cloneDriver("vettel"), + }, + { + position: 13, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 800 * 4, + driver: cloneDriver("stroll"), + }, + { + position: 14, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 700 * 4, + driver: cloneDriver("tsunoda"), + }, + { + position: 15, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 600 * 4, + driver: cloneDriver("russell"), + }, + { + position: 16, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 500 * 4, + driver: cloneDriver("raikkonen"), + }, + { + position: 17, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 400 * 4, + driver: cloneDriver("latifi"), + }, + { + position: 18, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 300 * 4, + driver: cloneDriver("giovinazzi"), + }, + { + position: 19, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 200 * 4, + driver: cloneDriver("schumacher"), + }, + { + position: 20, + status: CarStatus.Normal, + tyre: DEFAULT_TYRE, + notices: [], + distance: 100 * 4, + driver: cloneDriver("mazepin"), + }, ], + lastUpdate: Date.now(), }; export const eventSlice = createSlice({ @@ -48,11 +197,40 @@ export const eventSlice = createSlice({ reducers: { setCourseFlag: (state, action: PayloadAction) => { state.courseStatus.courseFlag = action.payload; + state.lastUpdate = Date.now(); + }, + refreshRunningOrder: (state) => { + const sortingGrid = state.grid.map((car, index) => ({ + gridSpot: index, + distance: car.distance, + status: car.status, + })); + + const add = (status: CarStatus) => { + if (status === CarStatus.Retired) { + return 1000000; + } else if (status === CarStatus.DidNotStart) { + return 2000000; + } + return 0; + }; + + sortingGrid.sort((a, b) => + // Retired cars go to the end but still maintain their own order. + (b.distance - add(b.status)) - (a.distance - add(a.status)), + ); + + sortingGrid.forEach((entry, sortedPosition) => { + state.grid[entry.gridSpot].position = sortedPosition + 1; + }); + state.leaderGridSpot = sortingGrid[0].gridSpot; + state.lastUpdate = Date.now(); }, }, }); export const { setCourseFlag, + refreshRunningOrder, } = eventSlice.actions; export default eventSlice.reducer; diff --git a/src/public/images/icons/fastest-lap.svg b/src/public/images/icons/fastest-lap.svg new file mode 100644 index 0000000..a47bcce --- /dev/null +++ b/src/public/images/icons/fastest-lap.svg @@ -0,0 +1 @@ + \ No newline at end of file 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..f6f3b75 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/shared/theme.ts b/src/shared/theme.ts index 2757431..cd6625c 100644 --- a/src/shared/theme.ts +++ b/src/shared/theme.ts @@ -23,24 +23,53 @@ export const theme = { faintGrey: "#eee", darkGrey: "#303030", videoFrameBG: "#333", - teams: { + teams: { // 2021 Season alfaRomeo: "#900000", alphaTauri: "#2b4562", alpine: "#0090ff", astonMartin: "#006f62", ferrari: "#dc0000", - haas: "#fff", + haas: "#ffffff", mclaren: "#ff9800", mercedes: "#00d2be", redBull: "#0600ef", williams: "#005aff", }, + logos: { // Colors provided by https://www.f1.daavs.org/credits + f1Red: "#ff1801", + dhlYellow: "#ffcc00", + dhlRed: "#d40511", + rolexGreen: "#006039", + rolexGold: "#a37e2c", + emiratesRed: "#d71a21", + pirelliRed: "#d52b1e", + pirelliYellow: "#fed100", + }, + laps: { // Colors provided by https://www.f1.daavs.org/credits + purple: "#a700ff", + green: "#44d745", + yellow: "#f8d500", + red: "#be2c30", + }, + tyres: { // Colors provided by https://www.f1.daavs.org/credits + soft: "#e93324", + medium: "#f3fd54", + hard: "#ffffff", + wet: "#518ed4", + intermediate: "#6ebe4f", + }, }, fontSizes: { label: "0.9em", selector: "0.9em", }, design: { + timingTower: { + rowHeightPx: 36.5, + rowLeftHalfWidthPx: 147, + rowRightHalfWidthPx: 108, + retiredTopGapPx: 3, + }, button: { borderRadius: "0.25rem", }, diff --git a/src/types/state.d.ts b/src/types/state.ts similarity index 70% rename from src/types/state.d.ts rename to src/types/state.ts index c01dc92..97a1a1b 100644 --- a/src/types/state.d.ts +++ b/src/types/state.ts @@ -1,4 +1,4 @@ -import { Milliseconds, Optional } from "./util"; +import { Meters, Milliseconds, Optional } from "./util"; import { Corner, Fraction } from "./style"; export interface RootState { @@ -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; @@ -70,10 +70,14 @@ export interface OverlayItem { // Event State export interface Event { trackName: string; + trackLength: Meters; courseStatus: CourseStatus; mode: EventMode; progress: EventProgress; + leaderGridSpot: GridSpot; grid: Grid; + // gridPositions: GridSpot[]; + lastUpdate: number; } export interface EventProgress { startTime: Milliseconds; @@ -91,8 +95,8 @@ export type EventMode = | "q2" | "q3"; export interface CourseStatus { - courseFlag: CourseFlags; - sectorFlags: Array; + courseFlag: CourseFlag; + sectorFlags: CourseFlag[]; safetyCar: SafetyCarStatus; virtualSafetyCar: VirtualSafetyCarStatus; } @@ -106,14 +110,16 @@ 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 type GridSpot = number; export interface Car { position: number; driver: Driver; - // status: ???; // retired + status: CarStatus; + tyre: Tyre; // flags: ???, // blue, red, meatball, black/white, black - // notices: ???; // Penalties, warnings, investigations, blue flags, etc - // distance: number; + notices: CarNotice[]; + distance: Meters; } export interface Driver { id: DriverId; @@ -150,6 +156,44 @@ export type DriverId = | "vettel" | "zhou"; +export enum CarStatus { + Normal, + OnGrid, + Finished, + Retired, + InPit, + OutLap, + InLap, + DidNotStart, +} + +export enum CarNotice { + FastestLap, + BlueFlag, + BlackAndWhiteFlag, + BlackFlag, + BlackWithOrangeCircleFlag, + UnderInvestigation, + PenaltyDriveThrough, + Penalty5Seconds, + Penalty10Seconds, + Penalty10SecondsStopGo, +} + +export interface Tyre { + compound: TyreCompound, + age: number, + new: boolean, +} +export enum TyreCompound { + Soft, + Medium, + Hard, + Wet, + Intermediate, +} + + export interface Team { id: TeamId; shortName: TeamShortName; @@ -193,7 +237,7 @@ export type TeamFullName = // Broadcast Director export interface BroadcastDirector { - selectedCars: Array; + selectedCars: Car[]; } // Broadcast Graphics @@ -213,14 +257,52 @@ 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; +} +export enum BGStatusIndicatorModes { + NormalNarrow, // "LAP" above "##/##" lap count. + NormalWide, // "LAP" to the left of "##/##" lap count. +} + +// Timing Tower +export interface BGTimingTower { + open: OpenState; + displayMode: BGTimingTowerDisplayModes; + splitsMode: BGTimingTowerSplitsMode, + focusedCars: Car[], + focusedCarsMode: BGTimingTowerFocusedCarsMode, +} +export enum BGTimingTowerDisplayModes { + Hidden, + LeftOnly, + LeftAndRight, + FullLeft, +} +export enum BGTimingTowerSplitsMode { + Leader, // Leader timing. + Interval, // Interval timing. +} +export enum BGTimingTowerFocusedCarsMode { + None, // When no special treatments are made. + Portrait, // When it shows the portrait of the driver. +} + + // Chyrons export type BGChyronMode = string; export type BGChyronSubMode = string; @@ -234,7 +316,7 @@ export interface BGChyrons extends BGBaseState { // sponsorGem: BGSponsorGem; } -export interface BGChyronDriver extends BGChyron { +export interface BGChyronDriver { car: Car; flagMode: FlagMode; showPosFlag: boolean; diff --git a/src/types/util.d.ts b/src/types/util.d.ts index 09ccfa6..8eb4d7a 100644 --- a/src/types/util.d.ts +++ b/src/types/util.d.ts @@ -9,3 +9,9 @@ export type Milliseconds = number; * Type to remind you that we're dealing with seconds. */ export type Seconds = number; + + +/** + * Type to remind you that we're dealing with meters. + */ +export type Meters = number; 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; +} diff --git a/src/utils/dataLookup.ts b/src/utils/dataLookup.ts index 469ebeb..f39b9b9 100644 --- a/src/utils/dataLookup.ts +++ b/src/utils/dataLookup.ts @@ -1,6 +1,6 @@ import { cloneDeep } from "lodash"; -import { drivers, teams, teamNumberStyles, teamFlagStyles } from "../domain/data/teams"; -import { DriverId, TeamId } from "../types/state"; +import { drivers, teams, teamNumberStyles, teamFlagStyles, teamGemStyles } from "../domain/data/teams"; +import { DriverId, Team, TeamId } from "../types/state"; /** * Prefer getting data from teams.ts through these simple getter functions. @@ -29,3 +29,6 @@ export function getTeamNumberStyle(teamId: TeamId) { export function getTeamFlagStyle(teamId: TeamId) { return teamFlagStyles[teamId]; } +export function getTeamGemStyle(teamId: TeamId) { + return teamGemStyles[teamId]; +} diff --git a/src/utils/event.ts b/src/utils/event.ts new file mode 100644 index 0000000..6208d66 --- /dev/null +++ b/src/utils/event.ts @@ -0,0 +1,29 @@ +import { random } from "lodash"; +import { Car, Grid } from "../types/state"; + +import { Meters } from "../types/util"; + +export function timeDiff( + front: Meters, + back: Meters, +) { + /** + * Spa length in 2020 was 308,052m. Hamilton won it in 1:24:08.761. + * That's 3600 + 1440 + 8.761 = 5,048.761 seconds. + * 61.015 m/s average. So, let's do that. + */ + + return random(0.95, 1.05) * ((front - back) / 61.015); +} + + +export function getCarAtPos( + grid: Grid, + targetPosition: number, +): Car { + const foundCar = grid.find(car => car.position === targetPosition); + if (!foundCar) { + return grid[0]; + } + return foundCar; +} diff --git a/src/utils/styling.spec.ts b/src/utils/styling.spec.ts new file mode 100644 index 0000000..fb19223 --- /dev/null +++ b/src/utils/styling.spec.ts @@ -0,0 +1,53 @@ +import { formatTime } from "./styling"; + +describe("styling", () => { + describe("formatTime", () => { + describe("works correctly with 60 limit", () => { + it("should format 65.32210101 to 1:05.322", () => { + expect(formatTime(65.32210101, 60)).toBe("1:05.322"); + }); + + it("should format 3.2009101 to 3.201", () => { + expect(formatTime(3.2009101, 60)).toBe("3.201"); + }); + + it("should format 50 to 50.000", () => { + expect(formatTime(50, 60)).toBe("50.000"); + }); + + it("should format 60 to 1:00.00", () => { + expect(formatTime(60, 60)).toBe("1:00.000"); + }); + }); + describe("works correctly with 70 limit", () => { + it("should format 65.32210101 to 65.322", () => { + expect(formatTime(65.32210101, 70)).toBe("65.322"); + }); + + it("should format 73.2009101 to 1:13.201", () => { + expect(formatTime(73.2009101, 70)).toBe("1:13.201"); + }); + + it("should format 50 to 50.000", () => { + expect(formatTime(50, 70)).toBe("50.000"); + }); + + it("should format 70 to 1:10.00", () => { + expect(formatTime(70, 70)).toBe("1:10.000"); + }); + }); + describe("works correctly with 50 limit", () => { + it("should format 65.32210101 to 1:05.322", () => { + expect(formatTime(65.32210101, 50)).toBe("1:05.322"); + }); + + it("should format 73.2009101 to 1:13.201", () => { + expect(formatTime(73.2009101, 50)).toBe("1:13.201"); + }); + + it("should format 50 to 0:50.00", () => { + expect(formatTime(50, 50)).toBe("0:50.000"); + }); + }); + }); +}); diff --git a/src/utils/styling.ts b/src/utils/styling.ts index de184de..5cfe318 100644 --- a/src/utils/styling.ts +++ b/src/utils/styling.ts @@ -2,6 +2,7 @@ import { css }from "styled-components"; import { clamp } from "lodash"; import { Corner, Fraction, Placement, Px, TransitionArgs } from "../types/style"; +import { Seconds } from "../types/util"; export function placementStyleRules(pos: Placement) { return css` @@ -127,9 +128,22 @@ export function outlineClipPath( [0, height + outlineThickness], ]; } +} - - // return [ - - // ] +/** + * Converts amount of seconds that are over the limit to become a new format: + * If limit is 60, then 65.322 will become "1:05.322". + * You can set the limit to other than 60 to change the time when the new format + * is used. + * @param time Time to format given in seconds + * @param limit Bounds (exclusive) that will keep the format in seconds. + * @returns + */ +export function formatTime(time: Seconds, limit: Seconds) { + if (time < limit) { + return String(time.toFixed(3)); + } + const minutes = Math.floor(time / 60); + const seconds = time % 60; + return `${minutes}:${seconds.toFixed(3).padStart(6, "0")}`; }