ISSUE-054 - Added +# LAP indicators to Leader mode.

Added state for tracking the leader of the race since its something that is needed quite often.
This commit is contained in:
Kyle Geib committed 2022-02-18 15:12:16 -05:00
1 parent 35ac571d90
commit 00d2c671cb
5 files changed
+54 -34

No files matched your search

@@ -1,12 +1,13 @@
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
import { eventSelector } from "../../../../features/event/eventSelector"; import { eventSelector } from "../../../../features/event/eventSelector";
import { BGTimingTowerModes, Car, CarNotice, CarStatus } from "../../../../types/state"; import { BGTimingTowerModes, Car, CarNotice, CarStatus } from "../../../../types/state";
import { Fraction } from "../../../../types/style"; import { Fraction } from "../../../../types/style";
import { orMatch } from "../../../../utils/common"; import { orMatch } from "../../../../utils/common";
import { timeDiff } from "../../../../utils/event"; import { timeDiff } from "../../../../utils/event";
import { formatTime } from "../../../../utils/styling"; import { formatTime } from "../../../../utils/styling";
import { PositionFlag } from "../../Common/PositionFlag"; import { PositionFlag } from "../../Common/PositionFlag";
import { TeamGem } from "../../Common/TeamGem"; import { TeamGem } from "../../Common/TeamGem";
@@ -30,7 +31,7 @@ export function TimingTower({
carsToDisplay = 20, carsToDisplay = 20,
}: TimingTowerProps) { }: TimingTowerProps) {
const { grid } = useSelector(eventSelector); const { grid, trackLength, leaderGridSpot } = useSelector(eventSelector);
const { timingBoard } = useSelector(broadcastGraphicsSelector); const { timingBoard } = useSelector(broadcastGraphicsSelector);
const runningCars: Car[] = []; const runningCars: Car[] = [];
@@ -58,24 +59,25 @@ export function TimingTower({
let xScale: Fraction = 1.0; let xScale: Fraction = 1.0;
let yScale: Fraction = 1.0; let yScale: Fraction = 1.0;
let leader = false; let isLeader = false;
if (forwardCarDistance === -1) { if (forwardCarDistance === -1) {
leader = true; isLeader = true;
forwardCarDistance = car.distance; forwardCarDistance = car.distance;
} }
if (leader) { if (isLeader) {
rightHalfContent = timingBoard.timingTower.mode === BGTimingTowerModes.Leader rightHalfContent = timingBoard.timingTower.mode === BGTimingTowerModes.Leader
? "Leader" : timingBoard.timingTower.mode === BGTimingTowerModes.Interval ? "Leader" : timingBoard.timingTower.mode === BGTimingTowerModes.Interval
? "Interval" : ""; ? "Interval" : "";
} else if (car.status === CarStatus.Retired) { } else if (car.status === CarStatus.Retired) {
rightHalfContent = "OUT"; rightHalfContent = "OUT";
} else { } else {
rightHalfContent = `+${formatTime(timeDiff( const plusLaps = Math.floor((grid[leaderGridSpot].distance - car.distance) / trackLength);
forwardCarDistance, rightHalfContent =
car.distance, timingBoard.timingTower.mode === BGTimingTowerModes.Leader && plusLaps > 0
), 60)}`; ? `+${plusLaps} LAP${plusLaps > 1 ? "S" : ""}`
xScale = rightHalfContent.includes(".") && rightHalfContent.length > 7 ? 0.75 : 0.9; : `+${formatTime(timeDiff(forwardCarDistance, car.distance), 60)}`;
yScale = rightHalfContent.includes(".") ? 1.1 : 1.0; xScale = rightHalfContent.includes(":") ? 0.75 : 0.9;
yScale = rightHalfContent.includes("+") ? 1.1 : 1.0;
} }
if (timingBoard.timingTower.mode === BGTimingTowerModes.Interval) { if (timingBoard.timingTower.mode === BGTimingTowerModes.Interval) {
@@ -142,3 +142,4 @@ export const FastestLapGem = styled.div`
background-size: 89%; background-size: 89%;
background-position: center 40%; background-position: center 40%;
`; `;
FastestLapGem.displayName = "FastestLapGem";
+37 -23
View File
@@ -10,7 +10,8 @@ const DEFAULT_TYRE: Tyre = {
}; };
const initialState: RootState["event"] = { const initialState: RootState["event"] = {
trackName: "Melbourne", trackName: "Circuit de Spa-Franchorchamps",
trackLength: 7004,
courseStatus: { courseStatus: {
courseFlag: "green", courseFlag: "green",
sectorFlags: ["green", "green", "green"], sectorFlags: ["green", "green", "green"],
@@ -24,21 +25,22 @@ const initialState: RootState["event"] = {
currentLap: 1, currentLap: 1,
lapCount: 10, lapCount: 10,
}, },
leaderGridSpot: 0,
grid: [ grid: [
{ {
position: 1, position: 1,
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [CarNotice.FastestLap],
distance: 2000 * 2, distance: 2000 * 4,
driver: cloneDriver("verstappen"), driver: cloneDriver("verstappen"),
}, },
{ {
position: 2, position: 2,
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [CarNotice.FastestLap], notices: [],
distance: 1900 * 2, distance: 1900 * 4,
driver: cloneDriver("hamilton"), driver: cloneDriver("hamilton"),
}, },
{ {
@@ -46,7 +48,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1800 * 2, distance: 1800 * 4,
driver: cloneDriver("bottas"), driver: cloneDriver("bottas"),
}, },
{ {
@@ -54,7 +56,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Retired, status: CarStatus.Retired,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1700 * 2, distance: 1700 * 4,
driver: cloneDriver("perez"), driver: cloneDriver("perez"),
}, },
{ {
@@ -62,7 +64,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1600 * 2, distance: 1600 * 4,
driver: cloneDriver("sainz"), driver: cloneDriver("sainz"),
}, },
{ {
@@ -70,7 +72,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Retired, status: CarStatus.Retired,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1500 * 2, distance: 1500 * 4,
driver: cloneDriver("norris"), driver: cloneDriver("norris"),
}, },
{ {
@@ -78,7 +80,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1400 * 2, distance: 1400 * 4,
driver: cloneDriver("leclerc"), driver: cloneDriver("leclerc"),
}, },
{ {
@@ -86,7 +88,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1300 * 2, distance: 1300 * 4,
driver: cloneDriver("ricciardo"), driver: cloneDriver("ricciardo"),
}, },
{ {
@@ -94,7 +96,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1200 * 2, distance: 1200 * 4,
driver: cloneDriver("gasly"), driver: cloneDriver("gasly"),
}, },
{ {
@@ -102,7 +104,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1100 * 2, distance: 1100 * 4,
driver: cloneDriver("alonso"), driver: cloneDriver("alonso"),
}, },
{ {
@@ -110,7 +112,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1000 * 2, distance: 1000 * 4,
driver: cloneDriver("ocon"), driver: cloneDriver("ocon"),
}, },
{ {
@@ -118,7 +120,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 900 * 2, distance: 900 * 4,
driver: cloneDriver("vettel"), driver: cloneDriver("vettel"),
}, },
{ {
@@ -126,7 +128,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 800 * 2, distance: 800 * 4,
driver: cloneDriver("stroll"), driver: cloneDriver("stroll"),
}, },
{ {
@@ -134,7 +136,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 700 * 2, distance: 700 * 4,
driver: cloneDriver("tsunoda"), driver: cloneDriver("tsunoda"),
}, },
{ {
@@ -142,7 +144,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 600 * 2, distance: 600 * 4,
driver: cloneDriver("russell"), driver: cloneDriver("russell"),
}, },
{ {
@@ -150,7 +152,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 500 * 2, distance: 500 * 4,
driver: cloneDriver("raikkonen"), driver: cloneDriver("raikkonen"),
}, },
{ {
@@ -158,7 +160,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 400 * 2, distance: 400 * 4,
driver: cloneDriver("latifi"), driver: cloneDriver("latifi"),
}, },
{ {
@@ -166,7 +168,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 300 * 2, distance: 300 * 4,
driver: cloneDriver("giovinazzi"), driver: cloneDriver("giovinazzi"),
}, },
{ {
@@ -174,7 +176,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 200 * 2, distance: 200 * 4,
driver: cloneDriver("schumacher"), driver: cloneDriver("schumacher"),
}, },
{ {
@@ -182,7 +184,7 @@ const initialState: RootState["event"] = {
status: CarStatus.Normal, status: CarStatus.Normal,
tyre: DEFAULT_TYRE, tyre: DEFAULT_TYRE,
notices: [], notices: [],
distance: 1, distance: 100 * 4,
driver: cloneDriver("mazepin"), driver: cloneDriver("mazepin"),
}, },
], ],
@@ -195,10 +197,22 @@ export const eventSlice = createSlice({
setCourseFlag: (state, action: PayloadAction<CourseFlag>) => { setCourseFlag: (state, action: PayloadAction<CourseFlag>) => {
state.courseStatus.courseFlag = action.payload; state.courseStatus.courseFlag = action.payload;
}, },
calculateLeader: (state) => {
let leader = 0;
let greatestDistance = Number.MIN_SAFE_INTEGER;
for (let p = 0; p < state.grid.length; ++p) {
if (state.grid[p].distance > greatestDistance) {
leader = p;
greatestDistance = state.grid[p].distance;
}
}
state.leaderGridSpot = leader;
},
}, },
}); });
export const { export const {
setCourseFlag, setCourseFlag,
calculateLeader,
} = eventSlice.actions; } = eventSlice.actions;
export default eventSlice.reducer; export default eventSlice.reducer;
Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

After

Width:  |  Height:  |  Size: 276 KiB

+3
View File
@@ -70,9 +70,11 @@ export interface OverlayItem {
// Event State // Event State
export interface Event { export interface Event {
trackName: string; trackName: string;
trackLength: Meters;
courseStatus: CourseStatus; courseStatus: CourseStatus;
mode: EventMode; mode: EventMode;
progress: EventProgress; progress: EventProgress;
leaderGridSpot: GridSpot;
grid: Grid; grid: Grid;
} }
export interface EventProgress { export interface EventProgress {
@@ -107,6 +109,7 @@ export type CourseFlag =
export type SafetyCarStatus = "clear" | "starting" | "out" | "ending"; export type SafetyCarStatus = "clear" | "starting" | "out" | "ending";
export type VirtualSafetyCarStatus = "clear" | "out" | "ending"; export type VirtualSafetyCarStatus = "clear" | "out" | "ending";
export type Grid = Car[]; // Grid order does not change. export type Grid = Car[]; // Grid order does not change.
export type GridSpot = number;
export interface Car { export interface Car {
position: number; position: number;
driver: Driver; driver: Driver;