feat(overlay): show places gained since the start in the OBS tower

Heats and finals started together show ▲/▼ against the start order
(new OBS option, on by default). In practice the best lap is no longer
printed twice as both result and best.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
larssandandClaude Opus 5.5 committed 2026-10-11 20:13:10 +02:00
1 parent 533f59adf9
commit 72d83ad183
12 files changed
+125 -8

No files matched your search

+30 -2
View File
@@ -180,6 +180,26 @@ export function renderTeamOverlay(rows, result, sessionTiming, deps) {
`;
}
const PRACTICE_TYPES = new Set(["open_practice", "free_practice", "practice"]);
// Places gained (positive) or lost (negative) since the start, for heats and finals started
// together from a start order (mass/position). null when it doesn't apply: practice and
// qualifying rank on best laps or individual clocks, and a staggered or flying start has no
// common start order to compare with.
export function getPositionChange(session, startOrder, driverId, currentPosition) {
if (!session || PRACTICE_TYPES.has(String(session.type || "")) || session.type === "qualification") return null;
if (!["mass", "position"].includes(String(session.startMode || "mass"))) return null;
if (session.status === "ready") return null;
const startPosition = (startOrder || []).indexOf(driverId) + 1;
return startPosition > 0 ? startPosition - currentPosition : null;
}
// In practice the ranking value *is* the best lap, so "result" and "best" would print the
// same time twice - show it once.
function obsShowsResult(session, obsConfig) {
return obsConfig.showResult && !(obsConfig.showBest && ["open_practice", "free_practice"].includes(String(session?.type || "")));
}
export function renderObsOverlay(active, leaderboard, result, sessionTiming, branding, deps) {
const {
t,
@@ -194,9 +214,16 @@ export function renderObsOverlay(active, leaderboard, result, sessionTiming, bra
normalizeStartMode,
renderPositionGrid,
getSessionGridEntries,
getSessionGridOrder = () => [],
formatTeamActiveMemberLabel,
} = deps;
const obsConfig = getObsOverlayConfig();
const startOrder = active && obsConfig.showPositionChange ? getSessionGridOrder(active) : [];
const positionChangeMarkup = (row, position) => {
const change = obsConfig.showPositionChange ? getPositionChange(active, startOrder, row.driverId, position) : null;
if (!change) return "";
return `<span class="overlay-position-change ${change > 0 ? "is-up" : "is-down"}" title="${escapeHtml(t("overlay.position_change_title"))}">${change > 0 ? "▲" : "▼"}${Math.abs(change)}</span>`;
};
const compactRows = leaderboard.slice(0, obsConfig.rows);
const readyPositionGrid = active && active.status === "ready" && normalizeStartMode(active.startMode) === "position";
const showStartGrid = obsConfig.showGrid && readyPositionGrid;
@@ -263,7 +290,7 @@ export function renderObsOverlay(active, leaderboard, result, sessionTiming, bra
<span class="pos-pill ${posClass}">${idx + 1}</span>
<strong>${escapeHtml(row.displayName || row.driverName)}${row.personalTimeUp ? " 🏁" : ""}${row.suspectPending ? ` <span class="suspect-flag" title="${escapeHtml(t("suspect.flag_title"))}">⚠</span>` : ""}</strong>
${obsConfig.showLaps ? `<span>${t("table.laps")}: ${row.laps ?? 0}</span>` : ""}
${obsConfig.showResult ? `<span>${t("table.result")}: ${escapeHtml(row.resultDisplay)}</span>` : ""}
${obsShowsResult(active, obsConfig) ? `<span>${t("table.result")}: ${escapeHtml(row.resultDisplay)}</span>` : ""}
${obsConfig.showGap ? `<span>${t("table.gap")}: ${escapeHtml(row.gapDisplay || row.gapAhead || "-")}</span>` : ""}
</article>
`;
@@ -293,8 +320,9 @@ export function renderObsOverlay(active, leaderboard, result, sessionTiming, bra
.map((row, idx) => {
const posClass = idx === 0 ? "pos-1" : idx === 1 ? "pos-2" : idx === 2 ? "pos-3" : "";
const trail = [
positionChangeMarkup(row, idx + 1),
obsConfig.showLaps ? `<span>${row.laps ?? 0}L</span>` : "",
obsConfig.showResult ? `<span>${escapeHtml(row.resultDisplay)}</span>` : "",
obsShowsResult(active, obsConfig) ? `<span>${escapeHtml(row.resultDisplay)}</span>` : "",
obsConfig.showBest ? `<span>${formatLap(row.bestLapMs)}</span>` : "",
obsConfig.showGap ? `<span>${escapeHtml(row.gapDisplay || row.gapAhead || "-")}</span>` : "",
]