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