ISSUE-054 - Added support for DidNotStart cars not taking up any space on the timing tower.
Fixed the bottom rounding functionality between running and retired cars in a reliable way. Relying more on car.position in the Timing Tower, as it should be.
This commit is contained in:
1 parent
c9388b86fc
commit
6e80ed056f
2 files changed
+40
-23
No files matched your search
@@ -40,42 +40,51 @@ export function TimingTower() {
|
|||||||
broadcastGraphicsSelector,
|
broadcastGraphicsSelector,
|
||||||
);
|
);
|
||||||
|
|
||||||
const [retiredCarsPresent, setRetiredCarsPresent] = useState(0);
|
const [startingCarsCount, setStartingCarsCount] = useState(0);
|
||||||
|
const [retiredCarsCount, setRetiredCarsCount] = useState(0);
|
||||||
const [rows, setRows] = useState<JSX.Element[]>([]);
|
const [rows, setRows] = useState<JSX.Element[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let anyRetired = 0;
|
// Filter away cars that are marked as not starting so they don't appear.
|
||||||
|
const startingGrid = grid.filter(car => car.status !== CarStatus.DidNotStart);
|
||||||
|
setStartingCarsCount(startingGrid.length);
|
||||||
|
|
||||||
setRows(grid.map((car, index, cars) => {
|
let retiredCount = 0;
|
||||||
|
startingGrid.forEach(car => {
|
||||||
if (car.status === CarStatus.Retired) {
|
if (car.status === CarStatus.Retired) {
|
||||||
++anyRetired;
|
++retiredCount;
|
||||||
}
|
}
|
||||||
return buildRow(car, index, cars.length);
|
});
|
||||||
}));
|
setRetiredCarsCount(retiredCount);
|
||||||
setRetiredCarsPresent(anyRetired);
|
|
||||||
|
setRows(startingGrid.map((car, index, grid) =>
|
||||||
|
buildRow(car, index, startingGrid.length, retiredCount)));
|
||||||
}, [lastUpdate, splitsMode]);
|
}, [lastUpdate, splitsMode]);
|
||||||
|
|
||||||
|
|
||||||
const buildRow = (
|
const buildRow = (
|
||||||
car: Car,
|
car: Car,
|
||||||
index: number,
|
index: number,
|
||||||
count: number,
|
startingCarsCount: number,
|
||||||
|
retiredCarsCount: number,
|
||||||
) => {
|
) => {
|
||||||
const lastRow = index + 1 === count;
|
const bottomRounded = car.status === CarStatus.Retired ? (
|
||||||
|
car.position === startingCarsCount
|
||||||
|
) : (
|
||||||
|
car.position === startingCarsCount - retiredCarsCount
|
||||||
|
);
|
||||||
|
|
||||||
let rightHalfContent = "";
|
let rightHalfContent = "";
|
||||||
let xScale: Fraction = 1.0;
|
let xScale: Fraction = 1.0;
|
||||||
let yScale: Fraction = 1.0;
|
let yScale: Fraction = 1.0;
|
||||||
|
|
||||||
if (index === leaderGridSpot) {
|
if (car.position === 1) {
|
||||||
// Leading car shows "Leader" or "Interval".
|
|
||||||
rightHalfContent = splitsMode === BGTimingTowerSplitsMode.Leader
|
rightHalfContent = splitsMode === BGTimingTowerSplitsMode.Leader
|
||||||
? "Leader" : splitsMode === BGTimingTowerSplitsMode.Interval
|
? "Leader" : splitsMode === BGTimingTowerSplitsMode.Interval
|
||||||
? "Interval" : "";
|
? "Interval" : "";
|
||||||
} else if (car.status === CarStatus.Retired) {
|
} else if (car.status === CarStatus.Retired) {
|
||||||
// Retired car shows "OUT".
|
|
||||||
rightHalfContent = "OUT";
|
rightHalfContent = "OUT";
|
||||||
} else {
|
} else {
|
||||||
// Other cars show gaps.
|
|
||||||
const deltaCar = getCarAtPos(
|
const deltaCar = getCarAtPos(
|
||||||
grid,
|
grid,
|
||||||
splitsMode === BGTimingTowerSplitsMode.Leader ? 1 : car.position - 1,
|
splitsMode === BGTimingTowerSplitsMode.Leader ? 1 : car.position - 1,
|
||||||
@@ -104,7 +113,7 @@ export function TimingTower() {
|
|||||||
)}
|
)}
|
||||||
<RowLeftHalf
|
<RowLeftHalf
|
||||||
roundedCornerBottom={
|
roundedCornerBottom={
|
||||||
lastRow && orMatch(
|
bottomRounded && orMatch(
|
||||||
timingTower.displayMode,
|
timingTower.displayMode,
|
||||||
BGTimingTowerDisplayModes.LeftOnly,
|
BGTimingTowerDisplayModes.LeftOnly,
|
||||||
BGTimingTowerDisplayModes.FullLeft,
|
BGTimingTowerDisplayModes.FullLeft,
|
||||||
@@ -128,12 +137,9 @@ export function TimingTower() {
|
|||||||
</RowLeftHalfGemContainer>
|
</RowLeftHalfGemContainer>
|
||||||
</RowLeftHalf>
|
</RowLeftHalf>
|
||||||
<RowRightHalf
|
<RowRightHalf
|
||||||
roundedCornerTop={
|
roundedCornerTop={car.position === 1 ? 5 : undefined}
|
||||||
index === 0 && car.status !== CarStatus.Retired
|
|
||||||
? 5 : undefined
|
|
||||||
}
|
|
||||||
roundedCornerBottom={
|
roundedCornerBottom={
|
||||||
lastRow && orMatch(
|
bottomRounded && orMatch(
|
||||||
timingTower.splitsMode,
|
timingTower.splitsMode,
|
||||||
BGTimingTowerSplitsMode.Leader,
|
BGTimingTowerSplitsMode.Leader,
|
||||||
BGTimingTowerSplitsMode.Interval,
|
BGTimingTowerSplitsMode.Interval,
|
||||||
@@ -151,7 +157,10 @@ export function TimingTower() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RowsContainer carsToDisplay={grid.length} retiredCarsPresent={!!retiredCarsPresent}>
|
<RowsContainer
|
||||||
|
carsToDisplay={startingCarsCount}
|
||||||
|
retiredCarsPresent={retiredCarsCount > 0}
|
||||||
|
>
|
||||||
{rows}
|
{rows}
|
||||||
</RowsContainer>
|
</RowsContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ const initialState: RootState["event"] = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
position: 9,
|
position: 9,
|
||||||
status: CarStatus.Normal,
|
status: CarStatus.DidNotStart,
|
||||||
tyre: DEFAULT_TYRE,
|
tyre: DEFAULT_TYRE,
|
||||||
notices: [],
|
notices: [],
|
||||||
distance: 1200 * 4,
|
distance: 1200 * 4,
|
||||||
@@ -206,10 +206,18 @@ export const eventSlice = createSlice({
|
|||||||
status: car.status,
|
status: car.status,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const add = (status: CarStatus) => {
|
||||||
|
if (status === CarStatus.Retired) {
|
||||||
|
return 1000000;
|
||||||
|
} else if (status === CarStatus.DidNotStart) {
|
||||||
|
return 2000000;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
sortingGrid.sort((a, b) =>
|
sortingGrid.sort((a, b) =>
|
||||||
// Retired cars go to the end but still maintain their own order.
|
// Retired cars go to the end but still maintain their own order.
|
||||||
(b.distance - (b.status === CarStatus.Retired ? 1000000 : 0))
|
(b.distance - add(b.status)) - (a.distance - add(a.status)),
|
||||||
- (a.distance - (a.status === CarStatus.Retired ? 1000000 : 0)),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
sortingGrid.forEach((entry, sortedPosition) => {
|
sortingGrid.forEach((entry, sortedPosition) => {
|
||||||
|
|||||||
Reference in new issue
Block a user