ISSUE-032 - Have Chyron prototyping controls configured and hooked up.

Support for double driver chyrons.
Serious refactoring of the BroadcastGraphics states.
Simplification and improvements to how the chyron states work (I was using interfaces in a way that was incompatible with reality and have fixed it).
This commit is contained in:
Kyle Geib committed 2022-01-31 18:24:25 -05:00
1 parent d5b653da9d
commit 0625361a18
16 files changed
+201 -92

No files matched your search

@@ -1,18 +1,23 @@
import { InlineCluster } from "@bedrock-layout/inline-cluster"; import { InlineCluster } from "@bedrock-layout/inline-cluster";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { FaPlay, FaStepForward, FaStop } from "react-icons/fa";
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
import { flagModeList, getChyronModesList, getChyronSubModesList } from "../../../../domain/data/broadcastGraphics";
import { BGChyronMode, BGChyronSubMode, FlagMode } from "../../../../types/state";
import { SlotSelector } from "../../../Common/Inputs/SlotSelector";
import { Button, CloseButton, OpenButton, SlotContainer, Title } from "./styles";
import { Toggle } from "../../../Common/Inputs/Toggle";
import { Stack } from "@bedrock-layout/stack"; import { Stack } from "@bedrock-layout/stack";
import { Inline } from "@bedrock-layout/inline"; import { Inline } from "@bedrock-layout/inline";
import { FaPlay, FaStepForward, FaStop } from "react-icons/fa";
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
import { broadcastDirectorSelector } from "../../../../features/broadcast/director/broadcastDirectorSelector";
import {
chyronsClear,
chyronsOpenStateIncrement,
chyronsSet,
} from "../../../../features/broadcast/graphics/broadcastGraphicsSlice";
import { flagModeList, getChyronModesList, getChyronSubModesList } from "../../../../domain/data/broadcastGraphics";
import { BGChyronDriver, BGChyronMode, BGChyrons, BGChyronSubMode, Car, FlagMode } from "../../../../types/state";
import { SlotSelector } from "../../../Common/Inputs/SlotSelector";
import { Button, CloseButton, OpenButton, Title } from "./styles";
import { Toggle } from "../../../Common/Inputs/Toggle";
export function ChyronsDirectorControls() { export function ChyronsDirectorControls() {
// Use state to prevent unnecessary resetting on re-renders. // Use state to prevent unnecessary resetting on re-renders.
@@ -27,28 +32,60 @@ export function ChyronsDirectorControls() {
const [portrait, setPortrait] = useState(false); const [portrait, setPortrait] = useState(false);
const [flagMode, setFlagMode] = useState<FlagMode>("country"); const [flagMode, setFlagMode] = useState<FlagMode>("country");
// Central state.
const dispatch = useDispatch(); const dispatch = useDispatch();
const { chyrons } = useSelector(broadcastGraphicsSelector); const { chyrons } = useSelector(broadcastGraphicsSelector);
const { selectedCars } = useSelector(broadcastDirectorSelector);
useEffect(() => { useEffect(() => {
setChyronSubModes(getChyronSubModesList(chyronMode)); setChyronSubModes(getChyronSubModesList(chyronMode));
}, [chyronMode]); }, [chyronMode]);
const onLaunch = () => { const onOpen = () => {
const x = 0; if (chyronMode === "driver") {
return x; if (selectedCars.length === 0) return;
}; let primaryCar = selectedCars[0];
let secondaryCar = selectedCars.length > 1 ? selectedCars[1] : null;
const controlSelector = (mode: BGChyronMode, subMode: BGChyronSubMode) => { // Auto-sort drivers by position so trailing car always appears second.
if (mode === "driver") { if (chyronSubMode === "medium" && secondaryCar != null
return driverMode(subMode); && secondaryCar.position < primaryCar.position) {
} else { secondaryCar = selectedCars[0];
return null; primaryCar = selectedCars[1];
}
const newChyrons: BGChyrons = {
openState: 1,
relativePos: { top: "0", right: "0", bottom: "0", left: "0" },
mode: chyronMode,
subMode: chyronSubMode,
driver: {
primary: buildDriverChyron(primaryCar),
secondary: secondaryCar != null ? buildDriverChyron(secondaryCar) : null,
},
};
dispatch(chyronsSet(newChyrons));
} }
}; };
const driverMode = (subMode: BGChyronSubMode) => ( const onNext = () => {
dispatch(chyronsOpenStateIncrement());
};
const onClose = () => {
dispatch(chyronsClear());
};
const buildDriverChyron = (car: Car): BGChyronDriver => ({
car,
flagMode,
showPosFlag: posFlag,
showDriverNumber: driverNum,
showPortrait: chyronSubMode === "large" ? false : portrait,
});
const modeControls = (mode: BGChyronMode, subMode: BGChyronSubMode) => {
if (mode === "driver") {
return (
<InlineCluster gutter="md"> <InlineCluster gutter="md">
<Toggle <Toggle
label="Pos. Flag" label="Pos. Flag"
@@ -75,6 +112,10 @@ export function ChyronsDirectorControls() {
/> />
</InlineCluster> </InlineCluster>
); );
} else {
return null;
}
};
return ( return (
<Stack gutter="md"> <Stack gutter="md">
@@ -92,23 +133,26 @@ export function ChyronsDirectorControls() {
</Inline> </Inline>
<Inline gutter="sm"> <Inline gutter="sm">
<OpenButton <OpenButton
disabled={false} onClick={onOpen}
disabled={chyrons != null}
> >
<FaPlay size="0.8em" /> <FaPlay size="0.8em" />
</OpenButton> </OpenButton>
<Button <Button
disabled={false} onClick={onNext}
disabled={chyrons == null}
> >
<FaStepForward size="0.8em" /> <FaStepForward size="0.8em" />
</Button> </Button>
<CloseButton <CloseButton
disabled={false} onClick={onClose}
disabled={chyrons == null}
> >
<FaStop size="0.8em" /> <FaStop size="0.8em" />
</CloseButton> </CloseButton>
</Inline> </Inline>
</Inline> </Inline>
{controlSelector(chyronMode, chyronSubMode)} {modeControls(chyronMode, chyronSubMode)}
</Stack> </Stack>
); );
} }
@@ -1,19 +1,10 @@
import styled from "styled-components"; import styled from "styled-components";
import { Px } from "../../../../types/style";
export const Title = styled.h4` export const Title = styled.h4`
font-family: ${p => p.theme.fonts.f1Italic}; font-family: ${p => p.theme.fonts.f1Italic};
`; `;
Title.displayName = "Title"; Title.displayName = "Title";
type SlotContainerProps = {
width: Px,
};
export const SlotContainer = styled.div<SlotContainerProps>`
width: ${({ width }) => `${width}px`};
`;
SlotContainer.displayName = "SlotContainer";
type ButtonProps = { type ButtonProps = {
disabled: boolean, disabled: boolean,
}; };
@@ -27,6 +18,13 @@ export const Button = styled.button<ButtonProps>`
border: 1px black solid; border: 1px black solid;
cursor: pointer; cursor: pointer;
&:hover {
box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, 0.3);
}
&:active {
box-shadow: inset 0px 0px 10px 4px rgba(255, 255, 255, 0.8);
}
`; `;
Button.displayName = "Button"; Button.displayName = "Button";
@@ -0,0 +1,32 @@
import { Inline } from "@bedrock-layout/inline";
import { useSelector } from "react-redux";
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
import { ChyronDriver } from "../Driver";
import { Spacer } from "./styles";
export function ChyronContainer() {
const { chyrons } = useSelector(broadcastGraphicsSelector);
if (chyrons == null || chyrons.driver == null) return null;
return (
<Inline gutter="none">
<ChyronDriver
chyronData={chyrons.driver.primary}
subMode={chyrons.subMode}
/>
{chyrons.subMode == "medium" && chyrons.driver.secondary && (
<>
<Spacer />
<ChyronDriver
chyronData={chyrons.driver.secondary}
subMode={chyrons.subMode}
/>
</>
)}
</Inline>
);
}
@@ -0,0 +1 @@
export * from "./ChyronContainer";
@@ -0,0 +1,6 @@
import styled from "styled-components";
export const Spacer = styled.div`
width: 32px;
`;
Spacer.displayName = "Spacer";
@@ -1,3 +1,7 @@
import { BGChyronDriver, BGChyronSubMode } from "../../../../types/state";
import { theme } from "../../../../shared/theme";
import { DriverNumber } from "../../Common/DriverNumber"; import { DriverNumber } from "../../Common/DriverNumber";
import { AngledFlag } from "../../Common/AngledFlag"; import { AngledFlag } from "../../Common/AngledFlag";
import { import {
@@ -14,37 +18,46 @@ import {
TextContainer, TextContainer,
FlagContainer, FlagContainer,
} from "./styles"; } from "./styles";
import { drivers } from "../../../../domain/data/teams";
import { theme } from "../../../../shared/theme";
export function ChyronDriver() { type ChyronDriverProps = {
// TODO - Get driver details from Redux. chyronData: BGChyronDriver,
const driver = drivers["hamilton"]; subMode: BGChyronSubMode,
const baseWidth = 582; };
const baseHeight = 72; export function ChyronDriver({ chyronData, subMode }: ChyronDriverProps) {
const [baseWidth, baseHeight] = subMode === "medium" ? [582, 72]
: subMode === "large" ? [638, 98]
: [0, 0];
const { car, flagMode, showPosFlag, showDriverNumber } = chyronData;
return ( return (
<BaseBackground width={baseWidth} height={baseHeight}> <BaseBackground width={baseWidth} height={baseHeight}>
<Spacer width="6px" /> <Spacer width="6px" />
{showPosFlag && (
<PositionFlag containerHeight={baseHeight}> <PositionFlag containerHeight={baseHeight}>
<PositionNumber containerHeight={baseHeight}>1</PositionNumber> <PositionNumber containerHeight={baseHeight}>
{car.position}
</PositionNumber>
</PositionFlag> </PositionFlag>
)}
<Spacer width="8px" /> <Spacer width="8px" />
<TeamColorBar color={theme.colors.teams[driver.team.id]} /> <TeamColorBar color={theme.colors.teams[car.driver.team.id]} />
<Spacer width="8px" /> <Spacer width="8px" />
<TextContainer> <TextContainer>
<NameContainer> <NameContainer>
<FirstName>{driver.firstName}</FirstName> <FirstName>{car.driver.firstName}</FirstName>
<LastName>{driver.lastName}</LastName> <LastName>{car.driver.lastName}</LastName>
{showDriverNumber && (
<NumberContainer> <NumberContainer>
<DriverNumber <DriverNumber
teamId={driver.team.id} teamId={car.driver.team.id}
fontSize="29px" fontSize="29px"
number={driver.number} number={car.driver.number}
/> />
</NumberContainer> </NumberContainer>
)}
</NameContainer> </NameContainer>
<TeamName>{driver.team.shortName}</TeamName> <TeamName>{car.driver.team.shortName}</TeamName>
</TextContainer> </TextContainer>
<FlagContainer <FlagContainer
height={baseHeight * 0.9} height={baseHeight * 0.9}
@@ -52,15 +65,11 @@ export function ChyronDriver() {
right={-baseHeight * 0.6} right={-baseHeight * 0.6}
> >
<AngledFlag <AngledFlag
flagMode="country" flagMode={flagMode}
flag={driver.nationality} flag={car.driver.nationality}
flagHeight={baseHeight * 0.9} flagHeight={baseHeight * 0.9}
/> />
</FlagContainer> </FlagContainer>
</BaseBackground> </BaseBackground>
); );
} }
// export function ChyronDriverStateContainer() {
// }
@@ -1,23 +1,26 @@
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 { AngledFlag } from "../../BroadcastGraphics/Common/AngledFlag"; import { AngledFlag } from "../../BroadcastGraphics/Common/AngledFlag";
import { BasicBlock } from "./styles"; import { BasicBlock } from "./styles";
type AngledFlagWorkSpaceProps = {
export function AngledFlagWorkSpace() { flagMode: FlagMode,
};
export function AngledFlagWorkSpace({ flagMode }: AngledFlagWorkSpaceProps) {
const { prototypeState } = useSelector(workspaceSelector); const { prototypeState } = useSelector(workspaceSelector);
return ( return (
<BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)"> <BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)">
<AngledFlag <AngledFlag
flagMode="country" flagMode={flagMode}
flag={prototypeState?.angledFlag?.flagA ?? "GBR"} flag={prototypeState?.angledFlag?.flagA ?? "GBR"}
flagHeight={64} flagHeight={64}
/> />
<AngledFlag <AngledFlag
flagMode="country" flagMode={flagMode}
flag={prototypeState?.angledFlag?.flagB ?? "GBR"} flag={prototypeState?.angledFlag?.flagB ?? "GBR"}
flagHeight={128} flagHeight={128}
/> />
@@ -26,8 +26,8 @@ export function AngledFlagPrototypeControls() {
}; };
return ( return (
<Split as={PadBox} gutter="md" padding="md"> <Split as={PadBox} gutter="md" padding="md">
<SlotSelector items={countries} onChange={onChange("flagA")}/> <SlotSelector label="64px" items={countries} onChange={onChange("flagA")}/>
<SlotSelector items={countries} onChange={onChange("flagB")}/> <SlotSelector label="128px" items={countries} onChange={onChange("flagB")}/>
</Split> </Split>
); );
} }
@@ -13,9 +13,7 @@ export type PreviewWindowProps = {
dimensions: Dimensions, dimensions: Dimensions,
animatedBG?: boolean, animatedBG?: boolean,
}; };
export const PreviewWindow = styled(PadBox).attrs(() => ({ export const PreviewWindow = styled.div<PreviewWindowProps>`
padding: "lg",
}))<PreviewWindowProps>`
position: relative; position: relative;
display: flex; display: flex;
justify-content: center; justify-content: center;
+14 -7
View File
@@ -11,10 +11,10 @@ import { WorkspaceList } from "./WorkspaceList";
import { LayoutGrid, LayoutGridItem } from "../Common/LayoutGrid.styled"; import { LayoutGrid, LayoutGridItem } from "../Common/LayoutGrid.styled";
import { Workspace } from "./Workspace"; import { Workspace } from "./Workspace";
import { ChyronDriver } from "../BroadcastGraphics/Chyrons/Driver";
import { ChyronPrototypeControls } from "./PrototypingControls/ChyronPrototype"; import { ChyronPrototypeControls } from "./PrototypingControls/ChyronPrototype";
import { AngledFlagWorkSpace } from "./CustomWorkSpaces/AngledFlagWorkSpace"; import { AngledFlagWorkSpace } from "./CustomWorkSpaces/AngledFlagWorkSpace";
import { AngledFlagPrototypeControls } from "./PrototypingControls/AngledFlagPrototype"; import { AngledFlagPrototypeControls } from "./PrototypingControls/AngledFlagPrototype";
import { ChyronContainer } from "../BroadcastGraphics/Chyrons/Container";
const WORKSPACE_LIST_WIDTH = 180; const WORKSPACE_LIST_WIDTH = 180;
@@ -49,17 +49,24 @@ export default function Workspaces() {
> >
<Routes> <Routes>
<Route index element={<h1>Workspaces Home</h1>} /> <Route index element={<h1>Workspaces Home</h1>} />
<Route path="chyronDriver" element={ <Route path="chyron" element={
<Workspace <Workspace
workspaceId="chyronDriver" workspaceId="chyron"
previewContent={<ChyronDriver />} previewContent={<ChyronContainer />}
prototypeControls={<ChyronPrototypeControls />} prototypeControls={<ChyronPrototypeControls />}
/> />
} /> } />
<Route path="angledFlag" element={ <Route path="chyronWide" element={
<Workspace <Workspace
workspaceId="angledFlag" workspaceId="chyronWide"
previewContent={<AngledFlagWorkSpace />} previewContent={<ChyronContainer />}
prototypeControls={<ChyronPrototypeControls />}
/>
} />
<Route path="angledFlagCountry" element={
<Workspace
workspaceId="angledFlagCountry"
previewContent={<AngledFlagWorkSpace flagMode="country"/>}
prototypeControls={<AngledFlagPrototypeControls />} prototypeControls={<AngledFlagPrototypeControls />}
/> />
} /> } />
+15 -5
View File
@@ -4,8 +4,8 @@ type WorkspaceObject = {
[id: WorkspaceId]: WorkspaceProperties, [id: WorkspaceId]: WorkspaceProperties,
}; };
export const workspaces: WorkspaceObject = { export const workspaces: WorkspaceObject = {
chyronDriver: { chyron: {
name: "Chyron Driver", name: "Chyron",
overlayIds: [ overlayIds: [
"chyron-driver-medium-full-ham.png", "chyron-driver-medium-full-ham.png",
"chyron-driver-medium-full-alo.png", "chyron-driver-medium-full-alo.png",
@@ -24,11 +24,21 @@ export const workspaces: WorkspaceObject = {
], ],
previewWindowDimensions: { previewWindowDimensions: {
width: 750, width: 750,
height: 300, height: 400,
}, },
}, },
angledFlag: { chyronWide: {
name: "Angled Flag", name: "Chyron (Wide)",
overlayIds: [
"chyron-driver-medium-full-sai-ric.png",
],
previewWindowDimensions: {
width: 1200,
height: 150,
},
},
angledFlagCountry: {
name: "Angled Flag (Country)",
overlayIds: [ overlayIds: [
"angled-flag-gbr.png", "angled-flag-gbr.png",
], ],
@@ -32,7 +32,9 @@ export const broadcastDirectorSlice = createSlice({
}, },
/** /**
* Shortcut to clear out selected cars. There is also a trick - if you * Shortcut to clear out selected cars. There is also a trick - if you
* @param action Car (optional) - if provided, it'll clear all and add this. * provide a single Car it'll replace all selected cars with that single
* car.
* @param action Car (optional)
*/ */
selectedCarsClear: (state, action: PayloadAction<Optional<Car>>) => { selectedCarsClear: (state, action: PayloadAction<Optional<Car>>) => {
if (action.payload == null) { if (action.payload == null) {
@@ -10,23 +10,23 @@ export const broadcastGraphicsSlice = createSlice({
name: "broadcastGraphics", name: "broadcastGraphics",
initialState, initialState,
reducers: { reducers: {
chyronsLaunch: (state, action: PayloadAction<BGChyrons>) => { chyronsSet: (state, action: PayloadAction<BGChyrons>) => {
state.chyrons = action.payload; state.chyrons = action.payload;
}, },
chyronsOpenStateSet: (state, action: PayloadAction<OpenState>) => { chyronsOpenStateSet: (state, action: PayloadAction<OpenState>) => {
if (state.chyrons == null) return; if (state.chyrons == null) return;
state.chyrons.primary.openState = action.payload; state.chyrons.openState = action.payload;
if (state.chyrons.secondary != null) { if (state.chyrons != null) {
state.chyrons.secondary.openState = action.payload; state.chyrons.openState = action.payload;
} }
}, },
chyronsOpenStateIncrement: (state) => { chyronsOpenStateIncrement: (state) => {
if (state.chyrons == null) return; if (state.chyrons == null) return;
++state.chyrons.primary.openState; ++state.chyrons.openState;
if (state.chyrons.secondary != null) { if (state.chyrons != null) {
++state.chyrons.secondary.openState; ++state.chyrons.openState;
} }
}, },
chyronsClear: (state) => { chyronsClear: (state) => {
@@ -36,7 +36,7 @@ export const broadcastGraphicsSlice = createSlice({
}); });
export const { export const {
chyronsLaunch, chyronsSet,
chyronsOpenStateSet, chyronsOpenStateSet,
chyronsOpenStateIncrement, chyronsOpenStateIncrement,
chyronsClear, chyronsClear,
+2 -2
View File
@@ -20,8 +20,8 @@ const initialState: RootState["event"] = {
}, },
grid: [ grid: [
{ position: 1, driver: cloneDriver("verstappen") }, { position: 1, driver: cloneDriver("verstappen") },
{ position: 3, driver: cloneDriver("hamilton") }, { position: 2, driver: cloneDriver("hamilton") },
{ position: 2, driver: cloneDriver("bottas") }, { position: 3, driver: cloneDriver("bottas") },
{ position: 4, driver: cloneDriver("perez") }, { position: 4, driver: cloneDriver("perez") },
{ position: 5, driver: cloneDriver("sainz") }, { position: 5, driver: cloneDriver("sainz") },
{ position: 6, driver: cloneDriver("norris") }, { position: 6, driver: cloneDriver("norris") },
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

+6 -7
View File
@@ -211,22 +211,21 @@ export interface BroadcastGraphics {
// Chyrons // Chyrons
export type BGChyronMode = string; export type BGChyronMode = string;
export type BGChyronSubMode = string; export type BGChyronSubMode = string;
export interface BGChyron extends BGBaseState { export interface BGChyrons extends BGBaseState {
mode: BGChyronMode; mode: BGChyronMode;
subMode: BGChyronSubMode;
driver?: {
primary: BGChyronDriver;
secondary: Optional<BGChyronDriver>;
} }
export interface BGChyrons {
primary: BGChyron;
secondary: Optional<BGChyron>;
// sponsorGem: BGSponsorGem; // sponsorGem: BGSponsorGem;
} }
export type FlagMode = "country" | "team" | "none";
export interface BGChyronDriver extends BGChyron { export interface BGChyronDriver extends BGChyron {
car: Car; car: Car;
subMode: BGChyronSubMode;
baseDimensions: Dimensions;
flagMode: FlagMode; flagMode: FlagMode;
showPosFlag: boolean; showPosFlag: boolean;
showDriverNumber: boolean; showDriverNumber: boolean;
showPortrait: boolean; showPortrait: boolean;
} }
export type FlagMode = "country" | "team" | "none";