ISSUE-075 - Switched to using GridSpots for the SelectedCars state.
Chyrons still show out-of-date information, though. Might need to do some refactoring to get this straightened.
This commit is contained in:
1 parent
bf89bc96dc
commit
d9b30f64f2
6 files changed
+44
-50
No files matched your search
@@ -7,6 +7,7 @@ import { FaCheck, FaStepForward, FaTimes } from "react-icons/fa";
|
|||||||
|
|
||||||
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
|
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
|
||||||
import { broadcastDirectorSelector } from "../../../../features/broadcast/director/broadcastDirectorSelector";
|
import { broadcastDirectorSelector } from "../../../../features/broadcast/director/broadcastDirectorSelector";
|
||||||
|
import { eventSelector } from "../../../../features/event/eventSelector";
|
||||||
import {
|
import {
|
||||||
incrementChyronsOpenState,
|
incrementChyronsOpenState,
|
||||||
setChyrons,
|
setChyrons,
|
||||||
@@ -36,6 +37,7 @@ export function ChyronsDirectorControls() {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { chyrons } = useSelector(broadcastGraphicsSelector);
|
const { chyrons } = useSelector(broadcastGraphicsSelector);
|
||||||
const { selectedCars } = useSelector(broadcastDirectorSelector);
|
const { selectedCars } = useSelector(broadcastDirectorSelector);
|
||||||
|
const { grid } = useSelector(eventSelector);
|
||||||
|
|
||||||
// Handle changes to the chyron mode so submodes can be changed accordingly.
|
// Handle changes to the chyron mode so submodes can be changed accordingly.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -60,14 +62,14 @@ export function ChyronsDirectorControls() {
|
|||||||
|
|
||||||
const buildDriver = () => {
|
const buildDriver = () => {
|
||||||
if (selectedCars.length === 0) return;
|
if (selectedCars.length === 0) return;
|
||||||
let primaryCar = selectedCars[0];
|
let primaryCar = grid[selectedCars[0]];
|
||||||
let secondaryCar = selectedCars.length > 1 ? selectedCars[1] : null;
|
let secondaryCar = selectedCars.length > 1 ? grid[selectedCars[1]] : null;
|
||||||
|
|
||||||
// Auto-sort drivers by position so trailing car always appears second.
|
// Auto-sort drivers by position so trailing car always appears second.
|
||||||
if (chyronSubMode === "medium" && secondaryCar != null
|
if (chyronSubMode === "medium" && secondaryCar != null
|
||||||
&& secondaryCar.position < primaryCar.position) {
|
&& secondaryCar.position < primaryCar.position) {
|
||||||
secondaryCar = selectedCars[0];
|
secondaryCar = grid[selectedCars[0]];
|
||||||
primaryCar = selectedCars[1];
|
primaryCar = grid[selectedCars[1]];
|
||||||
}
|
}
|
||||||
const newChyrons: BGChyrons = {
|
const newChyrons: BGChyrons = {
|
||||||
openState: 0,
|
openState: 0,
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { InlineCluster } from "@bedrock-layout/inline-cluster";
|
import { InlineCluster } from "@bedrock-layout/inline-cluster";
|
||||||
import { findIndex } from "lodash";
|
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
import { broadcastDirectorSelector } from "../../../../features/broadcast/director/broadcastDirectorSelector";
|
import { broadcastDirectorSelector } from "../../../../features/broadcast/director/broadcastDirectorSelector";
|
||||||
import { pushSelectedCars, clearSelectedCars, removeSelectedCars } from "../../../../features/broadcast/director/broadcastDirectorSlice";
|
import { pushSelectedCars, clearSelectedCars, removeSelectedCars } from "../../../../features/broadcast/director/broadcastDirectorSlice";
|
||||||
import { eventSelector } from "../../../../features/event/eventSelector";
|
import { eventSelector } from "../../../../features/event/eventSelector";
|
||||||
import { Car } from "../../../../types/state";
|
import { GridSpot } from "../../../../types/state";
|
||||||
import { carMatch } from "../../../../utils/comparators";
|
|
||||||
|
|
||||||
import { DriverLabel, GridItem, SelectionLabel } from "./styles";
|
import { DriverLabel, GridItem, SelectionLabel } from "./styles";
|
||||||
|
|
||||||
@@ -19,24 +17,24 @@ export function GridSelection() {
|
|||||||
selectedCars,
|
selectedCars,
|
||||||
} = useSelector(broadcastDirectorSelector);
|
} = useSelector(broadcastDirectorSelector);
|
||||||
|
|
||||||
const carClick = (car: Car, selected: boolean) => () => {
|
const carClick = (gridSpot: GridSpot, selected: boolean) => () => {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
dispatch(removeSelectedCars(car));
|
dispatch(removeSelectedCars(gridSpot));
|
||||||
} else {
|
} else {
|
||||||
dispatch(pushSelectedCars(car));
|
dispatch(pushSelectedCars(gridSpot));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const carDoubleClick = (car: Car) => () => {
|
const carDoubleClick = (gridSpot: GridSpot) => () => {
|
||||||
dispatch(clearSelectedCars(car));
|
dispatch(clearSelectedCars(gridSpot));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InlineCluster gutter="xs">
|
<InlineCluster gutter="xs">
|
||||||
{grid.map(car => {
|
{grid.map((car, gridSpot) => {
|
||||||
const selectedIndex = findIndex(selectedCars, carMatch(car));
|
const selectedIndex = selectedCars.findIndex(g => g === gridSpot);
|
||||||
const selected = selectedIndex !== -1;
|
const selected = selectedIndex !== -1;
|
||||||
const onClick = carClick(car, selected);
|
const onClick = carClick(gridSpot, selected);
|
||||||
const onDoubleClick = carDoubleClick(car);
|
const onDoubleClick = carDoubleClick(gridSpot);
|
||||||
return (
|
return (
|
||||||
<GridItem
|
<GridItem
|
||||||
key={car.driver.id}
|
key={car.driver.id}
|
||||||
|
|||||||
+5
-5
@@ -32,7 +32,7 @@ export function TimingTowerPrototypeControls() {
|
|||||||
<ClickSpan
|
<ClickSpan
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch(increaseDistance({
|
dispatch(increaseDistance({
|
||||||
cars: selectedCars,
|
gridSpots: selectedCars,
|
||||||
distance: 200,
|
distance: 200,
|
||||||
randomness: 0,
|
randomness: 0,
|
||||||
usePerformance: false,
|
usePerformance: false,
|
||||||
@@ -45,7 +45,7 @@ export function TimingTowerPrototypeControls() {
|
|||||||
<ClickSpan
|
<ClickSpan
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch(increaseDistance({
|
dispatch(increaseDistance({
|
||||||
cars: grid,
|
gridSpots: Array.from(Array(grid.length).keys()),
|
||||||
distance: 100,
|
distance: 100,
|
||||||
randomness: 0.05,
|
randomness: 0.05,
|
||||||
usePerformance: true,
|
usePerformance: true,
|
||||||
@@ -58,7 +58,7 @@ export function TimingTowerPrototypeControls() {
|
|||||||
<ClickSpan
|
<ClickSpan
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch(increaseDistance({
|
dispatch(increaseDistance({
|
||||||
cars: grid,
|
gridSpots: Array.from(Array(grid.length).keys()),
|
||||||
distance: 1000,
|
distance: 1000,
|
||||||
randomness: 0.05,
|
randomness: 0.05,
|
||||||
usePerformance: true,
|
usePerformance: true,
|
||||||
@@ -71,7 +71,7 @@ export function TimingTowerPrototypeControls() {
|
|||||||
<ClickSpan
|
<ClickSpan
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch(setCarStatus({
|
dispatch(setCarStatus({
|
||||||
cars: selectedCars,
|
gridSpots: selectedCars,
|
||||||
status: CarStatus.Retired,
|
status: CarStatus.Retired,
|
||||||
}));
|
}));
|
||||||
dispatch(refreshRunningOrder());
|
dispatch(refreshRunningOrder());
|
||||||
@@ -82,7 +82,7 @@ export function TimingTowerPrototypeControls() {
|
|||||||
<ClickSpan
|
<ClickSpan
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch(setCarStatus({
|
dispatch(setCarStatus({
|
||||||
cars: selectedCars,
|
gridSpots: selectedCars,
|
||||||
status: CarStatus.Normal,
|
status: CarStatus.Normal,
|
||||||
}));
|
}));
|
||||||
dispatch(refreshRunningOrder());
|
dispatch(refreshRunningOrder());
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||||
import { findIndex } from "lodash";
|
|
||||||
|
|
||||||
import { RootState, Car } from "../../../types/state";
|
import { RootState, GridSpot } from "../../../types/state";
|
||||||
import { Optional } from "../../../types/util";
|
import { Optional } from "../../../types/util";
|
||||||
import { carMatch } from "../../../utils/comparators";
|
|
||||||
|
|
||||||
const initialState: RootState["broadcastDirector"] = {
|
const initialState: RootState["broadcastDirector"] = {
|
||||||
selectedCars: [],
|
selectedCars: [],
|
||||||
@@ -13,22 +11,16 @@ export const broadcastDirectorSlice = createSlice({
|
|||||||
name: "broadcastDirector",
|
name: "broadcastDirector",
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
pushSelectedCars: (state, action: PayloadAction<Car>) => {
|
pushSelectedCars: (state, action: PayloadAction<GridSpot>) => {
|
||||||
const index = findIndex(state.selectedCars, carMatch(action.payload));
|
if (!state.selectedCars.includes(action.payload)) {
|
||||||
if (index === -1) {
|
state.selectedCars.push(action.payload);
|
||||||
state.selectedCars = state.selectedCars.concat(action.payload);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setSelectedCars: (state, action: PayloadAction<Car>) => { // Might be removed.
|
setSelectedCars: (state, action: PayloadAction<GridSpot>) => { // Might be removed.
|
||||||
state.selectedCars = [action.payload];
|
state.selectedCars = [action.payload];
|
||||||
},
|
},
|
||||||
removeSelectedCars: (state, action: PayloadAction<Car | number>) => {
|
removeSelectedCars: (state, action: PayloadAction<GridSpot>) => {
|
||||||
const index = typeof action.payload === "number"
|
state.selectedCars = state.selectedCars.filter(grid => grid !== action.payload);
|
||||||
? action.payload
|
|
||||||
: findIndex(state.selectedCars, carMatch(action.payload));
|
|
||||||
state.selectedCars = state.selectedCars.slice(0, index).concat(
|
|
||||||
state.selectedCars.slice(index + 1),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@@ -36,7 +28,7 @@ export const broadcastDirectorSlice = createSlice({
|
|||||||
* car.
|
* car.
|
||||||
* @param action Car (optional)
|
* @param action Car (optional)
|
||||||
*/
|
*/
|
||||||
clearSelectedCars: (state, action: PayloadAction<Optional<Car>>) => {
|
clearSelectedCars: (state, action: PayloadAction<Optional<GridSpot>>) => {
|
||||||
if (action.payload == null) {
|
if (action.payload == null) {
|
||||||
state.selectedCars = [];
|
state.selectedCars = [];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
SectorFlag,
|
SectorFlag,
|
||||||
SafetyCarStatus,
|
SafetyCarStatus,
|
||||||
VirtualSafetyCarStatus,
|
VirtualSafetyCarStatus,
|
||||||
Car,
|
GridSpot,
|
||||||
} from "../../types/state";
|
} from "../../types/state";
|
||||||
import { Meters } from "../../types/util";
|
import { Meters } from "../../types/util";
|
||||||
import { orMatch } from "../../utils/common";
|
import { orMatch } from "../../utils/common";
|
||||||
@@ -211,14 +211,14 @@ const initialState: RootState["event"] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface IncreaseDistanceAction {
|
interface IncreaseDistanceAction {
|
||||||
cars: Car[];
|
gridSpots: GridSpot[];
|
||||||
distance: Meters;
|
distance: Meters;
|
||||||
randomness: number;
|
randomness: number;
|
||||||
usePerformance: boolean;
|
usePerformance: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SetCarStatusAction {
|
interface SetCarStatusAction {
|
||||||
cars: Car[];
|
gridSpots: GridSpot[];
|
||||||
status: CarStatus;
|
status: CarStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,9 +267,11 @@ export const eventSlice = createSlice({
|
|||||||
increaseDistance: (state, action: PayloadAction<IncreaseDistanceAction>) => {
|
increaseDistance: (state, action: PayloadAction<IncreaseDistanceAction>) => {
|
||||||
const gridMap = driverToGridMap(state.grid);
|
const gridMap = driverToGridMap(state.grid);
|
||||||
|
|
||||||
const { cars, distance, randomness, usePerformance } = action.payload;
|
const { gridSpots, distance, randomness, usePerformance } = action.payload;
|
||||||
|
|
||||||
|
gridSpots.forEach(gridSpot => {
|
||||||
|
const car = state.grid[gridSpot];
|
||||||
|
|
||||||
cars.forEach(car => {
|
|
||||||
// Do not update cars that are DNS, retired, or finished.
|
// Do not update cars that are DNS, retired, or finished.
|
||||||
// This does remind me that Finished cars must be treated and reported
|
// This does remind me that Finished cars must be treated and reported
|
||||||
// differently...
|
// differently...
|
||||||
@@ -289,13 +291,13 @@ export const eventSlice = createSlice({
|
|||||||
});
|
});
|
||||||
state.lastUpdate = Date.now();
|
state.lastUpdate = Date.now();
|
||||||
},
|
},
|
||||||
awardFastestLap: (state, action: PayloadAction<Car>) => {
|
awardFastestLap: (state, action: PayloadAction<GridSpot>) => {
|
||||||
// Awards fastest lap to provided car. Removes fastest lap from anyone else.
|
// Awards fastest lap to provided car. Removes fastest lap from anyone else.
|
||||||
state.grid.forEach((car, index) => {
|
state.grid.forEach((car, index) => {
|
||||||
const fastestLapNoticeIndex = car.notices.findIndex(
|
const fastestLapNoticeIndex = car.notices.findIndex(
|
||||||
notice => notice === CarNotice.FastestLap,
|
notice => notice === CarNotice.FastestLap,
|
||||||
);
|
);
|
||||||
if (car.driver.id === action.payload.driver.id) {
|
if (car.driver.id === state.grid[action.payload].driver.id) {
|
||||||
if (fastestLapNoticeIndex === -1) {
|
if (fastestLapNoticeIndex === -1) {
|
||||||
state.grid[index].notices.push(CarNotice.FastestLap);
|
state.grid[index].notices.push(CarNotice.FastestLap);
|
||||||
}
|
}
|
||||||
@@ -307,8 +309,9 @@ export const eventSlice = createSlice({
|
|||||||
},
|
},
|
||||||
setCarStatus: (state, action: PayloadAction<SetCarStatusAction>) => {
|
setCarStatus: (state, action: PayloadAction<SetCarStatusAction>) => {
|
||||||
const gridMap = driverToGridMap(state.grid);
|
const gridMap = driverToGridMap(state.grid);
|
||||||
const { cars, status } = action.payload;
|
const { gridSpots, status } = action.payload;
|
||||||
cars.forEach(car => {
|
gridSpots.forEach(gridSpot => {
|
||||||
|
const car = state.grid[gridSpot];
|
||||||
state.grid[gridMap[car.driver.id]].status = status;
|
state.grid[gridMap[car.driver.id]].status = status;
|
||||||
});
|
});
|
||||||
state.lastUpdate = Date.now();
|
state.lastUpdate = Date.now();
|
||||||
|
|||||||
+3
-4
@@ -1,5 +1,5 @@
|
|||||||
import { Meters, Milliseconds, Optional } from "./util";
|
import { Meters, Milliseconds, Optional } from "./util";
|
||||||
import { Corner, Fraction, Placement } from "./style";
|
import { Corner, Fraction } from "./style";
|
||||||
|
|
||||||
export interface RootState {
|
export interface RootState {
|
||||||
pageDimensions: PageDimensions;
|
pageDimensions: PageDimensions;
|
||||||
@@ -76,7 +76,6 @@ export interface Event {
|
|||||||
progress: EventProgress;
|
progress: EventProgress;
|
||||||
leaderGridSpot: GridSpot; // Might be removed.
|
leaderGridSpot: GridSpot; // Might be removed.
|
||||||
grid: Grid;
|
grid: Grid;
|
||||||
// gridPositions: GridSpot[];
|
|
||||||
lastUpdate: number;
|
lastUpdate: number;
|
||||||
}
|
}
|
||||||
export interface EventProgress {
|
export interface EventProgress {
|
||||||
@@ -120,7 +119,7 @@ export enum SectorFlag {
|
|||||||
export enum SafetyCarStatus { Clear, Starting, Out, Ending }
|
export enum SafetyCarStatus { Clear, Starting, Out, Ending }
|
||||||
export enum VirtualSafetyCarStatus { Clear, Active, Ending }
|
export enum VirtualSafetyCarStatus { Clear, Active, Ending }
|
||||||
export type Grid = Car[]; // Grid order does not change.
|
export type Grid = Car[]; // Grid order does not change.
|
||||||
export type GridSpot = number;
|
export type GridSpot = number; // GridSpot doesn't change. Starts at 0.
|
||||||
export interface Car {
|
export interface Car {
|
||||||
position: number; // Position is DERIVED from distance and status.
|
position: number; // Position is DERIVED from distance and status.
|
||||||
driver: Driver;
|
driver: Driver;
|
||||||
@@ -249,7 +248,7 @@ export type TeamFullName =
|
|||||||
|
|
||||||
// Broadcast Director
|
// Broadcast Director
|
||||||
export interface BroadcastDirector {
|
export interface BroadcastDirector {
|
||||||
selectedCars: Car[];
|
selectedCars: GridSpot[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast Graphics
|
// Broadcast Graphics
|
||||||
|
|||||||
Reference in new issue
Block a user