diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriverBasic.tsx b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriverBasic.tsx new file mode 100644 index 0000000..8fb48d6 --- /dev/null +++ b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriverBasic.tsx @@ -0,0 +1,36 @@ +import { DriverNumber } from "../../Common/DriverNumber"; +import { + BaseBackground, + FirstName, + FlagNumber, + LastName, + NameContainer, + NumberContainer, + NumberFlag, + TeamColorBar, + TeamName, + TextContainer, +} from "./styles"; + +export function ChyronDriverBasic() { + // TODO - Get driver details from Redux. + + return ( + + + 1 + + + + + Lewis + Hamilton + + + + + Mercedes + + + ); +} diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/index.ts b/src/components/BroadcastGraphics/Chyrons/Driver/index.ts new file mode 100644 index 0000000..c1bd7e0 --- /dev/null +++ b/src/components/BroadcastGraphics/Chyrons/Driver/index.ts @@ -0,0 +1 @@ +export * from "./ChyronDriverBasic"; diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/styles.ts b/src/components/BroadcastGraphics/Chyrons/Driver/styles.ts new file mode 100644 index 0000000..9b49de1 --- /dev/null +++ b/src/components/BroadcastGraphics/Chyrons/Driver/styles.ts @@ -0,0 +1,96 @@ +import styled from "styled-components"; + +export const BaseBackground = styled.div` + position: relative; + width: 582px; + height: 72px; + + border-bottom-right-radius: 11px; + background-color: #000; +`; +BaseBackground.displayName = "BaseBackground"; + +export const NumberFlag = styled.div` + position: absolute; + width: 61px; + height: 61px; + top: 6px; + left: 6px; + + border-bottom-right-radius: 9px; + background-color: #f4f3ee; + + display: flex; + align-items: center; + justify-content: center; +`; +NumberFlag.displayName = "NumberFlag"; + +export const FlagNumber = styled.span` + font-family: ${p => p.theme.fonts.f1Regular}; + font-size: 39px; + margin-top: 2px; +`; +FlagNumber.displayName = "FlagNumber"; + +type TeamColorBarProps = { + color: string, +}; +export const TeamColorBar = styled.div` + position: absolute; + width: 6px; + height: 45px; + top: 14px; + left: 75px; + + background-color: ${({ color }) => color}; +`; +TeamColorBar.displayName = "TeamColorBar"; + +export const TextContainer = styled.div` + position: absolute; + width: 100%; + height: 100%; + left: 90px; +`; +TextContainer.displayName = "TextContainer"; + +export const NameContainer = styled.div` + position: relative; + top: 5px; +`; +NameContainer.displayName = "NameContainer"; + +export const FirstName = styled.span` + font-family: ${p => p.theme.fonts.f1Regular}; + color: #fff; + font-size: 25px; +`; +FirstName.displayName = "FirstName"; + +export const LastName = styled.span` + font-family: ${p => p.theme.fonts.f1Bold}; + text-transform: uppercase; + color: #fff; + font-size: 25px; + margin-left: 5px; +`; +LastName.displayName = "LastName"; + +export const NumberContainer = styled.div` + position: relative; + display: inline; + + bottom: 3px; + left: 10px; +`; +NumberContainer.displayName = "NumberContainer"; + +export const TeamName = styled.span` + position: absolute; + font-family: ${p => p.theme.fonts.f1Regular}; + color: #d1d1d1; + font-size: 20px; + bottom: 6px; +`; +TeamName.displayName = "TeamName"; diff --git a/src/components/BroadcastGraphics/Common/DriverNumber/DriverNumber.tsx b/src/components/BroadcastGraphics/Common/DriverNumber/DriverNumber.tsx new file mode 100644 index 0000000..d4502ab --- /dev/null +++ b/src/components/BroadcastGraphics/Common/DriverNumber/DriverNumber.tsx @@ -0,0 +1,44 @@ +import { TeamId } from "../../../../types/state"; +import { getTeamNumberStyle } from "../../../../utils/dataLookup"; +import { NumberContainer, ShadowNumber, StrokeNumber } from "./styles"; + +type DriverNumberProps = { + number: number, + fontSize: string, + teamId: TeamId, +}; +export function DriverNumber({ number, fontSize, teamId }: DriverNumberProps) { + const style = getTeamNumberStyle(teamId); + return ( + + {style.rules.map((rule, i) => { + if (rule.type === "stroke") { + return ( + + {number} + + ); + } else if (rule.type === "shadow") { + return ( + + {number} + + ); + } + })} + + ); +} diff --git a/src/components/BroadcastGraphics/Common/DriverNumber/index.ts b/src/components/BroadcastGraphics/Common/DriverNumber/index.ts new file mode 100644 index 0000000..1432e1c --- /dev/null +++ b/src/components/BroadcastGraphics/Common/DriverNumber/index.ts @@ -0,0 +1 @@ +export * from "./DriverNumber"; diff --git a/src/components/BroadcastGraphics/Common/DriverNumber/styles.ts b/src/components/BroadcastGraphics/Common/DriverNumber/styles.ts new file mode 100644 index 0000000..620c90c --- /dev/null +++ b/src/components/BroadcastGraphics/Common/DriverNumber/styles.ts @@ -0,0 +1,40 @@ +import styled from "styled-components"; + +export const NumberContainer = styled.div` + position: relative; + display: inline; +`; +NumberContainer.displayName = "NumberContainer"; + +type NumberProps = { + fontFamily: string, + fontSize: string, + numberColor: string, +} +type StrokeNumberProps = NumberProps & { + strokeColor: string, + strokeWidth: string, +} +export const StrokeNumber = styled.span` + position: absolute; + font-family: ${({ fontFamily }) => fontFamily}; + font-size: ${({ fontSize }) => fontSize}; + color: ${({ numberColor }) => numberColor}; + + -webkit-text-stroke-color: ${({ strokeColor }) => strokeColor}; + -webkit-text-stroke-width: ${({ strokeWidth }) => strokeWidth}; +`; +StrokeNumber.displayName = "StrokeNumber"; + +type ShadowNumberProps = NumberProps & { + shadowProperties: string, +}; +export const ShadowNumber = styled.span` + position: absolute; + font-family: ${({ fontFamily }) => fontFamily}; + font-size: ${({ fontSize }) => fontSize}; + color: ${({ numberColor }) => numberColor}; + + text-shadow: ${({ shadowProperties }) => shadowProperties}; +`; +ShadowNumber.displayName = "ShadowNumber"; diff --git a/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx b/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx index 516ce92..f97e808 100644 --- a/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx +++ b/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx @@ -50,12 +50,9 @@ export function OverlayDisplay({ const xPos = currentOverlayItem?.position.x ?? 0; const yPos = currentOverlayItem?.position.y ?? 0; const transition = useTransition(visible, { - from: { top: 50, opacity: 0 }, - enter: { - top: 0, - opacity: 1, - }, - leave: { top: 50, opacity: 0 }, + from: { opacity: 0 }, + enter: { opacity: 1 }, + leave: { opacity: 0 }, }); // Cannot make an earlier return because all hooks must run or React gets mad. diff --git a/src/components/Workspaces/Workspace/Workspace.tsx b/src/components/Workspaces/Workspace/Workspace.tsx index 2fac558..6f903ef 100644 --- a/src/components/Workspaces/Workspace/Workspace.tsx +++ b/src/components/Workspaces/Workspace/Workspace.tsx @@ -10,11 +10,10 @@ import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSe import { newWorkspace } from "../../../features/overlayTool/overlayToolSlice"; import { PreviewWindow, H2, ControlsContainer } from "./styles"; -import { WorkspaceControls } from "./WorkspaceControls"; -import { MockupBlock } from "../../Common/MockupBlock.styled"; +import { WorkspaceControls } from "./WorkspaceControls/WorkspaceControls"; import { OverlayDisplay } from "../../OverlayTool"; -import { workspaces } from "../workspaces"; +import { fetchBroadcastGraphic, workspaces } from "../../../domain/data/workspaces"; export const Workspace = () => { const dispatch = useDispatch(); @@ -54,11 +53,7 @@ export const Workspace = () => { dimensions={workspaceProperties.previewWindowDimensions} animatedBG={animatedBG} > - Preview Item + {fetchBroadcastGraphic(workspaceId)} diff --git a/src/components/Workspaces/Workspace/WorkspaceControls.tsx b/src/components/Workspaces/Workspace/WorkspaceControls/WorkspaceControls.tsx similarity index 68% rename from src/components/Workspaces/Workspace/WorkspaceControls.tsx rename to src/components/Workspaces/Workspace/WorkspaceControls/WorkspaceControls.tsx index 406d9be..ea90e0a 100644 --- a/src/components/Workspaces/Workspace/WorkspaceControls.tsx +++ b/src/components/Workspaces/Workspace/WorkspaceControls/WorkspaceControls.tsx @@ -2,11 +2,11 @@ import { Grid } from "@bedrock-layout/grid"; import { PadBox } from "@bedrock-layout/padbox"; import { useDispatch, useSelector } from "react-redux"; -import { workspaceSelector } from "../../../features/workspace/workspaceSelector"; -import { setAnimatedBG } from "../../../features/workspace/workspaceSlice"; +import { workspaceSelector } from "../../../../features/workspace/workspaceSelector"; +import { setAnimatedBG } from "../../../../features/workspace/workspaceSlice"; -import { Toggle } from "../../Common/Inputs/Toggle"; -import { OverlayControl } from "../../OverlayTool"; +import { Toggle } from "../../../Common/Inputs/Toggle"; +import { OverlayControl } from "../../../OverlayTool"; export const WorkspaceControls = () => { const dispatch = useDispatch(); diff --git a/src/components/Workspaces/WorkspaceList/WorkspaceList.tsx b/src/components/Workspaces/WorkspaceList/WorkspaceList.tsx index 8f3e63c..017f5ff 100644 --- a/src/components/Workspaces/WorkspaceList/WorkspaceList.tsx +++ b/src/components/Workspaces/WorkspaceList/WorkspaceList.tsx @@ -5,7 +5,7 @@ import { WorkspaceListBox } from "./styles"; import { Stack } from "@bedrock-layout/stack"; import { MenuItem } from "../../Common/MenuItem.styled"; -import { workspaces } from "../workspaces"; +import { workspaces } from "../../../domain/data/workspaces"; type WorkspaceListProps = { headerOffset?: number, diff --git a/src/components/Workspaces/workspaces.ts b/src/components/Workspaces/workspaces.ts deleted file mode 100644 index d4c8fde..0000000 --- a/src/components/Workspaces/workspaces.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { WorkspaceProperties } from "../../types/state"; - -type WorkspaceObject = { - [id: string]: WorkspaceProperties, -}; -export const workspaces: WorkspaceObject = { - chyronSimple: { - name: "Chyron Simple", - overlayIds: [ - "chyron-simple-full.png", - "chyron-simple-opening-1.png", - "chyron-simple-opening-2.png", - ], - previewWindowDimensions: { - width: 650, - height: 200, - }, - }, -}; - diff --git a/src/domain/data/teams.ts b/src/domain/data/teams.ts new file mode 100644 index 0000000..a8f4cdd --- /dev/null +++ b/src/domain/data/teams.ts @@ -0,0 +1,336 @@ +import { theme } from "../../shared/theme"; +import { Driver, Team } from "../../types/state"; +import { repeater } from "../../utils/strings"; + +/** + * Do not grab directly! + * 2021 Driver lineup with 2022 newcomers included (Zhou and Albon). + */ +export const teams: {[id: string]: Team} = { + alfaRomeo: { + id: "alfaRomeo", + shortName: "Alfa Romeo", + fullName: "Alfa Romeo F1 Team ORLEN", + nationality: "CHE", + }, + alphaTauri: { + id: "alphaTauri", + shortName: "AlphaTauri", + fullName: "Scuderia AlphaTauri", + nationality: "ITA", + }, + alpine: { + id: "alpine", + shortName: "Alpine", + fullName: "Alpine F1 Team", + nationality: "FRA", + }, + astonMartin: { + id: "astonMartin", + shortName: "Aston Martin", + fullName: "Aston Martin Cognizant Formula One Team", + nationality: "GBR", + }, + ferrari: { + id: "ferrari", + shortName: "Ferrari", + fullName: "Scuderia Ferrari", + nationality: "ITA", + }, + haas: { + id: "haas", + shortName: "Haas F1 Team", + fullName: "Uralkali Haas F1 Team", + nationality: "USA", + }, + mclaren: { + id: "mclaren", + shortName: "McLaren", + fullName: "McLaren F1 Team", + nationality: "GBR", + }, + mercedes: { + id: "mercedes", + shortName: "Mercedes", + fullName: "Mercedes-AMG Petronas Formula One Team", + nationality: "DEU", + }, + redBull: { + id: "redBull", + shortName: "Red Bull Racing", + fullName: "Red Bull Racing", + nationality: "AUT", + }, + williams: { + id: "williams", + shortName: "Williams", + fullName: "Williams Racing", + nationality: "GBR", + }, +}; + +/** + * Do not grab directly! + * 2021 Driver lineup with 2022 newcomers included (Zhou and Albon) + */ +export const drivers: {[lastName: string]: Driver} = { + albon: { + id: "albon", + firstName: "Alex", + lastName: "Albon", + number: 23, + team: teams.williams, + yellowTCam: false, // TBD + initials: "ALB", + nationality: "THA", + }, + alonso: { + id: "alonso", + firstName: "Fernando", + lastName: "Alonso", + number: 14, + team: teams.alpine, + yellowTCam: false, + initials: "ALO", + nationality: "ESP", + }, + bottas: { + id: "bottas", + firstName: "Valtteri", + lastName: "Bottas", + number: 77, + team: teams.mercedes, + yellowTCam: true, + initials: "BOT", + nationality: "FIN", + }, + gasly: { + id: "gasly", + firstName: "Pierre", + lastName: "Gasly", + number: 10, + team: teams.alphaTauri, + yellowTCam: true, + initials: "GAS", + nationality: "FRA", + }, + giovinazzi: { + id: "giovinazzi", + firstName: "Antonio", + lastName: "Giovinazzi", + number: 99, + team: teams.alfaRomeo, + yellowTCam: true, + initials: "GIO", + nationality: "ITA", + }, + hamilton: { + id: "hamilton", + firstName: "Lewis", + lastName: "Hamilton", + number: 44, + team: teams.mercedes, + yellowTCam: false, + initials: "HAM", + nationality: "GBR", + }, + kubica: { + id: "kubica", + firstName: "Robert", + lastName: "Kubica", + number: 88, + team: teams.alfaRomeo, + yellowTCam: false, + initials: "KUB", + nationality: "POL", + }, + latifi: { + id: "latifi", + firstName: "Nicolas", + lastName: "Latifi", + number: 6, + team: teams.williams, + yellowTCam: true, + initials: "LAT", + nationality: "CAN", + }, + leclerc: { + id: "leclerc", + firstName: "Charles", + lastName: "Leclerc", + number: 16, + team: teams.ferrari, + yellowTCam: false, + initials: "LEC", + nationality: "MCO", + }, + mazepin: { + id: "mazepin", + firstName: "Nikita", + lastName: "Mazepin", + number: 9, + team: teams.haas, + yellowTCam: false, + initials: "MAZ", + nationality: "RUS", // RAF SUPPORT MAYBE LATER... + }, + norris: { + id: "norris", + firstName: "Lando", + lastName: "Norris", + number: 4, + team: teams.mclaren, + yellowTCam: true, + initials: "NOR", + nationality: "GBR", + }, + ocon: { + id: "ocon", + firstName: "Esteban", + lastName: "Ocon", + number: 31, + team: teams.alpine, + yellowTCam: true, + initials: "OCO", + nationality: "FRA", + }, + perez: { + id: "perez", + firstName: "Sergio", + lastName: "Pérez", + number: 11, + team: teams.redBull, + yellowTCam: true, + initials: "PER", + nationality: "MEX", + }, + raikkonen: { + id: "raikkonen", + firstName: "Kimi", + lastName: "Räikkönen", + number: 7, + team: teams.alfaRomeo, + yellowTCam: false, + initials: "RAI", + nationality: "FIN", + }, + ricciardo: { + id: "ricciardo", + firstName: "Daniel", + lastName: "Ricciardo", + number: 3, + team: teams.mclaren, + yellowTCam: false, + initials: "RIC", + nationality: "AUS", + }, + russell: { + id: "russell", + firstName: "George", + lastName: "Russell", + number: 63, + team: teams.williams, + yellowTCam: false, + initials: "RUS", + nationality: "GBR", + }, + sainz: { + id: "sainz", + firstName: "Carlos", + lastName: "Sainz", + number: 55, + team: teams.ferrari, + yellowTCam: true, + initials: "SAI", + nationality: "ESP", + }, + schumacher: { + id: "schumacher", + firstName: "Mick", + lastName: "Schumacher", + number: 47, + team: teams.haas, + yellowTCam: true, + initials: "MSC", + nationality: "DEU", + }, + stroll: { + id: "stroll", + firstName: "Lance", + lastName: "Stroll", + number: 18, + team: teams.astonMartin, + yellowTCam: false, + initials: "STR", + nationality: "CAN", + }, + tsunoda: { + id: "tsunoda", + firstName: "Yuki", + lastName: "Tsunoda", + number: 22, + team: teams.alphaTauri, + yellowTCam: false, + initials: "TSU", + nationality: "JPN", + }, + verstappen: { + id: "verstappen", + firstName: "Max", + lastName: "Verstappen", + number: 33, + team: teams.redBull, + yellowTCam: false, + initials: "VER", + nationality: "NLD", + }, + vettel: { + id: "vettel", + firstName: "Sebastian", + lastName: "Vettel", + number: 5, + team: teams.astonMartin, + yellowTCam: true, + initials: "VET", + nationality: "DEU", + }, + zhou: { + id: "zhou", + firstName: "Guanyu", + lastName: "Zhou", + number: 24, + team: teams.alfaRomeo, + yellowTCam: true, + initials: "ZHO", + nationality: "CHN", + }, +}; + +type NumberStyleRule = { + type: "stroke" + color: string, + width: number, +} | { + type: "shadow", + property: string, +}; +export type NumberStyle = { + numberColor: string, + fontFamily: string, + rules: Array, +}; +/** + * Do not grab directly! + */ +export const teamNumberStyles: { [teamId: string]: NumberStyle } = { + mercedes: { + numberColor: "#daffff", + fontFamily: theme.fonts.f1Italic, + rules: [ + { type: "shadow", property: repeater("0 0 0.15em #daffff", 4) }, + { type: "stroke", color: "#000", width: 0.10 }, + { type: "stroke", color: "#35dfae", width: 0.05 }, + { type: "shadow", property: repeater("0 0 0.07em #35dfae", 2) }, + ], + }, +}; diff --git a/src/domain/data/workspaces.ts b/src/domain/data/workspaces.ts new file mode 100644 index 0000000..4359da7 --- /dev/null +++ b/src/domain/data/workspaces.ts @@ -0,0 +1,31 @@ +import { ReactNode } from "react"; +import { WorkspaceId, WorkspaceProperties } from "../../types/state"; + +// Broadcast Graphics +import { ChyronDriverBasic } from "../../components/BroadcastGraphics/Chyrons/Driver"; + +type WorkspaceObject = { + [id: WorkspaceId]: WorkspaceProperties, +}; +export const workspaces: WorkspaceObject = { + chyronDriverBasic: { + name: "Chyron Driver Basic", + overlayIds: [ + "chyron-driver-basic-full.png", + "chyron-driver-basic-opening-1.png", + "chyron-driver-basic-opening-2.png", + ], + previewWindowDimensions: { + width: 650, + height: 200, + }, + }, +}; + +export function fetchBroadcastGraphic(workspaceId: WorkspaceId): ReactNode { + switch(workspaceId) { + case "chyronDriverBasic": return ChyronDriverBasic(); + default: return null; + } +} + diff --git a/src/public/images/overlays/chyron-simple-full.png b/src/public/images/overlays/chyron-driver-basic-full.png similarity index 100% rename from src/public/images/overlays/chyron-simple-full.png rename to src/public/images/overlays/chyron-driver-basic-full.png diff --git a/src/public/images/overlays/chyron-simple-opening-1.png b/src/public/images/overlays/chyron-driver-basic-opening-1.png similarity index 100% rename from src/public/images/overlays/chyron-simple-opening-1.png rename to src/public/images/overlays/chyron-driver-basic-opening-1.png diff --git a/src/public/images/overlays/chyron-simple-opening-2.png b/src/public/images/overlays/chyron-driver-basic-opening-2.png similarity index 100% rename from src/public/images/overlays/chyron-simple-opening-2.png rename to src/public/images/overlays/chyron-driver-basic-opening-2.png diff --git a/src/shared/theme.ts b/src/shared/theme.ts index 4ee114a..61980ae 100644 --- a/src/shared/theme.ts +++ b/src/shared/theme.ts @@ -20,12 +20,28 @@ export const theme = { faintGrey: "#eee", darkGrey: "#303030", videoFrameBG: "#333", + teams: { + alfaRomeo: "#900000", + alphaTauri: "#2b4562", + alpine: "#0090ff", + astonMartin: "#006f62", + ferrari: "#dc0000", + haas: "#fff", + mclaren: "#ff9800", + mercedes: "#00d2be", + redbull: "#0600ef", + williams: "#005aff", + }, }, design: { button: { borderRadius: "0.25rem", }, }, + graphics: { + medRadius: "11px", + smRadius: "7px", + }, }; export type MainThemeProps = ThemeProps; diff --git a/src/types/state.d.ts b/src/types/state.d.ts index de6fb3f..e30bb47 100644 --- a/src/types/state.d.ts +++ b/src/types/state.d.ts @@ -41,3 +41,89 @@ export type OverlayItem = { position: OverlayPosition, opacity: number, }; + +// Race State. +export type Car = { + position: number, + driver: Driver, + // status: ???, + // distance: number, +}; +export type Grid = Array; +export type Driver = { + id: DriverId, + firstName: string, + lastName: string, + number: number, + team: Team, + yellowTCam: boolean, + initials: string, + nationality: string, // ISO 3166-1 alpha-3 codes +}; +export type DriverId = + | "albon" + | "alonso" + | "bottas" + | "gasly" + | "giovinazzi" + | "hamilton" + | "kubica" + | "latifi" + | "leclerc" + | "mazepin" + | "norris" + | "ocon" + | "perez" + | "raikkonen" + | "ricciardo" + | "russell" + | "sainz" + | "schumacher" + | "stroll" + | "tsunoda" + | "verstappen" + | "vettel" + | "zhou"; + +export type Team = { + id: TeamId, + shortName: TeamShortName, + fullName: TeamFullName, + nationality: string, // ISO 3166-1 alpha-3 codes + // logo: string, +}; +export type TeamId = + | "alfaRomeo" + | "alphaTauri" + | "alpine" + | "astonMartin" + | "ferrari" + | "haas" + | "mclaren" + | "mercedes" + | "redBull" + | "williams"; +export type TeamShortName = + | "Alfa Romeo" + | "AlphaTauri" + | "Alpine" + | "Aston Martin" + | "Ferrari" + | "Haas F1 Team" + | "McLaren" + | "Mercedes" + | "Red Bull Racing" + | "Williams"; +export type TeamFullName = + | "Alfa Romeo F1 Team ORLEN" + | "Scuderia AlphaTauri" + | "Alpine F1 Team" + | "Aston Martin Cognizant Formula One Team" + | "Scuderia Ferrari" + | "Uralkali Haas F1 Team" + | "McLaren F1 Team" + | "Mercedes-AMG Petronas Formula One Team" + | "Red Bull Racing" + | "Williams Racing"; + +// Broadcast Graphics diff --git a/src/utils/dataLookup.ts b/src/utils/dataLookup.ts new file mode 100644 index 0000000..6731b3c --- /dev/null +++ b/src/utils/dataLookup.ts @@ -0,0 +1,21 @@ +import { drivers, teams, teamNumberStyles, NumberStyle } from "../domain/data/teams"; +import { Driver, DriverId, Team, TeamId } from "../types/state"; + +/** + * Prefer getting data from teams.ts through these simple getter functions. + * Why? Because we cannot use type literals (such as TeamId) as keys in an + * object in TypeScript. This allows me to enforce some type checking in a + * situation I wouldn't be able to normally + */ + +export function getDriver(driverId: DriverId): Driver { + return drivers[driverId]; +} + +export function getTeam(teamId: TeamId): Team { + return teams[teamId]; +} + +export function getTeamNumberStyle(teamId: TeamId): NumberStyle { + return teamNumberStyles[teamId]; +} diff --git a/src/utils/strings.spec.ts b/src/utils/strings.spec.ts index d7c4935..85bacc9 100644 --- a/src/utils/strings.spec.ts +++ b/src/utils/strings.spec.ts @@ -1,4 +1,4 @@ -import { findPrefixCount } from "./strings"; +import { findPrefixCount, repeater } from "./strings"; describe("strings", () => { describe("findPrefixCount", () => { @@ -41,7 +41,7 @@ describe("strings", () => { "Hello", ], true)).toBe(1); }); - it("is correctly case-insensitive", () => { + it("is case-insensitive", () => { expect(findPrefixCount([ "Hello", "HELLO", @@ -50,4 +50,51 @@ describe("strings", () => { }); }); }); + + describe("repeater", () => { + describe("repeats correctly", () => { + it("repeats 1 time", () => { + expect(repeater( + "A", + 1, + ",", + )).toBe("A"); + }); + it("repeats 3 times", () => { + expect(repeater( + "A", + 3, + ",", + )).toBe("A,A,A"); + }); + it("correctly handles 0", () => { + expect(repeater( + "A", + 0, + ",", + )).toBe(""); + }); + it("correctly handles -1", () => { + expect(repeater( + "A", + -1, + ",", + )).toBe(""); + }); + it("correctly handles blank delimiter", () => { + expect(repeater( + "A", + 3, + "", + )).toBe("AAA"); + }); + it("correctly handles different delimiter", () => { + expect(repeater( + "A", + 3, + " + ", + )).toBe("A + A + A"); + }); + }); + }); }); diff --git a/src/utils/strings.ts b/src/utils/strings.ts index 19652ba..76b8b6a 100644 --- a/src/utils/strings.ts +++ b/src/utils/strings.ts @@ -23,3 +23,22 @@ export function findPrefixCount(strings: Array, caseSensitive = true): n } return maskLength; } + +/** + * Basic function repeats the given string a set number of times and allows for + * a delimiter. + * @param value the string to repeat + * @param count the number of times to repeat + * @param delimiter the string to place between repeated strings + * @returns + */ +export function repeater(value: string, count: number, delimiter = ", "): string { + let output = ""; + for (let x = 0; x < count; ++x) { + output += value; + if (delimiter.length !== 0 && x < count - 1) { + output += delimiter; + } + } + return output; +}