ISSUE-057 - Added outline effect to position changes left half side.
Refactored outlineClipPath() to support outlines that have been offset to be inside. Added animation duration configuration to the TimingBoard workspace.
This commit is contained in:
1 parent
e88bd614d3
commit
cdf8d2b332
7 files changed
+127
-28
No files matched your search
@@ -1,3 +0,0 @@
|
||||
import styled from "styled-components";
|
||||
|
||||
export const Foo = styled.div``;
|
||||
@@ -1,9 +1,14 @@
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
|
||||
import { theme } from "../../../shared/theme";
|
||||
import { MockupBlock } from "../../Common/MockupBlock.styled";
|
||||
|
||||
import { TimingBoardLayout } from "./styles";
|
||||
import { MockupBlock } from "../../Common/MockupBlock.styled";
|
||||
import { TimingTower } from "./TimingTower";
|
||||
|
||||
export function TimingBoard() {
|
||||
const { debugDurationMultiplier } = useSelector(workspaceSelector);
|
||||
return (
|
||||
<TimingBoardLayout>
|
||||
<MockupBlock
|
||||
@@ -11,7 +16,9 @@ export function TimingBoard() {
|
||||
width={`${theme.design.timingTower.rowLeftHalfWidthPx}px`}
|
||||
color="black"
|
||||
/>
|
||||
<TimingTower />
|
||||
<TimingTower
|
||||
debugDurationMultiplier={debugDurationMultiplier}
|
||||
/>
|
||||
</TimingBoardLayout>
|
||||
);
|
||||
}
|
||||
@@ -4,11 +4,16 @@ import { useSelector } from "react-redux";
|
||||
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
|
||||
import { eventSelector } from "../../../../features/event/eventSelector";
|
||||
import { CarStatus } from "../../../../types/state";
|
||||
import { Fraction } from "../../../../types/style";
|
||||
|
||||
import { RowsContainer } from "./styles";
|
||||
import { TimingTowerRow } from "./TimingTowerRow";
|
||||
|
||||
export function TimingTower() {
|
||||
type TimingTowerProps = {
|
||||
debugDurationMultiplier?: Fraction,
|
||||
};
|
||||
|
||||
export function TimingTower({ debugDurationMultiplier: DDM }: TimingTowerProps) {
|
||||
const { lastUpdate, grid, trackLength } = useSelector(eventSelector);
|
||||
const { timingBoard: { timingTower: { splitsMode, displayMode } } } = useSelector(
|
||||
broadcastGraphicsSelector,
|
||||
@@ -41,6 +46,7 @@ export function TimingTower() {
|
||||
splitsMode={splitsMode}
|
||||
displayMode={displayMode}
|
||||
trackLength={trackLength}
|
||||
debugDurationMultiplier={DDM}
|
||||
/>));
|
||||
}, [lastUpdate, splitsMode]);
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import useTimeoutWhen from "@rooks/use-timeout-when";
|
||||
import { useSpring } from "@react-spring/web";
|
||||
|
||||
import { theme } from "../../../../shared/theme";
|
||||
import { orMatch } from "../../../../utils/common";
|
||||
import { getCarAtPos, timeDiff } from "../../../../utils/event";
|
||||
import { formatTime } from "../../../../utils/styling";
|
||||
import { formatTime, outlineClipPath } from "../../../../utils/styling";
|
||||
|
||||
import { Fraction } from "../../../../types/style";
|
||||
import { Meters, Milliseconds } from "../../../../types/util";
|
||||
@@ -32,10 +33,13 @@ import {
|
||||
RowRightHalfLayout,
|
||||
TimeDiff,
|
||||
RowLeftHalfPosFlagChangeContainer,
|
||||
AnimatedRowLeftHalfOutline,
|
||||
} from "./styles";
|
||||
import useMeasure from "react-use-measure";
|
||||
|
||||
const WIPE_DELAY: Milliseconds = 3500;
|
||||
const WIPE_DURATION: Milliseconds = 400;
|
||||
const TRAVEL_DURATION: Milliseconds = 750;
|
||||
|
||||
interface TimingTowerRowProps {
|
||||
car: Car;
|
||||
@@ -45,6 +49,7 @@ interface TimingTowerRowProps {
|
||||
splitsMode: BGTimingTowerSplitsMode;
|
||||
displayMode: BGTimingTowerDisplayMode;
|
||||
trackLength: Meters;
|
||||
debugDurationMultiplier?: Fraction,
|
||||
}
|
||||
export function TimingTowerRow({
|
||||
car,
|
||||
@@ -54,26 +59,41 @@ export function TimingTowerRow({
|
||||
splitsMode,
|
||||
displayMode,
|
||||
trackLength,
|
||||
debugDurationMultiplier: DDM = 1.0,
|
||||
}: 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 [showPosChange, setshowPosChange] = useState(false);
|
||||
const [showOutline, setShowOutline] = useState(false);
|
||||
const [wipeVisible, setWipeVisible] = useState(false);
|
||||
useTimeoutWhen(() => setShowChange(false), WIPE_DELAY + WIPE_DURATION, showChange);
|
||||
useTimeoutWhen(() => setshowPosChange(false), (WIPE_DELAY + WIPE_DURATION) * DDM, showPosChange);
|
||||
useTimeoutWhen(() => setShowOutline(false), TRAVEL_DURATION * DDM, showOutline);
|
||||
useTimeoutWhen(() => setWipeVisible(false), 1, wipeVisible);
|
||||
|
||||
useEffect(() => {
|
||||
if (car.position !== pastPos) {
|
||||
setPastPos(car.position);
|
||||
setPosChange(pastPos - car.position);
|
||||
setShowChange(true);
|
||||
setshowPosChange(true);
|
||||
setShowOutline(true);
|
||||
setWipeVisible(true);
|
||||
}
|
||||
}, [car.position]);
|
||||
|
||||
const { outlineClipPathProgress } = useSpring({
|
||||
outlineClipPathProgress: showPosChange ? 1 : 0,
|
||||
config: { duration: 333 * DDM },
|
||||
delay: 0 * DDM,
|
||||
});
|
||||
|
||||
const [leftHalfRef, {
|
||||
height: leftHalfHeight,
|
||||
width: leftHalfWidth,
|
||||
}] = useMeasure();
|
||||
|
||||
const bottomRounded = car.status === CarStatus.Retired ? (
|
||||
car.position === startingCarsCount
|
||||
) : (
|
||||
@@ -113,7 +133,7 @@ export function TimingTowerRow({
|
||||
retired={car.status === CarStatus.Retired}
|
||||
wide={displayMode !== BGTimingTowerDisplayMode.LeftOnly}
|
||||
top={(car.position - 1) * theme.design.timingTower.rowHeightPx}
|
||||
transitionTime={750}
|
||||
transitionTime={TRAVEL_DURATION * DDM}
|
||||
>
|
||||
{car.notices.includes(CarNotice.FastestLap) && (
|
||||
<FastestLapGem />
|
||||
@@ -126,6 +146,8 @@ export function TimingTowerRow({
|
||||
BGTimingTowerDisplayMode.FullLeft,
|
||||
) ? 5 : undefined
|
||||
}
|
||||
transitionTime={TRAVEL_DURATION * DDM}
|
||||
ref={leftHalfRef}
|
||||
>
|
||||
<RowLeftHalfLayout>
|
||||
{car.status !== CarStatus.Retired && (
|
||||
@@ -137,15 +159,15 @@ export function TimingTowerRow({
|
||||
/>
|
||||
<RowLeftHalfPosFlagChangeContainer
|
||||
size={32}
|
||||
visible={showChange}
|
||||
transitionTime={167}
|
||||
visible={showPosChange}
|
||||
transitionTime={167 * DDM}
|
||||
>
|
||||
{showChange && (
|
||||
{showPosChange && (
|
||||
<WipeTransition
|
||||
visible={wipeVisible}
|
||||
delay={WIPE_DELAY}
|
||||
delay={WIPE_DELAY * DDM}
|
||||
angle={45}
|
||||
duration={WIPE_DURATION}
|
||||
duration={WIPE_DURATION * DDM}
|
||||
startingCorner="topLeft"
|
||||
>
|
||||
<PositionFlag
|
||||
@@ -170,7 +192,36 @@ export function TimingTowerRow({
|
||||
<RowLeftHalfGemContainer>
|
||||
<TeamGem team={car.driver.team.id} height={30} />
|
||||
</RowLeftHalfGemContainer>
|
||||
|
||||
<AnimatedRowLeftHalfOutline
|
||||
open={showOutline}
|
||||
startThickness={1.5}
|
||||
endThickness={1.5}
|
||||
startColor={posChange > 0
|
||||
? theme.colors.posGainedGreen
|
||||
: theme.colors.posLostRed}
|
||||
endColor={posChange > 0
|
||||
? theme.colors.posGainedGreen
|
||||
: theme.colors.posLostRed}
|
||||
transitionProps={[{
|
||||
property: "opacity",
|
||||
duration: 333 * DDM,
|
||||
}]}
|
||||
style={{
|
||||
clipPath: outlineClipPathProgress.to(progress => {
|
||||
const coordinates = outlineClipPath(
|
||||
leftHalfWidth,
|
||||
leftHalfHeight,
|
||||
progress,
|
||||
3,
|
||||
3,
|
||||
);
|
||||
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
</RowLeftHalf>
|
||||
|
||||
<RowRightHalf
|
||||
roundedCornerTop={car.position === 1 ? 5 : undefined}
|
||||
roundedCornerBottom={
|
||||
@@ -180,6 +231,7 @@ export function TimingTowerRow({
|
||||
BGTimingTowerSplitsMode.Interval,
|
||||
) ? 5 : undefined
|
||||
}
|
||||
transitionTime={TRAVEL_DURATION * DDM}
|
||||
>
|
||||
<RowRightHalfLayout>
|
||||
<TimeDiff xScale={xScale} yScale={yScale}>
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import styled, { css } from "styled-components";
|
||||
import { animated } from "@react-spring/web";
|
||||
|
||||
import { Fraction, Px } from "../../../../types/style";
|
||||
import { Fraction, Px, TransitionArgs } from "../../../../types/style";
|
||||
import { Milliseconds } from "../../../../types/util";
|
||||
import { commonTransition } from "../../../../utils/styling";
|
||||
|
||||
import fastestLapIcon from "../../../../public/images/icons/fastest-lap.svg";
|
||||
|
||||
|
||||
type OpenProps = {
|
||||
open: boolean,
|
||||
};
|
||||
type TransitionProps = OpenProps & {
|
||||
transitionProps: TransitionArgs[],
|
||||
};
|
||||
|
||||
type RowsContainerProps = {
|
||||
carsToDisplay: number,
|
||||
retiredCarsPresent: boolean,
|
||||
@@ -52,13 +61,15 @@ AnimatedRowContainer.displayName = "AnimatedRowContainer";
|
||||
type RoundedProp = {
|
||||
roundedCornerTop?: Px,
|
||||
roundedCornerBottom?: Px,
|
||||
transitionTime: Milliseconds,
|
||||
};
|
||||
const Rounded = styled.div<RoundedProp>`
|
||||
${({ roundedCornerTop }) =>
|
||||
roundedCornerTop && css`border-top-right-radius: ${roundedCornerTop}px;`}
|
||||
${({ roundedCornerBottom }) =>
|
||||
roundedCornerBottom && css`border-bottom-right-radius: ${roundedCornerBottom}px;`}
|
||||
transition: border-top-right-radius 500ms, border-bottom-right-radius 500ms;
|
||||
transition: border-top-right-radius ${({ transitionTime }) => transitionTime}ms,
|
||||
border-bottom-right-radius ${({ transitionTime }) => transitionTime}ms;
|
||||
`;
|
||||
|
||||
export const RowLeftHalf = styled(Rounded)`
|
||||
@@ -73,6 +84,29 @@ export const RowLeftHalf = styled(Rounded)`
|
||||
`;
|
||||
RowLeftHalf.displayName = "RowLeftHalf";
|
||||
|
||||
type AnimatedRowLeftHalfOutlineProps = TransitionProps & {
|
||||
startThickness: Px,
|
||||
endThickness: Px,
|
||||
startColor: string,
|
||||
endColor: string,
|
||||
};
|
||||
export const AnimatedRowLeftHalfOutline = animated(styled(Rounded) <AnimatedRowLeftHalfOutlineProps>`
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
opacity: ${({ open }) => open ? 1 : 0};
|
||||
outline: ${({ open, startThickness, endThickness, startColor, endColor }) => open
|
||||
? `${endThickness}px solid ${endColor}`
|
||||
: `${startThickness}px solid ${startColor}`};
|
||||
outline-offset: ${({ startThickness }) => -startThickness}px;
|
||||
|
||||
${({ transitionProps }) => commonTransition(transitionProps)}
|
||||
`);
|
||||
AnimatedRowLeftHalfOutline.displayName = "AnimatedRowLeftHalfOutline";
|
||||
|
||||
export const RowLeftHalfLayout = styled.div`
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
||||
@@ -97,6 +97,7 @@ export default function Workspaces() {
|
||||
previewContent={<TimingBoard />}
|
||||
prototypeControls={<TimingTowerPrototypeControls />}
|
||||
bleedover={500}
|
||||
showAnimationSpeedSelector
|
||||
/>
|
||||
} />
|
||||
<Route path="*" element={<IndexHeading>Unknown Workspace</IndexHeading>} />
|
||||
|
||||
+12
-10
@@ -80,6 +80,7 @@ export function commonTransition(propsArray: TransitionArgs[]) {
|
||||
* @param height element height in pixels
|
||||
* @param progress fraction from 0 to 1
|
||||
* @param outlineThickness the expected max width of the outline
|
||||
* @param interiorThickness the expected max width of the outline internally
|
||||
* @returns
|
||||
*/
|
||||
export function outlineClipPath(
|
||||
@@ -87,6 +88,7 @@ export function outlineClipPath(
|
||||
height: Px,
|
||||
progress: Fraction,
|
||||
outlineThickness: Px,
|
||||
interiorThickness: Px = 0,
|
||||
): [[Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px]] {
|
||||
const travelDistance = width * 2 + height;
|
||||
const pt1End = width / travelDistance;
|
||||
@@ -96,10 +98,10 @@ export function outlineClipPath(
|
||||
if (progress <= pt1End) {
|
||||
const x = width * progress / pt1End;
|
||||
return [
|
||||
[0, height],
|
||||
[0, height],
|
||||
[0, height],
|
||||
[x, height],
|
||||
[0, height - interiorThickness],
|
||||
[0, height - interiorThickness],
|
||||
[0, height - interiorThickness],
|
||||
[x, height - interiorThickness],
|
||||
[x, height + outlineThickness],
|
||||
[0, height + outlineThickness],
|
||||
];
|
||||
@@ -108,9 +110,9 @@ export function outlineClipPath(
|
||||
} else if (progress > pt1End && progress <= pt2End) {
|
||||
const y = height - (height + outlineThickness) * ((progress - pt1End) / (pt2End - pt1End));
|
||||
return [
|
||||
[0, height],
|
||||
[width - 10, height],
|
||||
[width, y],
|
||||
[0, height - interiorThickness],
|
||||
[width - Math.max(10, interiorThickness), height - interiorThickness],
|
||||
[width - interiorThickness, y],
|
||||
[width + outlineThickness, y],
|
||||
[width + outlineThickness, height + outlineThickness],
|
||||
[0, height + outlineThickness],
|
||||
@@ -120,9 +122,9 @@ export function outlineClipPath(
|
||||
} else {
|
||||
const x = width - width * ((progress - pt2End) / (1 - pt2End));
|
||||
return [
|
||||
[0, height],
|
||||
[x - 10, height],
|
||||
[x, -outlineThickness],
|
||||
[0, height - interiorThickness],
|
||||
[x - Math.max(10, interiorThickness), height - interiorThickness],
|
||||
[x - interiorThickness, -outlineThickness],
|
||||
[width + outlineThickness, -outlineThickness],
|
||||
[width + outlineThickness, height + outlineThickness],
|
||||
[0, height + outlineThickness],
|
||||
|
||||
Reference in new issue
Block a user