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
@@ -8,9 +8,7 @@ import { CarStatus } from "../../../../types/state";
|
||||
import { RowsContainer } from "./styles";
|
||||
import { TimingTowerRow } from "./TimingTowerRow";
|
||||
|
||||
|
||||
export function TimingTower() {
|
||||
|
||||
const { lastUpdate, grid, trackLength } = useSelector(eventSelector);
|
||||
const { timingBoard: { timingTower: { splitsMode, displayMode } } } = useSelector(
|
||||
broadcastGraphicsSelector,
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import useTimeoutWhen from "@rooks/use-timeout-when";
|
||||
|
||||
import { theme } from "../../../../shared/theme";
|
||||
import { orMatch } from "../../../../utils/common";
|
||||
import { getCarAtPos, timeDiff } from "../../../../utils/event";
|
||||
import { formatTime } from "../../../../utils/styling";
|
||||
|
||||
import { Fraction } from "../../../../types/style";
|
||||
import { Meters, Milliseconds } from "../../../../types/util";
|
||||
import {
|
||||
BGTimingTowerDisplayMode,
|
||||
BGTimingTowerSplitsMode,
|
||||
@@ -10,23 +16,27 @@ import {
|
||||
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 { WipeTransition } from "../../Common/WipeTransition";
|
||||
import {
|
||||
AnimatedRowContainer,
|
||||
DriverName,
|
||||
FastestLapGem,
|
||||
RowLeftHalf,
|
||||
RowLeftHalfPosFlagContainer,
|
||||
RowLeftHalfGemContainer,
|
||||
RowLeftHalfLayout,
|
||||
RowRightHalf,
|
||||
RowRightHalfLayout,
|
||||
TimeDiff,
|
||||
RowLeftHalfPosFlagChangeContainer,
|
||||
} from "./styles";
|
||||
|
||||
const WIPE_DELAY: Milliseconds = 3500;
|
||||
const WIPE_DURATION: Milliseconds = 400;
|
||||
|
||||
interface TimingTowerRowProps {
|
||||
car: Car;
|
||||
grid: Grid;
|
||||
@@ -45,6 +55,25 @@ export function TimingTowerRow({
|
||||
displayMode,
|
||||
trackLength,
|
||||
}: 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 ? (
|
||||
car.position === startingCarsCount
|
||||
) : (
|
||||
@@ -84,6 +113,7 @@ export function TimingTowerRow({
|
||||
retired={car.status === CarStatus.Retired}
|
||||
wide={displayMode !== BGTimingTowerDisplayMode.LeftOnly}
|
||||
top={(car.position - 1) * theme.design.timingTower.rowHeightPx}
|
||||
transitionTime={750}
|
||||
>
|
||||
{car.notices.includes(CarNotice.FastestLap) && (
|
||||
<FastestLapGem />
|
||||
@@ -99,11 +129,39 @@ export function TimingTowerRow({
|
||||
>
|
||||
<RowLeftHalfLayout>
|
||||
{car.status !== CarStatus.Retired && (
|
||||
<PositionFlag
|
||||
size={32}
|
||||
number={car.position}
|
||||
numberSizeFraction={.6}
|
||||
/>
|
||||
<RowLeftHalfPosFlagContainer size={32}>
|
||||
<PositionFlag
|
||||
size={32}
|
||||
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>
|
||||
{car.driver.initials}
|
||||
@@ -132,3 +190,4 @@ export function TimingTowerRow({
|
||||
</AnimatedRowContainer>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import styled, { css } from "styled-components";
|
||||
import { animated } from "@react-spring/web";
|
||||
|
||||
import { Fraction, Px } from "../../../../types/style";
|
||||
import { Milliseconds } from "../../../../types/util";
|
||||
|
||||
import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg";
|
||||
|
||||
@@ -26,6 +27,7 @@ type AnimatedRowContainerProps = {
|
||||
retired?: boolean,
|
||||
wide?: boolean,
|
||||
top: Px,
|
||||
transitionTime: Milliseconds,
|
||||
};
|
||||
// All the elements in a row should go in here.
|
||||
export const AnimatedRowContainer = animated(styled.div.attrs<AnimatedRowContainerProps>(({
|
||||
@@ -38,7 +40,7 @@ export const AnimatedRowContainer = animated(styled.div.attrs<AnimatedRowContain
|
||||
}))<AnimatedRowContainerProps>`
|
||||
position: absolute;
|
||||
left: 0;
|
||||
transition: top 500ms;
|
||||
transition: top ${({ transitionTime }) => transitionTime}ms;
|
||||
|
||||
width: ${({ wide }) => wide ? 255 : 147}px;
|
||||
height: ${p => p.theme.design.timingTower.rowHeightPx}px; // Future will be animated.
|
||||
@@ -84,6 +86,33 @@ export const RowLeftHalfLayout = styled.div`
|
||||
`;
|
||||
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`
|
||||
position: absolute;
|
||||
right: 0;
|
||||
|
||||
Reference in new issue
Block a user