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:
1 parent
57647f6488
commit
bd1892ab17
9 files changed
+231
-53
No files matched your search
@@ -29,6 +29,9 @@ export function ChyronDriver({ chyronData, subMode }: ChyronDriverProps) {
|
||||
: [0, 0];
|
||||
|
||||
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 (
|
||||
<BaseBackground width={baseWidth} height={baseHeight}>
|
||||
@@ -64,11 +67,12 @@ export function ChyronDriver({ chyronData, subMode }: ChyronDriverProps) {
|
||||
width={baseHeight * 3}
|
||||
right={-baseHeight * 0.6}
|
||||
>
|
||||
<AngledFlag
|
||||
flagMode={flagMode}
|
||||
flag={car.driver.nationality}
|
||||
flagHeight={baseHeight * 0.9}
|
||||
/>
|
||||
{flagProps != null && (
|
||||
<AngledFlag
|
||||
flagHeight={baseHeight * 0.9}
|
||||
flagProps={flagProps}
|
||||
/>
|
||||
)}
|
||||
</FlagContainer>
|
||||
</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 { getTeamFlagStyle } from "../../../../utils/dataLookup";
|
||||
import {
|
||||
Container,
|
||||
Slant,
|
||||
Sheen,
|
||||
CountryFlagEdge,
|
||||
FlagEdge,
|
||||
CountryFlagDiv,
|
||||
FlagContainer,
|
||||
TeamFlagDiv,
|
||||
} from "./styles";
|
||||
|
||||
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
|
||||
@@ -19,35 +22,67 @@ const countryFlags = require.context("../../../../public/images/countryFlags/ang
|
||||
* center.
|
||||
*/
|
||||
type AngledFlagProps = {
|
||||
flagMode: FlagMode,
|
||||
flag: string,
|
||||
flagHeight: Px,
|
||||
flagProps: {
|
||||
flagMode: "country",
|
||||
flag: string,
|
||||
} | {
|
||||
flagMode: "team",
|
||||
flag: TeamId,
|
||||
},
|
||||
};
|
||||
export function AngledFlag({ flagMode, flag, flagHeight }: AngledFlagProps) {
|
||||
const topFlag = flagMode === "country"
|
||||
? (
|
||||
export function AngledFlag(props: AngledFlagProps) {
|
||||
const { flagProps, flagHeight } = props;
|
||||
|
||||
let topFlag: ReactNode = null;
|
||||
let bottomFlag: ReactNode = null;
|
||||
|
||||
if (flagProps.flagMode === "country") {
|
||||
topFlag = (
|
||||
<CountryFlagDiv
|
||||
src={countryFlags(`./${flag}.svg`)}
|
||||
src={countryFlags(`./${flagProps.flag}.svg`)}
|
||||
height={flagHeight}
|
||||
width={flagHeight * 2}
|
||||
>
|
||||
<CountryFlagEdge
|
||||
<FlagEdge
|
||||
x={flagHeight / 2}
|
||||
height={flagHeight}
|
||||
girth={flagHeight * 0.07}
|
||||
/>
|
||||
</CountryFlagDiv>
|
||||
) : null; // Team flag here
|
||||
|
||||
const bottomFlag = flagMode === "country"
|
||||
? (
|
||||
);
|
||||
bottomFlag = (
|
||||
<CountryFlagDiv
|
||||
src={countryFlags(`./${flag}.svg`)}
|
||||
src={countryFlags(`./${flagProps.flag}.svg`)}
|
||||
height={flagHeight}
|
||||
width={flagHeight * 2}
|
||||
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 (
|
||||
<Container width={flagHeight * 6} height={flagHeight * 3}>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import styled, { css } from "styled-components";
|
||||
import { TeamFlagStyle } from "../../../../domain/data/teams";
|
||||
import { Px } from "../../../../types/style";
|
||||
|
||||
type ContainerProps = {
|
||||
@@ -68,24 +69,48 @@ export const FlagContainer = styled.div<FlagContainerProps>`
|
||||
`;
|
||||
FlagContainer.displayName = "FlagContainer";
|
||||
|
||||
type CountryFlagDivProps = {
|
||||
type FlagDivBaseProps = {
|
||||
src: string,
|
||||
height: Px,
|
||||
width: Px,
|
||||
xOffset?: Px,
|
||||
};
|
||||
export const CountryFlagDiv = styled.div<CountryFlagDivProps>`
|
||||
const FlagDivBase = styled.div<FlagDivBaseProps>`
|
||||
height: ${({ height }) => `${height}px`};
|
||||
width: ${({ width }) => `${width}px`};
|
||||
background-image: url(${({ src }) => src});
|
||||
background-size: ${({ width, height }) => `${width}px ${height}px`};
|
||||
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
|
||||
? css`background-position: center;`
|
||||
: css`background-position-x: ${xOffset}px`}
|
||||
`;
|
||||
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 = {
|
||||
x?: Px,
|
||||
height: Px,
|
||||
@@ -126,7 +151,7 @@ export const Slant = styled.div<SlashProps>`
|
||||
`;
|
||||
Slant.displayName = "Slant";
|
||||
|
||||
export const CountryFlagEdge = styled.div<SlashProps>`
|
||||
export const FlagEdge = styled.div<SlashProps>`
|
||||
position: absolute;
|
||||
height: ${({ height }) => `${height}px`};
|
||||
width: ${({ girth }) => `${girth}px`};
|
||||
@@ -142,4 +167,4 @@ export const CountryFlagEdge = styled.div<SlashProps>`
|
||||
black 100%
|
||||
);
|
||||
`;
|
||||
CountryFlagEdge.displayName = "CountryFlagEdge";
|
||||
FlagEdge.displayName = "FlagEdge";
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
|
||||
import { FlagMode } from "../../../types/state";
|
||||
import { FlagMode, TeamId } from "../../../types/state";
|
||||
|
||||
import { AngledFlag } from "../../BroadcastGraphics/Common/AngledFlag";
|
||||
import { BasicBlock } from "./styles";
|
||||
@@ -11,20 +11,48 @@ type AngledFlagWorkSpaceProps = {
|
||||
};
|
||||
export function AngledFlagWorkSpace({ flagMode }: AngledFlagWorkSpaceProps) {
|
||||
const { prototypeState } = useSelector(workspaceSelector);
|
||||
const defaultFlag = flagMode === "country" ? "GBR" : flagMode === "team" ? "alpine" : "";
|
||||
if (flagMode === "none") return null;
|
||||
|
||||
const defaultTeam: TeamId = "alpine";
|
||||
|
||||
return (
|
||||
<BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)">
|
||||
<AngledFlag
|
||||
flagMode={flagMode}
|
||||
flag={prototypeState?.angledFlag?.flagA ?? defaultFlag}
|
||||
flagHeight={64}
|
||||
/>
|
||||
<AngledFlag
|
||||
flagMode={flagMode}
|
||||
flag={prototypeState?.angledFlag?.flagB ?? defaultFlag}
|
||||
flagHeight={128}
|
||||
/>
|
||||
{flagMode === "country" ? (
|
||||
<>
|
||||
<AngledFlag
|
||||
flagProps={{
|
||||
flagMode,
|
||||
flag: prototypeState?.angledFlagCountry?.flagA ?? "GBR",
|
||||
}}
|
||||
flagHeight={64}
|
||||
/>
|
||||
<AngledFlag
|
||||
flagProps={{
|
||||
flagMode,
|
||||
flag: prototypeState?.angledFlagCountry?.flagB ?? "GBR",
|
||||
}}
|
||||
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>
|
||||
);
|
||||
}
|
||||
+16
-6
@@ -26,12 +26,22 @@ export function AngledFlagPrototypeControls({ flagMode }: AngledFlagPrototypeCon
|
||||
const flagList = flagMode === "country" ? countries : flagMode === "team" ? teams : [];
|
||||
|
||||
const onChange = (flag: "flagA" | "flagB") => (index: number) => {
|
||||
dispatch(setPrototypeState({
|
||||
angledFlag: {
|
||||
flagA: flag === "flagA" ? flagList[index] : prototypeState?.angledFlag?.flagA ?? "GBR",
|
||||
flagB: flag === "flagB" ? flagList[index] : prototypeState?.angledFlag?.flagB ?? "GBR",
|
||||
},
|
||||
}));
|
||||
if (flagMode === "country") {
|
||||
dispatch(setPrototypeState({
|
||||
angledFlagCountry: {
|
||||
flagA: flag === "flagA" ? countries[index] : prototypeState?.angledFlagCountry?.flagA ?? "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 (
|
||||
<Split as={PadBox} gutter="md" padding="md">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { theme } from "../../shared/theme";
|
||||
import { Driver, Team } from "../../types/state";
|
||||
import { Percent } from "../../types/style";
|
||||
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 },
|
||||
},
|
||||
};
|
||||
Vendored
+5
-1
@@ -32,10 +32,14 @@ export interface WorkspaceProperties {
|
||||
previewWindowDimensions: Dimensions;
|
||||
}
|
||||
export interface PrototypeState {
|
||||
angledFlag?: {
|
||||
angledFlagCountry?: {
|
||||
flagA: string;
|
||||
flagB: string;
|
||||
};
|
||||
angledFlagTeam?: {
|
||||
flagA: TeamId;
|
||||
flagB: TeamId;
|
||||
};
|
||||
}
|
||||
|
||||
// Overlay Tool
|
||||
|
||||
Vendored
+5
@@ -2,3 +2,8 @@
|
||||
* Type to remind you that we're dealing with pixels.
|
||||
*/
|
||||
export type Px = number;
|
||||
|
||||
/**
|
||||
* Type to remind you that we're dealing with percentages.
|
||||
*/
|
||||
export type Percent = number;
|
||||
+10
-7
@@ -1,6 +1,6 @@
|
||||
import { cloneDeep } from "lodash";
|
||||
import { drivers, teams, teamNumberStyles, NumberStyle } from "../domain/data/teams";
|
||||
import { Driver, DriverId, Team, TeamId } from "../types/state";
|
||||
import { drivers, teams, teamNumberStyles, teamFlagStyles } from "../domain/data/teams";
|
||||
import { DriverId, TeamId } from "../types/state";
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
export function getDriver(driverId: DriverId): Driver {
|
||||
export function getDriver(driverId: DriverId) {
|
||||
return drivers[driverId];
|
||||
}
|
||||
export function cloneDriver(driverId: DriverId): Driver {
|
||||
export function cloneDriver(driverId: DriverId) {
|
||||
return cloneDeep(drivers[driverId]);
|
||||
}
|
||||
|
||||
export function getTeam(teamId: TeamId): Team {
|
||||
export function getTeam(teamId: TeamId) {
|
||||
return teams[teamId];
|
||||
}
|
||||
export function cloneTeam(teamId: TeamId): Team {
|
||||
export function cloneTeam(teamId: TeamId) {
|
||||
return cloneDeep(teams[teamId]);
|
||||
}
|
||||
|
||||
export function getTeamNumberStyle(teamId: TeamId): NumberStyle {
|
||||
export function getTeamNumberStyle(teamId: TeamId) {
|
||||
return teamNumberStyles[teamId];
|
||||
}
|
||||
export function getTeamFlagStyle(teamId: TeamId) {
|
||||
return teamFlagStyles[teamId];
|
||||
}
|
||||
Reference in new issue
Block a user