Merge pull request #73 from TiE23/ISSUE-069

Issue 069
This commit is contained in:
Kyle Geib authored and GitHub committed 2022-03-14 09:28:16 -05:00
commit 9ccaa5b3d6
7 files changed
+105 -66

No files matched your search

@@ -7,17 +7,19 @@ type PositionFlagProps = {
size: Px, size: Px,
number: number, number: number,
numberSizeFraction?: Fraction, numberSizeFraction?: Fraction,
color?: string; bgColor?: string,
numberColor?: string,
}; };
export function PositionFlag({ export function PositionFlag({
size, size,
number, number,
numberSizeFraction = 0.64, numberSizeFraction = 0.64,
color = theme.colors.positionFlagBG, bgColor = theme.colors.posWhite,
numberColor = theme.colors.black,
}: PositionFlagProps) { }: PositionFlagProps) {
return ( return (
<PositionFlagBox size={size} color={color}> <PositionFlagBox size={size} color={bgColor}>
<PositionNumber size={size * numberSizeFraction}> <PositionNumber size={size * numberSizeFraction} color={numberColor}>
{number} {number}
</PositionNumber> </PositionNumber>
</PositionFlagBox> </PositionFlagBox>
@@ -21,10 +21,12 @@ PositionFlagBox.displayName = "PositionFlagBox";
type PositionNumberProps = { type PositionNumberProps = {
size: Px, size: Px,
color: string,
}; };
export const PositionNumber = styled.span<PositionNumberProps>` export const PositionNumber = styled.span<PositionNumberProps>`
font-family: ${p => p.theme.fonts.f1Regular}; font-family: ${p => p.theme.fonts.f1Regular};
font-size: ${({ size }) => size}px; font-size: ${({ size }) => size}px;
color: ${({ color }) => color};
margin-top: 2px; margin-top: 2px;
`; `;
PositionNumber.displayName = "PositionNumber"; PositionNumber.displayName = "PositionNumber";
@@ -36,6 +36,7 @@ import {
AnimatedRowLeftHalfOutline, AnimatedRowLeftHalfOutline,
DriverNameContainer, DriverNameContainer,
DriverNameWipe, DriverNameWipe,
FastestLapContainer,
} from "./styles"; } from "./styles";
import useMeasure from "react-use-measure"; import useMeasure from "react-use-measure";
@@ -61,30 +62,38 @@ export function TimingTowerRow({
const { design: { timingTower: ttTheme } } = theme; const { design: { timingTower: ttTheme } } = theme;
const [pastPos, setPastPos] = useState(car.position); const [pastPos, setPastPos] = useState(car.position);
const [posChange, setPosChange] = useState(0); const [currentFL, setCurrentFL] = useState(false);
const [pastDisplayMode, setPastDisplayMode] = useState(displayMode); const [pastDisplayMode, setPastDisplayMode] = useState(displayMode);
const [hugRight, setHugRight] = useState(true); const [hugRight, setHugRight] = useState(true);
// Using timeouts and boolean states I can manipulate visiblity of the position // 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. // change effects. When a
const [showPosChange, setShowPosChange] = useState(false);
const [showOutline, setShowOutline] = useState(false); const [showOutline, setShowOutline] = useState(false);
const [wipeVisible, setWipeVisible] = useState(false);
useTimeoutWhen(() => setShowPosChange(false), (
ttTheme.wipeDelayMs + ttTheme.wipeDurationMs
) * DDM, showPosChange);
useTimeoutWhen(() => setShowOutline(false), ttTheme.rowTravelDurationMs * DDM, showOutline); useTimeoutWhen(() => setShowOutline(false), ttTheme.rowTravelDurationMs * DDM, showOutline);
useTimeoutWhen(() => setWipeVisible(false), 1, wipeVisible); const [showChangeFlag, setShowChangeFlag] = useState(false);
useTimeoutWhen(() => setShowChangeFlag(false), ttTheme.wipeDelayMs * DDM, showChangeFlag);
const [changeColors, setChangeColors] = useState<[string, string]>(["white", "black"]);
useEffect(() => { useEffect(() => {
if (car.position !== pastPos) { if (car.position !== pastPos) {
// Position change.
setShowChangeFlag(true);
setChangeColors([
car.position < pastPos ? theme.colors.posGainedGreen : theme.colors.posLostRed,
theme.colors.black,
]);
setPastPos(car.position); setPastPos(car.position);
setPosChange(pastPos - car.position);
setShowPosChange(true);
setShowOutline(true); setShowOutline(true);
setWipeVisible(true); } else if (car.notices.includes(CarNotice.FastestLap) && !currentFL) {
// Fastest Lap gained.
setShowChangeFlag(true);
setCurrentFL(true);
setChangeColors([theme.colors.posFastestLap, theme.colors.textWhite]);
} else if (currentFL && !car.notices.includes(CarNotice.FastestLap)) {
// Fastest Lap lost.
setCurrentFL(false);
} }
}, [car.position]); }, [car.position, car.notices]);
useEffect(() => { useEffect(() => {
if (pastDisplayMode !== displayMode) { if (pastDisplayMode !== displayMode) {
@@ -103,7 +112,7 @@ export function TimingTowerRow({
}, [displayMode]); }, [displayMode]);
const { outlineClipPathProgress } = useSpring({ const { outlineClipPathProgress } = useSpring({
outlineClipPathProgress: showPosChange ? 1 : 0, outlineClipPathProgress: showOutline ? 1 : 0,
config: { duration: 333 * DDM }, config: { duration: 333 * DDM },
delay: 0 * DDM, delay: 0 * DDM,
}); });
@@ -154,9 +163,15 @@ export function TimingTowerRow({
top={(car.position - 1) * ttTheme.rowHeightPx} top={(car.position - 1) * ttTheme.rowHeightPx}
transitionTime={ttTheme.rowTravelDurationMs * DDM} transitionTime={ttTheme.rowTravelDurationMs * DDM}
> >
{car.notices.includes(CarNotice.FastestLap) && ( <FastestLapContainer>
<FastestLapGem /> <FastestLapGem
)} open={car.notices.includes(CarNotice.FastestLap)}
transitionProps={[{
property: "left",
duration: ttTheme.fastestLapToastDurationMs * DDM,
}]}
/>
</FastestLapContainer>
<RowLeftHalf <RowLeftHalf
roundedCornerBottom={ roundedCornerBottom={
bottomRounded && orMatch( bottomRounded && orMatch(
@@ -193,36 +208,34 @@ export function TimingTowerRow({
> >
<RowLeftHalfLayout> <RowLeftHalfLayout>
{car.status !== CarStatus.Retired && ( {car.status !== CarStatus.Retired && (
/**
* The "Change" PositionFlag (the colored one) is always present but
* usually hidden under a second visible "Normal" PositionFlag. When
* a change is made the normal PositionFlag is hidden instantly and
* after a delay is revealed. With the reveal a WipeTransition also
* takes place. Before, the "Change" PositionFlag would wipe away.
* Now, instead, it is hidden under a revealed "Normal" PositionFlag.
*/
<RowLeftHalfPosFlagContainer size={ttTheme.posFlagSizePx}> <RowLeftHalfPosFlagContainer size={ttTheme.posFlagSizePx}>
<PositionFlag <PositionFlag
size={ttTheme.posFlagSizePx} size={ttTheme.posFlagSizePx}
number={car.position} number={car.position}
numberSizeFraction={.6} numberSizeFraction={0.6}
bgColor={changeColors[0]}
numberColor={changeColors[1]}
/> />
<RowLeftHalfPosFlagChangeContainer <RowLeftHalfPosFlagChangeContainer open={!showChangeFlag}>
size={ttTheme.posFlagSizePx} <WipeTransition
visible={showPosChange} visible={!showChangeFlag}
transitionTime={167 * DDM} angle={45}
> duration={ttTheme.wipeDurationMs * DDM}
{showPosChange && ( startingCorner="bottomRight"
<WipeTransition >
visible={wipeVisible} <PositionFlag
delay={ttTheme.wipeDelayMs * DDM} size={ttTheme.posFlagSizePx}
angle={45} number={car.position}
duration={ttTheme.wipeDurationMs * DDM} />
startingCorner="topLeft" </WipeTransition>
>
<PositionFlag
size={ttTheme.posFlagSizePx}
number={car.position}
numberSizeFraction={.6}
color={posChange > 0
? theme.colors.posGainedGreen
: theme.colors.posLostRed}
/>
</WipeTransition>
)}
</RowLeftHalfPosFlagChangeContainer> </RowLeftHalfPosFlagChangeContainer>
</RowLeftHalfPosFlagContainer> </RowLeftHalfPosFlagContainer>
)} )}
@@ -277,12 +290,8 @@ export function TimingTowerRow({
open={showOutline} open={showOutline}
startThickness={1.5} startThickness={1.5}
endThickness={1.5} endThickness={1.5}
startColor={posChange > 0 startColor={changeColors[0]}
? theme.colors.posGainedGreen endColor={changeColors[0]}
: theme.colors.posLostRed}
endColor={posChange > 0
? theme.colors.posGainedGreen
: theme.colors.posLostRed}
transitionProps={[{ transitionProps={[{
property: "opacity", property: "opacity",
duration: 333 * DDM, duration: 333 * DDM,
@@ -5,9 +5,11 @@ import {
Fraction, Fraction,
Px, Px,
DirectionalTransitionProps, DirectionalTransitionProps,
TransitionProps,
OpenProps,
} from "../../../../types/style"; } from "../../../../types/style";
import { Milliseconds } from "../../../../types/util"; import { Milliseconds } from "../../../../types/util";
import { commonDirectionalTransition } from "../../../../utils/styling"; import { commonDirectionalTransition, commonTransition } from "../../../../utils/styling";
import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg"; import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg";
@@ -118,6 +120,7 @@ export const RowLeftHalfLayout = styled.div`
display: flex; display: flex;
padding-left: 3px; padding-left: 3px;
align-items: center;
justify-content: flex-start; justify-content: flex-start;
`; `;
RowLeftHalfLayout.displayName = "RowLeftHalfLayout"; RowLeftHalfLayout.displayName = "RowLeftHalfLayout";
@@ -132,20 +135,12 @@ export const RowLeftHalfPosFlagContainer = styled.div<RowLeftHalfPosFlagContaine
`; `;
RowLeftHalfPosFlagContainer.displayName = "RowLeftHalfPosFlagContainer"; RowLeftHalfPosFlagContainer.displayName = "RowLeftHalfPosFlagContainer";
type RowLeftHalfPosFlagChangeContainerProps = { export const RowLeftHalfPosFlagChangeContainer = styled.div<OpenProps>`
size: Px,
visible: boolean,
transitionTime: Milliseconds,
};
export const RowLeftHalfPosFlagChangeContainer = styled.div<RowLeftHalfPosFlagChangeContainerProps>`
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
height: ${({ size }) => size}px;
width: ${({ size }) => size}px;
opacity: ${({ visible }) => visible ? 1 : 0}; opacity: ${({ open }) => open ? 1 : 0};
transition: opacity ${({ transitionTime }) => transitionTime}ms;
`; `;
RowLeftHalfPosFlagChangeContainer.displayName = "RowLeftHalfPosFlagChangeContainer"; RowLeftHalfPosFlagChangeContainer.displayName = "RowLeftHalfPosFlagChangeContainer";
@@ -198,6 +193,7 @@ RowRightHalfLayout.displayName = "RowRightHalfLayout";
export const DriverNameContainer = styled.div` export const DriverNameContainer = styled.div`
position: relative; position: relative;
margin-left: ${p => p.theme.design.timingTower.nameLeftMarginPx}px; margin-left: ${p => p.theme.design.timingTower.nameLeftMarginPx}px;
margin-top: ${p => p.theme.design.timingTower.nameTopMarginPx}px;
`; `;
DriverNameContainer.displayName = "DriverNameContainer"; DriverNameContainer.displayName = "DriverNameContainer";
@@ -251,19 +247,32 @@ export const TimeDiff = styled.span<TimeDiffProps>`
`; `;
TimeDiff.displayName = "TimeDiff"; TimeDiff.displayName = "TimeDiff";
export const FastestLapGem = styled.div` export const FastestLapContainer = styled.div`
position: absolute; position: absolute;
left: ${p => -p.theme.design.timingTower.rowHeightPx + 2}px;
top: 0;
height: ${p => p.theme.design.timingTower.rowHeightPx}px; height: ${p => p.theme.design.timingTower.rowHeightPx}px;
width: ${p => p.theme.design.timingTower.rowHeightPx - 2}px; width: ${p => p.theme.design.timingTower.rowHeightPx - 2}px;
left: ${p => -p.theme.design.timingTower.rowHeightPx + 2}px; overflow: clip;
`;
export const FastestLapGem = styled.div<TransitionProps>`
position: absolute;
left: ${({ open }) => open ? 0
: p => p.theme.design.timingTower.rowHeightPx}px;
top: 0; top: 0;
height: ${p => p.theme.design.timingTower.rowHeightPx}px;
width: ${p => p.theme.design.timingTower.rowHeightPx - 2}px;
background-color: ${p => p.theme.colors.laps.purple}; background-color: ${p => p.theme.colors.laps.purple};
background-image: url(${fastestLapIcon}); background-image: url(${fastestLapIcon});
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 89%; background-size: 89%;
background-position: center 40%; background-position: center 40%;
${({ transitionProps }) => commonTransition(transitionProps)}
`; `;
FastestLapGem.displayName = "FastestLapGem"; FastestLapGem.displayName = "FastestLapGem";
@@ -8,7 +8,7 @@ import { broadcastDirectorSelector } from "../../../../features/broadcast/direct
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector"; import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
import { setTimingTowerDisplayMode, setTimingTowerSplitsMode } from "../../../../features/broadcast/graphics/broadcastGraphicsSlice"; import { setTimingTowerDisplayMode, setTimingTowerSplitsMode } from "../../../../features/broadcast/graphics/broadcastGraphicsSlice";
import { eventSelector } from "../../../../features/event/eventSelector"; import { eventSelector } from "../../../../features/event/eventSelector";
import { increaseDistance, refreshRunningOrder, setCarStatus } from "../../../../features/event/eventSlice"; import { awardFastestLap, increaseDistance, refreshRunningOrder, setCarStatus } from "../../../../features/event/eventSlice";
import { BGTimingTowerDisplayMode, BGTimingTowerSplitsMode, CarStatus } from "../../../../types/state"; import { BGTimingTowerDisplayMode, BGTimingTowerSplitsMode, CarStatus } from "../../../../types/state";
import { GridSelection } from "../GridSelection"; import { GridSelection } from "../GridSelection";
@@ -90,6 +90,15 @@ export function TimingTowerPrototypeControls() {
> >
Un-retire Un-retire
</ClickSpan> </ClickSpan>
<ClickSpan
onClick={() => {
if (selectedCars.length > 0) {
dispatch(awardFastestLap(selectedCars[0]));
}
}}
>
Award FL
</ClickSpan>
</InlineCluster> </InlineCluster>
<hr /> <hr />
<InlineCluster gutter="md"> <InlineCluster gutter="md">
+4
View File
@@ -222,6 +222,10 @@ interface SetCarStatusAction {
status: CarStatus; status: CarStatus;
} }
/**
* Note: Add `state.lastUpdate = Date.now();` to the end of every reducer to
* keep components up to date that watch for changes with useEffect() functions.
*/
export const eventSlice = createSlice({ export const eventSlice = createSlice({
name: "event", name: "event",
initialState, initialState,
+5 -1
View File
@@ -20,13 +20,15 @@ export const theme = {
disabledRed: "#e08a91", disabledRed: "#e08a91",
posLostRed: "#e40030", posLostRed: "#e40030",
posGainedGreen: "#10ff35", posGainedGreen: "#10ff35",
posFastestLap: "#ae43ca",
black: "#000",
grey: "#aaa", grey: "#aaa",
lightGrey: "#ddd", lightGrey: "#ddd",
faintGrey: "#eee", faintGrey: "#eee",
darkGrey: "#303030", darkGrey: "#303030",
dimGrey: "#999", dimGrey: "#999",
videoFrameBG: "#333", videoFrameBG: "#333",
positionFlagBG: "#f4f3ee", posWhite: "#f4f3ee",
textWhite: "#f1f1f1", // I found it to be #f2f2f2 but whatever textWhite: "#f1f1f1", // I found it to be #f2f2f2 but whatever
teams: { // 2021 Season teams: { // 2021 Season
alfaRomeo: "#900000", alfaRomeo: "#900000",
@@ -83,12 +85,14 @@ export const theme = {
teamGemSizePx: 30, teamGemSizePx: 30,
posFlagSizePx: 32, posFlagSizePx: 32,
nameLeftMarginPx: 14, nameLeftMarginPx: 14,
nameTopMarginPx: 4,
rowRoundedCornerRadiusPx: 5, rowRoundedCornerRadiusPx: 5,
wipeDelayMs: 3500, wipeDelayMs: 3500,
wipeDurationMs: 400, wipeDurationMs: 400,
rowTravelDurationMs: 750, rowTravelDurationMs: 750,
fullWidthDurationMs: 750, fullWidthDurationMs: 750,
fullWidthCloseDelayMs: 333, fullWidthCloseDelayMs: 333,
fastestLapToastDurationMs: 500,
}, },
button: { button: {
borderRadius: "0.25rem", borderRadius: "0.25rem",