ISSUE-057 - Progress on building prototyping tools.

New reducers for event slice that allow increasing of car distances, awarding fastest laps, and changing the statuses of cars.
Updating more types to enums, which are just better in most cases as far as I can tell.
This commit is contained in:
Kyle Geib committed 2022-02-22 19:12:29 -05:00
1 parent 0d41fbc59a
commit edeba37c6d
13 files changed
+288 -64

No files matched your search

@@ -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 (
<TimingBoardLayout>
<MockupBlock
height="73px"
width={`${theme.design.timingTower.rowLeftHalfWidthPx}px`}
color="black"
/>
<TimingTower />
</TimingBoardLayout>
);
}
@@ -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,
);
@@ -56,6 +56,7 @@ const Rounded = styled.div<RoundedProp>`
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)`
@@ -0,0 +1 @@
export * from "./TimingBoard";
@@ -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;
`;
@@ -1,19 +1,27 @@
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 (
<InlineCluster gutter="md">
<Split gutter="md">
<InlineCluster as={PadBox} padding="md" gutter="md">
<ClickSpan onClick={() => dispatch(refreshRunningOrder())}>
Refresh Running Order
</ClickSpan>
@@ -28,6 +36,58 @@ export function TimingTowerPrototypeControls() {
>
Splits Mode = {BGTimingTowerSplitsMode[splitsMode]}
</ClickSpan>
<ClickSpan
onClick={() => {
dispatch(increaseDistance({
cars: selectedCars,
distance: 200,
randomness: 0,
usePerformance: false,
}));
dispatch(refreshRunningOrder());
}}
>
+200m to cars
</ClickSpan>
<ClickSpan
onClick={() => {
dispatch(increaseDistance({
cars: grid,
distance: 100,
randomness: 0.05,
usePerformance: true,
}));
dispatch(refreshRunningOrder());
}}
>
+100m performance to all
</ClickSpan>
<ClickSpan
onClick={() => {
dispatch(setCarStatus({
cars: selectedCars,
status: CarStatus.Retired,
}));
dispatch(refreshRunningOrder());
}}
>
Retire cars
</ClickSpan>
<ClickSpan
onClick={() => {
dispatch(setCarStatus({
cars: selectedCars,
status: CarStatus.Normal,
}));
dispatch(refreshRunningOrder());
}}
>
Un-retire cars
</ClickSpan>
</InlineCluster>
<PadBox padding="md">
<GridSelection />
</PadBox>
</Split>
);
}
@@ -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() {
<Route path="timingBoard" element={
<Workspace
workspaceId="timingBoard"
previewContent={<TimingTower />}
previewContent={<TimingBoard />}
prototypeControls={<TimingTowerPrototypeControls />}
bleedover={500}
/>
+33
View File
@@ -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,
},
};
@@ -16,7 +16,7 @@ const initialState: RootState["broadcastGraphics"] = {
relativePos: {},
openState: 0,
statusIndicator: {
mode: BGStatusIndicatorModes.NormalNarrow,
mode: BGStatusIndicatorModes.LapNarrow,
},
timingTower: {
open: 1,
+104 -28
View File
@@ -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<IncreaseDistanceAction>) => {
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<Car>) => {
// 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<SetCarStatusAction>) => {
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;
+37 -25
View File
@@ -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
+1 -1
View File
@@ -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.
+16 -2
View File
@@ -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;
}