ISSUE-057 - Refactor: Switched from buildRow() to a dedicated component named TimingTowerRow.
This is both simply a better way of going about it and will allow me to use hooks to track position changes and allow for new non-CSS animations.
This commit is contained in:
1 parent
edeba37c6d
commit
49dd08cc13
4 files changed
+153
-127
No files matched your search
@@ -3,40 +3,16 @@ 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 { theme } from "../../../../shared/theme";
|
import { CarStatus } from "../../../../types/state";
|
||||||
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 { RowsContainer } from "./styles";
|
||||||
import { TeamGem } from "../../Common/TeamGem";
|
import { TimingTowerRow } from "./TimingTowerRow";
|
||||||
|
|
||||||
import {
|
|
||||||
DriverName,
|
|
||||||
FastestLapGem,
|
|
||||||
AnimatedRowContainer,
|
|
||||||
RowLeftHalf,
|
|
||||||
RowLeftHalfGemContainer,
|
|
||||||
RowLeftHalfLayout,
|
|
||||||
RowRightHalf,
|
|
||||||
RowRightHalfLayout,
|
|
||||||
RowsContainer,
|
|
||||||
TimeDiff,
|
|
||||||
} from "./styles";
|
|
||||||
|
|
||||||
|
|
||||||
export function TimingTower() {
|
export function TimingTower() {
|
||||||
|
|
||||||
const { lastUpdate, grid, trackLength } = useSelector(eventSelector);
|
const { lastUpdate, grid, trackLength } = useSelector(eventSelector);
|
||||||
const { timingBoard: { timingTower }, timingBoard: { timingTower: { splitsMode } } } = useSelector(
|
const { timingBoard: { timingTower: { splitsMode, displayMode } } } = useSelector(
|
||||||
broadcastGraphicsSelector,
|
broadcastGraphicsSelector,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -57,102 +33,18 @@ export function TimingTower() {
|
|||||||
});
|
});
|
||||||
setRetiredCarsCount(retiredCount);
|
setRetiredCarsCount(retiredCount);
|
||||||
|
|
||||||
setRows(startingGrid.map(car => buildRow(car, startingGrid.length, retiredCount)));
|
setRows(startingGrid.map(car =>
|
||||||
}, [lastUpdate, splitsMode]);
|
<TimingTowerRow
|
||||||
|
|
||||||
|
|
||||||
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 (
|
|
||||||
<AnimatedRowContainer
|
|
||||||
key={car.driver.id}
|
key={car.driver.id}
|
||||||
retired={car.status === CarStatus.Retired}
|
car={car}
|
||||||
wide={timingTower.displayMode !== BGTimingTowerDisplayModes.LeftOnly}
|
grid={grid}
|
||||||
top={(car.position - 1) * theme.design.timingTower.rowHeightPx}
|
startingCarsCount={startingGrid.length}
|
||||||
>
|
retiredCarsCount={retiredCount}
|
||||||
{car.notices.includes(CarNotice.FastestLap) && (
|
splitsMode={splitsMode}
|
||||||
<FastestLapGem />
|
displayMode={displayMode}
|
||||||
)}
|
trackLength={trackLength}
|
||||||
<RowLeftHalf
|
/>));
|
||||||
roundedCornerBottom={
|
}, [lastUpdate, splitsMode]);
|
||||||
bottomRounded && orMatch(
|
|
||||||
timingTower.displayMode,
|
|
||||||
BGTimingTowerDisplayModes.LeftOnly,
|
|
||||||
BGTimingTowerDisplayModes.FullLeft,
|
|
||||||
) ? 5 : undefined
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<RowLeftHalfLayout>
|
|
||||||
{car.status !== CarStatus.Retired && (
|
|
||||||
<PositionFlag
|
|
||||||
size={32}
|
|
||||||
number={car.position}
|
|
||||||
numberSizeFraction={.6}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<DriverName>
|
|
||||||
{car.driver.initials}
|
|
||||||
</DriverName>
|
|
||||||
</RowLeftHalfLayout>
|
|
||||||
<RowLeftHalfGemContainer>
|
|
||||||
<TeamGem team={car.driver.team.id} height={30} />
|
|
||||||
</RowLeftHalfGemContainer>
|
|
||||||
</RowLeftHalf>
|
|
||||||
<RowRightHalf
|
|
||||||
roundedCornerTop={car.position === 1 ? 5 : undefined}
|
|
||||||
roundedCornerBottom={
|
|
||||||
bottomRounded && orMatch(
|
|
||||||
timingTower.splitsMode,
|
|
||||||
BGTimingTowerSplitsMode.Leader,
|
|
||||||
BGTimingTowerSplitsMode.Interval,
|
|
||||||
) ? 5 : undefined
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<RowRightHalfLayout>
|
|
||||||
<TimeDiff xScale={xScale} yScale={yScale}>
|
|
||||||
{rightHalfContent}
|
|
||||||
</TimeDiff>
|
|
||||||
</RowRightHalfLayout>
|
|
||||||
</RowRightHalf>
|
|
||||||
</AnimatedRowContainer>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RowsContainer
|
<RowsContainer
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
import { theme } from "../../../../shared/theme";
|
||||||
|
import { orMatch } from "../../../../utils/common";
|
||||||
|
import { getCarAtPos, timeDiff } from "../../../../utils/event";
|
||||||
|
import { formatTime } from "../../../../utils/styling";
|
||||||
|
import {
|
||||||
|
BGTimingTowerDisplayMode,
|
||||||
|
BGTimingTowerSplitsMode,
|
||||||
|
Car,
|
||||||
|
CarNotice,
|
||||||
|
CarStatus,
|
||||||
|
Grid,
|
||||||
|
} from "../../../../types/state";
|
||||||
|
import { Fraction } from "../../../../types/style";
|
||||||
|
import { Meters } from "../../../../types/util";
|
||||||
|
|
||||||
|
import { PositionFlag } from "../../Common/PositionFlag";
|
||||||
|
import { TeamGem } from "../../Common/TeamGem";
|
||||||
|
import {
|
||||||
|
AnimatedRowContainer,
|
||||||
|
DriverName,
|
||||||
|
FastestLapGem,
|
||||||
|
RowLeftHalf,
|
||||||
|
RowLeftHalfGemContainer,
|
||||||
|
RowLeftHalfLayout,
|
||||||
|
RowRightHalf,
|
||||||
|
RowRightHalfLayout,
|
||||||
|
TimeDiff,
|
||||||
|
} from "./styles";
|
||||||
|
|
||||||
|
interface TimingTowerRowProps {
|
||||||
|
car: Car;
|
||||||
|
grid: Grid;
|
||||||
|
startingCarsCount: number;
|
||||||
|
retiredCarsCount: number;
|
||||||
|
splitsMode: BGTimingTowerSplitsMode;
|
||||||
|
displayMode: BGTimingTowerDisplayMode;
|
||||||
|
trackLength: Meters;
|
||||||
|
}
|
||||||
|
export function TimingTowerRow({
|
||||||
|
car,
|
||||||
|
grid,
|
||||||
|
startingCarsCount,
|
||||||
|
retiredCarsCount,
|
||||||
|
splitsMode,
|
||||||
|
displayMode,
|
||||||
|
trackLength,
|
||||||
|
}: TimingTowerRowProps) {
|
||||||
|
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 (
|
||||||
|
<AnimatedRowContainer
|
||||||
|
key={car.driver.id}
|
||||||
|
retired={car.status === CarStatus.Retired}
|
||||||
|
wide={displayMode !== BGTimingTowerDisplayMode.LeftOnly}
|
||||||
|
top={(car.position - 1) * theme.design.timingTower.rowHeightPx}
|
||||||
|
>
|
||||||
|
{car.notices.includes(CarNotice.FastestLap) && (
|
||||||
|
<FastestLapGem />
|
||||||
|
)}
|
||||||
|
<RowLeftHalf
|
||||||
|
roundedCornerBottom={
|
||||||
|
bottomRounded && orMatch(
|
||||||
|
displayMode,
|
||||||
|
BGTimingTowerDisplayMode.LeftOnly,
|
||||||
|
BGTimingTowerDisplayMode.FullLeft,
|
||||||
|
) ? 5 : undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<RowLeftHalfLayout>
|
||||||
|
{car.status !== CarStatus.Retired && (
|
||||||
|
<PositionFlag
|
||||||
|
size={32}
|
||||||
|
number={car.position}
|
||||||
|
numberSizeFraction={.6}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<DriverName>
|
||||||
|
{car.driver.initials}
|
||||||
|
</DriverName>
|
||||||
|
</RowLeftHalfLayout>
|
||||||
|
<RowLeftHalfGemContainer>
|
||||||
|
<TeamGem team={car.driver.team.id} height={30} />
|
||||||
|
</RowLeftHalfGemContainer>
|
||||||
|
</RowLeftHalf>
|
||||||
|
<RowRightHalf
|
||||||
|
roundedCornerTop={car.position === 1 ? 5 : undefined}
|
||||||
|
roundedCornerBottom={
|
||||||
|
bottomRounded && orMatch(
|
||||||
|
splitsMode,
|
||||||
|
BGTimingTowerSplitsMode.Leader,
|
||||||
|
BGTimingTowerSplitsMode.Interval,
|
||||||
|
) ? 5 : undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<RowRightHalfLayout>
|
||||||
|
<TimeDiff xScale={xScale} yScale={yScale}>
|
||||||
|
{rightHalfContent}
|
||||||
|
</TimeDiff>
|
||||||
|
</RowRightHalfLayout>
|
||||||
|
</RowRightHalf>
|
||||||
|
</AnimatedRowContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|||||||
import {
|
import {
|
||||||
BGChyrons,
|
BGChyrons,
|
||||||
BGStatusIndicatorModes,
|
BGStatusIndicatorModes,
|
||||||
BGTimingTowerDisplayModes,
|
BGTimingTowerDisplayMode,
|
||||||
BGTimingTowerFocusedCarsMode,
|
BGTimingTowerFocusedCarsMode,
|
||||||
BGTimingTowerSplitsMode,
|
BGTimingTowerSplitsMode,
|
||||||
OpenState,
|
OpenState,
|
||||||
@@ -20,7 +20,7 @@ const initialState: RootState["broadcastGraphics"] = {
|
|||||||
},
|
},
|
||||||
timingTower: {
|
timingTower: {
|
||||||
open: 1,
|
open: 1,
|
||||||
displayMode: BGTimingTowerDisplayModes.LeftAndRight,
|
displayMode: BGTimingTowerDisplayMode.LeftAndRight,
|
||||||
splitsMode: BGTimingTowerSplitsMode.Leader,
|
splitsMode: BGTimingTowerSplitsMode.Leader,
|
||||||
focusedCars: [],
|
focusedCars: [],
|
||||||
focusedCarsMode: BGTimingTowerFocusedCarsMode.None,
|
focusedCarsMode: BGTimingTowerFocusedCarsMode.None,
|
||||||
|
|||||||
+2
-2
@@ -294,12 +294,12 @@ export enum BGStatusIndicatorModes {
|
|||||||
// Timing Tower
|
// Timing Tower
|
||||||
export interface BGTimingTower {
|
export interface BGTimingTower {
|
||||||
open: OpenState;
|
open: OpenState;
|
||||||
displayMode: BGTimingTowerDisplayModes;
|
displayMode: BGTimingTowerDisplayMode;
|
||||||
splitsMode: BGTimingTowerSplitsMode,
|
splitsMode: BGTimingTowerSplitsMode,
|
||||||
focusedCars: Car[],
|
focusedCars: Car[],
|
||||||
focusedCarsMode: BGTimingTowerFocusedCarsMode,
|
focusedCarsMode: BGTimingTowerFocusedCarsMode,
|
||||||
}
|
}
|
||||||
export enum BGTimingTowerDisplayModes {
|
export enum BGTimingTowerDisplayMode {
|
||||||
Hidden,
|
Hidden,
|
||||||
LeftOnly,
|
LeftOnly,
|
||||||
LeftAndRight,
|
LeftAndRight,
|
||||||
|
|||||||
Reference in new issue
Block a user