ISSUE-057 - Added color and wipe effect to position flag on timing tower.
Also adjusted timing for transitions to match what is shown on broadcast TV.
This commit is contained in:
1 parent
759e788af4
commit
e88bd614d3
9 files changed
+123
-13
No files matched your search
@@ -18,6 +18,7 @@
|
|||||||
"@react-hook/resize-observer": "^1.2.5",
|
"@react-hook/resize-observer": "^1.2.5",
|
||||||
"@react-spring/web": "^9.4.1",
|
"@react-spring/web": "^9.4.1",
|
||||||
"@reduxjs/toolkit": "^1.7.1",
|
"@reduxjs/toolkit": "^1.7.1",
|
||||||
|
"@rooks/use-timeout-when": "^4.11.2",
|
||||||
"@testing-library/jest-dom": "^5.14.1",
|
"@testing-library/jest-dom": "^5.14.1",
|
||||||
"@testing-library/react": "^12.0.0",
|
"@testing-library/react": "^12.0.0",
|
||||||
"@testing-library/user-event": "^13.2.1",
|
"@testing-library/user-event": "^13.2.1",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { theme } from "../../../../shared/theme";
|
||||||
import { Fraction, Px } from "../../../../types/style";
|
import { Fraction, Px } from "../../../../types/style";
|
||||||
|
|
||||||
import { PositionFlagBox, PositionNumber } from "./styles";
|
import { PositionFlagBox, PositionNumber } from "./styles";
|
||||||
@@ -6,10 +7,16 @@ type PositionFlagProps = {
|
|||||||
size: Px,
|
size: Px,
|
||||||
number: number,
|
number: number,
|
||||||
numberSizeFraction?: Fraction,
|
numberSizeFraction?: Fraction,
|
||||||
|
color?: string;
|
||||||
};
|
};
|
||||||
export function PositionFlag({ size, number, numberSizeFraction = 0.64 }: PositionFlagProps) {
|
export function PositionFlag({
|
||||||
|
size,
|
||||||
|
number,
|
||||||
|
numberSizeFraction = 0.64,
|
||||||
|
color = theme.colors.positionFlagBG,
|
||||||
|
}: PositionFlagProps) {
|
||||||
return (
|
return (
|
||||||
<PositionFlagBox size={size}>
|
<PositionFlagBox size={size} color={color}>
|
||||||
<PositionNumber size={size * numberSizeFraction}>
|
<PositionNumber size={size * numberSizeFraction}>
|
||||||
{number}
|
{number}
|
||||||
</PositionNumber>
|
</PositionNumber>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Px } from "../../../../types/style";
|
|||||||
|
|
||||||
type PositionFlagBoxProps = {
|
type PositionFlagBoxProps = {
|
||||||
size: Px,
|
size: Px,
|
||||||
|
color: string,
|
||||||
};
|
};
|
||||||
export const PositionFlagBox = styled.div<PositionFlagBoxProps>`
|
export const PositionFlagBox = styled.div<PositionFlagBoxProps>`
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -10,7 +11,7 @@ export const PositionFlagBox = styled.div<PositionFlagBoxProps>`
|
|||||||
width: ${({ size }) => `${size}px`};
|
width: ${({ size }) => `${size}px`};
|
||||||
|
|
||||||
border-bottom-right-radius: 15%;
|
border-bottom-right-radius: 15%;
|
||||||
background-color: #f4f3ee;
|
background-color: ${({ color }) => color};
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ import { CarStatus } from "../../../../types/state";
|
|||||||
import { RowsContainer } from "./styles";
|
import { RowsContainer } from "./styles";
|
||||||
import { TimingTowerRow } from "./TimingTowerRow";
|
import { TimingTowerRow } from "./TimingTowerRow";
|
||||||
|
|
||||||
|
|
||||||
export function TimingTower() {
|
export function TimingTower() {
|
||||||
|
|
||||||
const { lastUpdate, grid, trackLength } = useSelector(eventSelector);
|
const { lastUpdate, grid, trackLength } = useSelector(eventSelector);
|
||||||
const { timingBoard: { timingTower: { splitsMode, displayMode } } } = useSelector(
|
const { timingBoard: { timingTower: { splitsMode, displayMode } } } = useSelector(
|
||||||
broadcastGraphicsSelector,
|
broadcastGraphicsSelector,
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import useTimeoutWhen from "@rooks/use-timeout-when";
|
||||||
|
|
||||||
import { theme } from "../../../../shared/theme";
|
import { theme } from "../../../../shared/theme";
|
||||||
import { orMatch } from "../../../../utils/common";
|
import { orMatch } from "../../../../utils/common";
|
||||||
import { getCarAtPos, timeDiff } from "../../../../utils/event";
|
import { getCarAtPos, timeDiff } from "../../../../utils/event";
|
||||||
import { formatTime } from "../../../../utils/styling";
|
import { formatTime } from "../../../../utils/styling";
|
||||||
|
|
||||||
|
import { Fraction } from "../../../../types/style";
|
||||||
|
import { Meters, Milliseconds } from "../../../../types/util";
|
||||||
import {
|
import {
|
||||||
BGTimingTowerDisplayMode,
|
BGTimingTowerDisplayMode,
|
||||||
BGTimingTowerSplitsMode,
|
BGTimingTowerSplitsMode,
|
||||||
@@ -10,23 +16,27 @@ import {
|
|||||||
CarStatus,
|
CarStatus,
|
||||||
Grid,
|
Grid,
|
||||||
} from "../../../../types/state";
|
} from "../../../../types/state";
|
||||||
import { Fraction } from "../../../../types/style";
|
|
||||||
import { Meters } from "../../../../types/util";
|
|
||||||
|
|
||||||
import { PositionFlag } from "../../Common/PositionFlag";
|
import { PositionFlag } from "../../Common/PositionFlag";
|
||||||
import { TeamGem } from "../../Common/TeamGem";
|
import { TeamGem } from "../../Common/TeamGem";
|
||||||
|
import { WipeTransition } from "../../Common/WipeTransition";
|
||||||
import {
|
import {
|
||||||
AnimatedRowContainer,
|
AnimatedRowContainer,
|
||||||
DriverName,
|
DriverName,
|
||||||
FastestLapGem,
|
FastestLapGem,
|
||||||
RowLeftHalf,
|
RowLeftHalf,
|
||||||
|
RowLeftHalfPosFlagContainer,
|
||||||
RowLeftHalfGemContainer,
|
RowLeftHalfGemContainer,
|
||||||
RowLeftHalfLayout,
|
RowLeftHalfLayout,
|
||||||
RowRightHalf,
|
RowRightHalf,
|
||||||
RowRightHalfLayout,
|
RowRightHalfLayout,
|
||||||
TimeDiff,
|
TimeDiff,
|
||||||
|
RowLeftHalfPosFlagChangeContainer,
|
||||||
} from "./styles";
|
} from "./styles";
|
||||||
|
|
||||||
|
const WIPE_DELAY: Milliseconds = 3500;
|
||||||
|
const WIPE_DURATION: Milliseconds = 400;
|
||||||
|
|
||||||
interface TimingTowerRowProps {
|
interface TimingTowerRowProps {
|
||||||
car: Car;
|
car: Car;
|
||||||
grid: Grid;
|
grid: Grid;
|
||||||
@@ -45,6 +55,25 @@ export function TimingTowerRow({
|
|||||||
displayMode,
|
displayMode,
|
||||||
trackLength,
|
trackLength,
|
||||||
}: TimingTowerRowProps) {
|
}: TimingTowerRowProps) {
|
||||||
|
const [pastPos, setPastPos] = useState(car.position);
|
||||||
|
const [posChange, setPosChange] = useState(0);
|
||||||
|
|
||||||
|
// Using timeouts and boolean states I can manipulate visiblity of the position
|
||||||
|
// change effects. wipeVisible is true for only 1ms before being switched back off.
|
||||||
|
const [showChange, setShowChange] = useState(false);
|
||||||
|
const [wipeVisible, setWipeVisible] = useState(false);
|
||||||
|
useTimeoutWhen(() => setShowChange(false), WIPE_DELAY + WIPE_DURATION, showChange);
|
||||||
|
useTimeoutWhen(() => setWipeVisible(false), 1, wipeVisible);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (car.position !== pastPos) {
|
||||||
|
setPastPos(car.position);
|
||||||
|
setPosChange(pastPos - car.position);
|
||||||
|
setShowChange(true);
|
||||||
|
setWipeVisible(true);
|
||||||
|
}
|
||||||
|
}, [car.position]);
|
||||||
|
|
||||||
const bottomRounded = car.status === CarStatus.Retired ? (
|
const bottomRounded = car.status === CarStatus.Retired ? (
|
||||||
car.position === startingCarsCount
|
car.position === startingCarsCount
|
||||||
) : (
|
) : (
|
||||||
@@ -84,6 +113,7 @@ export function TimingTowerRow({
|
|||||||
retired={car.status === CarStatus.Retired}
|
retired={car.status === CarStatus.Retired}
|
||||||
wide={displayMode !== BGTimingTowerDisplayMode.LeftOnly}
|
wide={displayMode !== BGTimingTowerDisplayMode.LeftOnly}
|
||||||
top={(car.position - 1) * theme.design.timingTower.rowHeightPx}
|
top={(car.position - 1) * theme.design.timingTower.rowHeightPx}
|
||||||
|
transitionTime={750}
|
||||||
>
|
>
|
||||||
{car.notices.includes(CarNotice.FastestLap) && (
|
{car.notices.includes(CarNotice.FastestLap) && (
|
||||||
<FastestLapGem />
|
<FastestLapGem />
|
||||||
@@ -99,11 +129,39 @@ export function TimingTowerRow({
|
|||||||
>
|
>
|
||||||
<RowLeftHalfLayout>
|
<RowLeftHalfLayout>
|
||||||
{car.status !== CarStatus.Retired && (
|
{car.status !== CarStatus.Retired && (
|
||||||
<PositionFlag
|
<RowLeftHalfPosFlagContainer size={32}>
|
||||||
size={32}
|
<PositionFlag
|
||||||
number={car.position}
|
size={32}
|
||||||
numberSizeFraction={.6}
|
number={car.position}
|
||||||
/>
|
numberSizeFraction={.6}
|
||||||
|
/>
|
||||||
|
<RowLeftHalfPosFlagChangeContainer
|
||||||
|
size={32}
|
||||||
|
visible={showChange}
|
||||||
|
transitionTime={167}
|
||||||
|
>
|
||||||
|
{showChange && (
|
||||||
|
<WipeTransition
|
||||||
|
visible={wipeVisible}
|
||||||
|
delay={WIPE_DELAY}
|
||||||
|
angle={45}
|
||||||
|
duration={WIPE_DURATION}
|
||||||
|
startingCorner="topLeft"
|
||||||
|
>
|
||||||
|
<PositionFlag
|
||||||
|
size={32}
|
||||||
|
number={car.position}
|
||||||
|
numberSizeFraction={.6}
|
||||||
|
color={posChange > 0
|
||||||
|
? theme.colors.posGainedGreen
|
||||||
|
: theme.colors.posLostRed}
|
||||||
|
/>
|
||||||
|
</WipeTransition>
|
||||||
|
|
||||||
|
)}
|
||||||
|
</RowLeftHalfPosFlagChangeContainer>
|
||||||
|
|
||||||
|
</RowLeftHalfPosFlagContainer>
|
||||||
)}
|
)}
|
||||||
<DriverName>
|
<DriverName>
|
||||||
{car.driver.initials}
|
{car.driver.initials}
|
||||||
@@ -132,3 +190,4 @@ export function TimingTowerRow({
|
|||||||
</AnimatedRowContainer>
|
</AnimatedRowContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2,6 +2,7 @@ import styled, { css } from "styled-components";
|
|||||||
import { animated } from "@react-spring/web";
|
import { animated } from "@react-spring/web";
|
||||||
|
|
||||||
import { Fraction, Px } from "../../../../types/style";
|
import { Fraction, Px } from "../../../../types/style";
|
||||||
|
import { Milliseconds } from "../../../../types/util";
|
||||||
|
|
||||||
import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg";
|
import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg";
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ type AnimatedRowContainerProps = {
|
|||||||
retired?: boolean,
|
retired?: boolean,
|
||||||
wide?: boolean,
|
wide?: boolean,
|
||||||
top: Px,
|
top: Px,
|
||||||
|
transitionTime: Milliseconds,
|
||||||
};
|
};
|
||||||
// All the elements in a row should go in here.
|
// All the elements in a row should go in here.
|
||||||
export const AnimatedRowContainer = animated(styled.div.attrs<AnimatedRowContainerProps>(({
|
export const AnimatedRowContainer = animated(styled.div.attrs<AnimatedRowContainerProps>(({
|
||||||
@@ -38,7 +40,7 @@ export const AnimatedRowContainer = animated(styled.div.attrs<AnimatedRowContain
|
|||||||
}))<AnimatedRowContainerProps>`
|
}))<AnimatedRowContainerProps>`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
transition: top 500ms;
|
transition: top ${({ transitionTime }) => transitionTime}ms;
|
||||||
|
|
||||||
width: ${({ wide }) => wide ? 255 : 147}px;
|
width: ${({ wide }) => wide ? 255 : 147}px;
|
||||||
height: ${p => p.theme.design.timingTower.rowHeightPx}px; // Future will be animated.
|
height: ${p => p.theme.design.timingTower.rowHeightPx}px; // Future will be animated.
|
||||||
@@ -84,6 +86,33 @@ export const RowLeftHalfLayout = styled.div`
|
|||||||
`;
|
`;
|
||||||
RowLeftHalfLayout.displayName = "RowLeftHalfLayout";
|
RowLeftHalfLayout.displayName = "RowLeftHalfLayout";
|
||||||
|
|
||||||
|
type RowLeftHalfPosFlagContainerProps = {
|
||||||
|
size: Px,
|
||||||
|
};
|
||||||
|
export const RowLeftHalfPosFlagContainer = styled.div<RowLeftHalfPosFlagContainerProps>`
|
||||||
|
position: relative;
|
||||||
|
height: ${({ size }) => size}px;
|
||||||
|
width: ${({ size }) => size}px;
|
||||||
|
`;
|
||||||
|
RowLeftHalfPosFlagContainer.displayName = "RowLeftHalfPosFlagContainer";
|
||||||
|
|
||||||
|
type RowLeftHalfPosFlagChangeContainerProps = {
|
||||||
|
size: Px,
|
||||||
|
visible: boolean,
|
||||||
|
transitionTime: Milliseconds,
|
||||||
|
};
|
||||||
|
export const RowLeftHalfPosFlagChangeContainer = styled.div<RowLeftHalfPosFlagChangeContainerProps>`
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: ${({ size }) => size}px;
|
||||||
|
width: ${({ size }) => size}px;
|
||||||
|
|
||||||
|
opacity: ${({ visible }) => visible ? 1 : 0};
|
||||||
|
transition: opacity ${({ transitionTime }) => transitionTime}ms;
|
||||||
|
`;
|
||||||
|
RowLeftHalfPosFlagChangeContainer.displayName = "RowLeftHalfPosFlagChangeContainer";
|
||||||
|
|
||||||
export const RowLeftHalfGemContainer = styled.div`
|
export const RowLeftHalfGemContainer = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
Car,
|
Car,
|
||||||
} from "../../types/state";
|
} from "../../types/state";
|
||||||
import { Meters } from "../../types/util";
|
import { Meters } from "../../types/util";
|
||||||
|
import { orMatch } from "../../utils/common";
|
||||||
import { cloneDriver, getTeam } from "../../utils/dataLookup";
|
import { cloneDriver, getTeam } from "../../utils/dataLookup";
|
||||||
import { driverToGridMap } from "../../utils/event";
|
import { driverToGridMap } from "../../utils/event";
|
||||||
|
|
||||||
@@ -262,6 +263,12 @@ export const eventSlice = createSlice({
|
|||||||
const { cars, distance, randomness, usePerformance } = action.payload;
|
const { cars, distance, randomness, usePerformance } = action.payload;
|
||||||
|
|
||||||
cars.forEach(car => {
|
cars.forEach(car => {
|
||||||
|
// Do not update cars that are DNS, retired, or finished.
|
||||||
|
// This does remind me that Finished cars must be treated and reported
|
||||||
|
// differently...
|
||||||
|
if (orMatch(car.status, CarStatus.DidNotStart, CarStatus.Finished, CarStatus.Retired)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let addedDistance = distance;
|
let addedDistance = distance;
|
||||||
|
|
||||||
if (randomness !== 0){
|
if (randomness !== 0){
|
||||||
|
|||||||
@@ -18,11 +18,14 @@ export const theme = {
|
|||||||
disabledGreen: "#b1d3b2",
|
disabledGreen: "#b1d3b2",
|
||||||
activeRed: "#e63746",
|
activeRed: "#e63746",
|
||||||
disabledRed: "#e08a91",
|
disabledRed: "#e08a91",
|
||||||
|
posLostRed: "#e40030",
|
||||||
|
posGainedGreen: "#10ff35",
|
||||||
grey: "#aaa",
|
grey: "#aaa",
|
||||||
lightGrey: "#ddd",
|
lightGrey: "#ddd",
|
||||||
faintGrey: "#eee",
|
faintGrey: "#eee",
|
||||||
darkGrey: "#303030",
|
darkGrey: "#303030",
|
||||||
videoFrameBG: "#333",
|
videoFrameBG: "#333",
|
||||||
|
positionFlagBG: "#f4f3ee",
|
||||||
teams: { // 2021 Season
|
teams: { // 2021 Season
|
||||||
alfaRomeo: "#900000",
|
alfaRomeo: "#900000",
|
||||||
alphaTauri: "#2b4562",
|
alphaTauri: "#2b4562",
|
||||||
|
|||||||
@@ -1585,6 +1585,11 @@
|
|||||||
estree-walker "^1.0.1"
|
estree-walker "^1.0.1"
|
||||||
picomatch "^2.2.2"
|
picomatch "^2.2.2"
|
||||||
|
|
||||||
|
"@rooks/use-timeout-when@^4.11.2":
|
||||||
|
version "4.11.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@rooks/use-timeout-when/-/use-timeout-when-4.11.2.tgz#12441395abd754ccd4aa93d38598981c26274ef0"
|
||||||
|
integrity sha512-ytSqN4KyDdLtMS69RbiQ/Y4Tc1vyCh508FkLMnEAMF2AQZo/C/7sEL2WnLTz04/fD9AbEgSIpfB28XOourDaNg==
|
||||||
|
|
||||||
"@rushstack/eslint-patch@^1.1.0":
|
"@rushstack/eslint-patch@^1.1.0":
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.1.0.tgz"
|
resolved "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.1.0.tgz"
|
||||||
|
|||||||
Reference in new issue
Block a user