ISSUE-035 - Took some work but have proper type checking for AngledFlag props and have updated everything necessary.

Styling is still to come. Only have Ferrari working.
I've discovered that the team flags are wider than the country flags. So I'll be tackling that necessary change in the next commit before dealing with styling.
This commit is contained in:
Kyle Geib committed 2022-02-01 12:57:40 -05:00
1 parent 57647f6488
commit bd1892ab17
9 files changed
+219 -41

No files matched your search

@@ -29,6 +29,9 @@ export function ChyronDriver({ chyronData, subMode }: ChyronDriverProps) {
: [0, 0]; : [0, 0];
const { car, flagMode, showPosFlag, showDriverNumber } = chyronData; const { car, flagMode, showPosFlag, showDriverNumber } = chyronData;
const flagProps = flagMode === "country"
? { flagMode, flag: car.driver.nationality }
: flagMode === "team" ? { flagMode, flag: car.driver.team.id } : undefined;
return ( return (
<BaseBackground width={baseWidth} height={baseHeight}> <BaseBackground width={baseWidth} height={baseHeight}>
@@ -64,11 +67,12 @@ export function ChyronDriver({ chyronData, subMode }: ChyronDriverProps) {
width={baseHeight * 3} width={baseHeight * 3}
right={-baseHeight * 0.6} right={-baseHeight * 0.6}
> >
{flagProps != null && (
<AngledFlag <AngledFlag
flagMode={flagMode}
flag={car.driver.nationality}
flagHeight={baseHeight * 0.9} flagHeight={baseHeight * 0.9}
flagProps={flagProps}
/> />
)}
</FlagContainer> </FlagContainer>
</BaseBackground> </BaseBackground>
); );
@@ -1,16 +1,19 @@
import { FlagMode } from "../../../../types/state"; import { ReactNode } from "react";
import { TeamId } from "../../../../types/state";
import { Px } from "../../../../types/style"; import { Px } from "../../../../types/style";
import { getTeamFlagStyle } from "../../../../utils/dataLookup";
import { import {
Container, Container,
Slant, Slant,
Sheen, Sheen,
CountryFlagEdge, FlagEdge,
CountryFlagDiv, CountryFlagDiv,
FlagContainer, FlagContainer,
TeamFlagDiv,
} from "./styles"; } from "./styles";
const countryFlags = require.context("../../../../public/images/countryFlags/angled", true); const countryFlags = require.context("../../../../public/images/countryFlags/angled", true);
// const teamLogos = require.context("../../../../public/images/teamLogos", true); const teamLogos = require.context("../../../../public/images/logos/team", true);
/** /**
* To look right, country flags need to be 2:1. Additional editing will be * To look right, country flags need to be 2:1. Additional editing will be
@@ -19,35 +22,67 @@ const countryFlags = require.context("../../../../public/images/countryFlags/ang
* center. * center.
*/ */
type AngledFlagProps = { type AngledFlagProps = {
flagMode: FlagMode,
flag: string,
flagHeight: Px, flagHeight: Px,
flagProps: {
flagMode: "country",
flag: string,
} | {
flagMode: "team",
flag: TeamId,
},
}; };
export function AngledFlag({ flagMode, flag, flagHeight }: AngledFlagProps) { export function AngledFlag(props: AngledFlagProps) {
const topFlag = flagMode === "country" const { flagProps, flagHeight } = props;
? (
let topFlag: ReactNode = null;
let bottomFlag: ReactNode = null;
if (flagProps.flagMode === "country") {
topFlag = (
<CountryFlagDiv <CountryFlagDiv
src={countryFlags(`./${flag}.svg`)} src={countryFlags(`./${flagProps.flag}.svg`)}
height={flagHeight} height={flagHeight}
width={flagHeight * 2} width={flagHeight * 2}
> >
<CountryFlagEdge <FlagEdge
x={flagHeight / 2} x={flagHeight / 2}
height={flagHeight} height={flagHeight}
girth={flagHeight * 0.07} girth={flagHeight * 0.07}
/> />
</CountryFlagDiv> </CountryFlagDiv>
) : null; // Team flag here );
bottomFlag = (
const bottomFlag = flagMode === "country"
? (
<CountryFlagDiv <CountryFlagDiv
src={countryFlags(`./${flag}.svg`)} src={countryFlags(`./${flagProps.flag}.svg`)}
height={flagHeight} height={flagHeight}
width={flagHeight * 2} width={flagHeight * 2}
xOffset={-flagHeight * 0.005} xOffset={-flagHeight * 0.005}
/> />
) : null; // Team flag here );
} else if (flagProps.flagMode === "team") {
topFlag = (
<TeamFlagDiv
src={teamLogos(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
style={getTeamFlagStyle(flagProps.flag)}
>
<FlagEdge
x={flagHeight / 2}
height={flagHeight}
girth={flagHeight * 0.07}
/>
</TeamFlagDiv>
);
bottomFlag = (
<TeamFlagDiv
src={teamLogos(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
style={getTeamFlagStyle(flagProps.flag)}
/>
);
}
return ( return (
<Container width={flagHeight * 6} height={flagHeight * 3}> <Container width={flagHeight * 6} height={flagHeight * 3}>
@@ -1,4 +1,5 @@
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
import { TeamFlagStyle } from "../../../../domain/data/teams";
import { Px } from "../../../../types/style"; import { Px } from "../../../../types/style";
type ContainerProps = { type ContainerProps = {
@@ -68,24 +69,48 @@ export const FlagContainer = styled.div<FlagContainerProps>`
`; `;
FlagContainer.displayName = "FlagContainer"; FlagContainer.displayName = "FlagContainer";
type CountryFlagDivProps = { type FlagDivBaseProps = {
src: string, src: string,
height: Px, height: Px,
width: Px, width: Px,
xOffset?: Px,
}; };
export const CountryFlagDiv = styled.div<CountryFlagDivProps>` const FlagDivBase = styled.div<FlagDivBaseProps>`
height: ${({ height }) => `${height}px`}; height: ${({ height }) => `${height}px`};
width: ${({ width }) => `${width}px`}; width: ${({ width }) => `${width}px`};
background-image: url(${({ src }) => src}); background-image: url(${({ src }) => src});
background-size: ${({ width, height }) => `${width}px ${height}px`};
background-repeat: no-repeat; background-repeat: no-repeat;
`;
type CountryFlagDivProps = {
xOffset?: Px,
};
export const CountryFlagDiv = styled(FlagDivBase)<CountryFlagDivProps>`
background-size: ${({ width, height }) => `${width}px ${height}px`};
${({ xOffset }) => xOffset == null ${({ xOffset }) => xOffset == null
? css`background-position: center;` ? css`background-position: center;`
: css`background-position-x: ${xOffset}px`} : css`background-position-x: ${xOffset}px`}
`; `;
CountryFlagDiv.displayName = "CountryFlagDiv"; CountryFlagDiv.displayName = "CountryFlagDiv";
type TeamFlagDivProps = {
style: TeamFlagStyle,
};
export const TeamFlagDiv = styled(FlagDivBase) <TeamFlagDivProps>`
height: ${({ height }) => `${height}px`};
width: ${({ width }) => `${width}px`};
background-image: url(${({ src }) => src})
${({ style: { backgroundImage } }) => backgroundImage
&& `, background-image: ${backgroundImage}`};
background-size: ${({ style: { imageSize } }) => `${imageSize}%`};
background-position: ${({ style: { imagePos: { x, y } } }) => `${x}% ${y}%`};
${({ style: { backgroundColor } }) => backgroundColor &&
css`background-color: ${backgroundColor};`}
${({ style: { backgroundImage } }) => backgroundImage &&
css`background-image: ${backgroundImage};`}
`;
type SlashProps = { type SlashProps = {
x?: Px, x?: Px,
height: Px, height: Px,
@@ -126,7 +151,7 @@ export const Slant = styled.div<SlashProps>`
`; `;
Slant.displayName = "Slant"; Slant.displayName = "Slant";
export const CountryFlagEdge = styled.div<SlashProps>` export const FlagEdge = styled.div<SlashProps>`
position: absolute; position: absolute;
height: ${({ height }) => `${height}px`}; height: ${({ height }) => `${height}px`};
width: ${({ girth }) => `${girth}px`}; width: ${({ girth }) => `${girth}px`};
@@ -142,4 +167,4 @@ export const CountryFlagEdge = styled.div<SlashProps>`
black 100% black 100%
); );
`; `;
CountryFlagEdge.displayName = "CountryFlagEdge"; FlagEdge.displayName = "FlagEdge";
@@ -1,7 +1,7 @@
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { workspaceSelector } from "../../../features/workspace/workspaceSelector"; import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
import { FlagMode } from "../../../types/state"; import { FlagMode, TeamId } from "../../../types/state";
import { AngledFlag } from "../../BroadcastGraphics/Common/AngledFlag"; import { AngledFlag } from "../../BroadcastGraphics/Common/AngledFlag";
import { BasicBlock } from "./styles"; import { BasicBlock } from "./styles";
@@ -11,20 +11,48 @@ type AngledFlagWorkSpaceProps = {
}; };
export function AngledFlagWorkSpace({ flagMode }: AngledFlagWorkSpaceProps) { export function AngledFlagWorkSpace({ flagMode }: AngledFlagWorkSpaceProps) {
const { prototypeState } = useSelector(workspaceSelector); const { prototypeState } = useSelector(workspaceSelector);
const defaultFlag = flagMode === "country" ? "GBR" : flagMode === "team" ? "alpine" : ""; if (flagMode === "none") return null;
const defaultTeam: TeamId = "alpine";
return ( return (
<BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)"> <BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)">
{flagMode === "country" ? (
<>
<AngledFlag <AngledFlag
flagMode={flagMode} flagProps={{
flag={prototypeState?.angledFlag?.flagA ?? defaultFlag} flagMode,
flag: prototypeState?.angledFlagCountry?.flagA ?? "GBR",
}}
flagHeight={64} flagHeight={64}
/> />
<AngledFlag <AngledFlag
flagMode={flagMode} flagProps={{
flag={prototypeState?.angledFlag?.flagB ?? defaultFlag} flagMode,
flag: prototypeState?.angledFlagCountry?.flagB ?? "GBR",
}}
flagHeight={128} flagHeight={128}
/> />
</>
) : flagMode === "team" ? (
<>
<AngledFlag
flagProps={{
flagMode,
flag: prototypeState?.angledFlagTeam?.flagA ?? defaultTeam,
}}
flagHeight={64}
/>
<AngledFlag
flagProps={{
flagMode,
flag: prototypeState?.angledFlagTeam?.flagB ?? defaultTeam,
}}
flagHeight={128}
/>
</>
) : null}
</BasicBlock> </BasicBlock>
); );
} }
@@ -26,12 +26,22 @@ export function AngledFlagPrototypeControls({ flagMode }: AngledFlagPrototypeCon
const flagList = flagMode === "country" ? countries : flagMode === "team" ? teams : []; const flagList = flagMode === "country" ? countries : flagMode === "team" ? teams : [];
const onChange = (flag: "flagA" | "flagB") => (index: number) => { const onChange = (flag: "flagA" | "flagB") => (index: number) => {
if (flagMode === "country") {
dispatch(setPrototypeState({ dispatch(setPrototypeState({
angledFlag: { angledFlagCountry: {
flagA: flag === "flagA" ? flagList[index] : prototypeState?.angledFlag?.flagA ?? "GBR", flagA: flag === "flagA" ? countries[index] : prototypeState?.angledFlagCountry?.flagA ?? "GBR",
flagB: flag === "flagB" ? flagList[index] : prototypeState?.angledFlag?.flagB ?? "GBR", flagB: flag === "flagB" ? countries[index] : prototypeState?.angledFlagCountry?.flagB ?? "GBR",
}, },
})); }));
} else if (flagMode === "team") {
dispatch(setPrototypeState({
angledFlagTeam: {
flagA: flag === "flagA" ? teams[index] : prototypeState?.angledFlagTeam?.flagA ?? "alpine",
flagB: flag === "flagB" ? teams[index] : prototypeState?.angledFlagTeam?.flagB ?? "alpine",
},
}));
}
}; };
return ( return (
<Split as={PadBox} gutter="md" padding="md"> <Split as={PadBox} gutter="md" padding="md">
+64
View File
@@ -1,5 +1,6 @@
import { theme } from "../../shared/theme"; import { theme } from "../../shared/theme";
import { Driver, Team } from "../../types/state"; import { Driver, Team } from "../../types/state";
import { Percent } from "../../types/style";
import { repeater } from "../../utils/strings"; import { repeater } from "../../utils/strings";
/** /**
@@ -418,3 +419,66 @@ export const teamNumberStyles: { [teamId: string]: NumberStyle } = {
], ],
}, },
}; };
export type TeamFlagStyle = {
backgroundColor?: string,
backgroundImage?: string,
imageSize: Percent,
imagePos: {
x: Percent,
y: Percent,
},
};
export const teamFlagStyles: { [teamId: string]: TeamFlagStyle } = {
alpine: {
backgroundColor: "black",
imageSize: 50,
imagePos: { x: 50, y: 50 },
},
alfaRomeo: {
backgroundColor: "black",
imageSize: 50,
imagePos: { x: 50, y: 50 },
},
alphaTauri: {
backgroundColor: "black",
imageSize: 50,
imagePos: { x: 50, y: 50 },
},
astonMartin: {
backgroundColor: "black",
imageSize: 50,
imagePos: { x: 50, y: 50 },
},
haas: {
backgroundColor: "black",
imageSize: 50,
imagePos: { x: 50, y: 50 },
},
ferrari: {
backgroundColor: "#dc0000",
imageSize: 55,
imagePos: { x: 80, y: -40 },
},
mclaren: {
backgroundColor: "black",
imageSize: 50,
imagePos: { x: 50, y: 50 },
},
mercedes: {
backgroundColor: "black",
imageSize: 50,
imagePos: { x: 50, y: 50 },
},
redBull: {
backgroundColor: "black",
imageSize: 50,
imagePos: { x: 50, y: 50 },
},
williams: {
backgroundColor: "black",
imageSize: 50,
imagePos: { x: 50, y: 50 },
},
};
+5 -1
View File
@@ -32,10 +32,14 @@ export interface WorkspaceProperties {
previewWindowDimensions: Dimensions; previewWindowDimensions: Dimensions;
} }
export interface PrototypeState { export interface PrototypeState {
angledFlag?: { angledFlagCountry?: {
flagA: string; flagA: string;
flagB: string; flagB: string;
}; };
angledFlagTeam?: {
flagA: TeamId;
flagB: TeamId;
};
} }
// Overlay Tool // Overlay Tool
+5
View File
@@ -2,3 +2,8 @@
* Type to remind you that we're dealing with pixels. * Type to remind you that we're dealing with pixels.
*/ */
export type Px = number; export type Px = number;
/**
* Type to remind you that we're dealing with percentages.
*/
export type Percent = number;
+10 -7
View File
@@ -1,6 +1,6 @@
import { cloneDeep } from "lodash"; import { cloneDeep } from "lodash";
import { drivers, teams, teamNumberStyles, NumberStyle } from "../domain/data/teams"; import { drivers, teams, teamNumberStyles, teamFlagStyles } from "../domain/data/teams";
import { Driver, DriverId, Team, TeamId } from "../types/state"; import { DriverId, TeamId } from "../types/state";
/** /**
* Prefer getting data from teams.ts through these simple getter functions. * Prefer getting data from teams.ts through these simple getter functions.
@@ -9,20 +9,23 @@ import { Driver, DriverId, Team, TeamId } from "../types/state";
* situation I wouldn't be able to normally * situation I wouldn't be able to normally
*/ */
export function getDriver(driverId: DriverId): Driver { export function getDriver(driverId: DriverId) {
return drivers[driverId]; return drivers[driverId];
} }
export function cloneDriver(driverId: DriverId): Driver { export function cloneDriver(driverId: DriverId) {
return cloneDeep(drivers[driverId]); return cloneDeep(drivers[driverId]);
} }
export function getTeam(teamId: TeamId): Team { export function getTeam(teamId: TeamId) {
return teams[teamId]; return teams[teamId];
} }
export function cloneTeam(teamId: TeamId): Team { export function cloneTeam(teamId: TeamId) {
return cloneDeep(teams[teamId]); return cloneDeep(teams[teamId]);
} }
export function getTeamNumberStyle(teamId: TeamId): NumberStyle { export function getTeamNumberStyle(teamId: TeamId) {
return teamNumberStyles[teamId]; return teamNumberStyles[teamId];
} }
export function getTeamFlagStyle(teamId: TeamId) {
return teamFlagStyles[teamId];
}