feat(overlay): flash the row on a new time, ticking pit clock and split badges (1.88.0)

This commit is contained in:
larssand committed 2026-11-10 07:42:47 +01:00
1 parent ee290a4ab8
commit f5b77d5589
11 files changed
+304 -6

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
import assert from "node:assert/strict";
// Overlay live marks in a real browser: a new time flashes the row, a car in the pits gets a
// ticking clock with a fuel pump next to its time, and a new split shows - on the regular
// leaderboard and the OBS tower.
export async function runOverlayLiveMarksSmoke({ evaluate }) {
const result = await evaluate(`(async () => {
const { renderOverlayLeaderboard, renderObsOverlay } = await import('/src/overlays.js');
const { refreshLiveMarkNodes } = await import('/src/overlay_live_marks.js');
const { escapeHtml } = await import('/src/html_escape.js');
const frame = document.createElement('iframe');
frame.style.cssText = 'position:fixed;left:0;top:0;width:1200px;height:700px;border:0;z-index:99999';
document.body.append(frame);
const doc = frame.contentDocument;
const style = doc.createElement('link'); style.rel = 'stylesheet'; style.href = '/src/styles.css';
const loaded = new Promise((resolve, reject) => { style.onload = resolve; style.onerror = reject; });
doc.head.append(style); await loaded;
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const deps = { t: (key) => key, escapeHtml, formatLap: (ms) => (ms / 1000).toFixed(3), formatTeamActiveMemberLabel: () => '', formatPredictedLapDelta: () => '-', getVisiblePassings: () => [], getEventName: () => 'Club', getSessionTypeLabel: () => 'Practice', getStartModeLabel: () => '', getStatusLabel: () => '', getObsOverlayConfig: () => ({ layout: 'broadcast', rows: 10, showClock: true, showLaps: true, showResult: true, showBest: true, showGap: true }), normalizeStartMode: (v) => v, renderPositionGrid: () => '', getSessionGridEntries: () => [], getSessionGridOrder: () => [] };
const now = Date.now();
let rows = [{ key: 'lm_a', displayName: 'Anna', laps: 3, resultDisplay: '3/0:41.000', bestLapMs: 13500, lastTimestamp: now - 5000 }, { key: 'lm_b', displayName: 'Bo', laps: 3, resultDisplay: '3/0:42.000', bestLapMs: 13700, lastTimestamp: now - 4000 }];
const out = {};
try {
doc.body.innerHTML = '<div class="overlay-board"></div>';
const board = doc.querySelector('.overlay-board');
const draw = () => { board.innerHTML = renderOverlayLeaderboard(rows, deps, { sortable: false }); };
draw();
out.flashOnOpen = board.querySelectorAll('.is-passing').length;
rows = rows.map((row) => row.key === 'lm_a' ? { ...row, laps: 4, lastTimestamp: now + 1 } : row);
draw();
const flashed = board.querySelector('.overlay-race-row.is-passing');
out.flashed = flashed?.dataset.overlayCompetitor || '';
out.animation = flashed ? getComputedStyle(flashed).animationName : '';
rows = rows.map((row) => row.key === 'lm_b' ? { ...row, pitActive: true, pitEnteredAt: now } : row);
draw();
const clock = () => board.querySelector('[data-overlay-competitor="lm_b"] [data-pit-clock] b')?.textContent || '';
out.pitIcon = Boolean(board.querySelector('[data-overlay-competitor="lm_b"] .overlay-pit-badge svg'));
const before = clock();
await wait(450);
refreshLiveMarkNodes(doc);
out.pitTicks = before !== clock() && /^0:00\\.[0-9]$/.test(clock());
rows = rows.map((row) => row.key === 'lm_a' ? { ...row, lastSplitTimestamp: now + 2, lastSplitMs: 5123, lastSplitDeltaMs: -120 } : row);
draw();
out.split = board.querySelector('[data-overlay-competitor="lm_a"] .overlay-split-chip')?.textContent.trim() || '';
doc.body.innerHTML = '<section class="overlay-shell-obs"></section>';
rows = rows.map((row) => row.key === 'lm_a' ? { ...row, laps: 5, lastTimestamp: now + 3 } : row);
doc.body.firstElementChild.innerHTML = renderObsOverlay({ name: 'Practice', eventId: 'e', status: 'running', type: 'open_practice' }, rows, {}, { remainingMs: 300000 }, {}, deps);
out.obsFlash = doc.querySelectorAll('.obs-tv-row.is-passing').length;
out.obsPit = Boolean(doc.querySelector('.obs-tv-row [data-pit-clock]'));
} finally { frame.remove(); }
return out;
})()`);
assert.equal(result.flashOnOpen, 0, "nothing flashes when the overlay opens");
assert.equal(result.flashed, "lm_a", "the driver with the new time flashes");
assert.equal(result.animation, "overlay-pass");
assert.equal(result.pitIcon, true, "fuel pump next to the time");
assert.equal(result.pitTicks, true, "the pit clock ticks without a redraw");
assert.match(result.split, /^S 5\.123 −0\.120$/);
assert.equal(result.obsFlash, 1, "the OBS tower flashes too");
assert.equal(result.obsPit, true, "and shows the pit clock");
console.log("PASS overlay live marks: a new time flashes the row, the pit clock ticks with a fuel pump, a new split shows - leaderboard and OBS tower");
}
+2
View File
@@ -1,4 +1,5 @@
import { runOverlaySmoke } from "./browser_overlays.js";
import { runOverlayLiveMarksSmoke } from "./browser_overlay_live_marks.js";
import { runRaceSetupSmoke } from "./browser_race_setup.js";
import { runRaceDaySmoke } from "./browser_race_day.js";
import { runRaceDayFinalsSmoke } from "./browser_race_day_finals.js";
@@ -222,6 +223,7 @@ try {
})()`);
console.log("PASS decoder diagnostics update without resetting settings draft");
await runOverlaySmoke({ evaluate });
await runOverlayLiveMarksSmoke({ evaluate });
const mobileState = await savedState();
const mobileToken = "browser-mobile-profile-token-1234567890";
mobileState.training ||= {};
+64
View File
@@ -0,0 +1,64 @@
import test from "node:test";
import assert from "node:assert/strict";
import { createOverlayLiveMarks, formatPitClock, passingFlashAttrs, renderLiveMarkBadges, PASSING_FLASH_MS } from "../src/overlay_live_marks.js";
const escapeHtml = (value) => String(value);
const formatLap = (ms) => `${Math.floor(ms / 60000)}:${String(Math.floor(ms % 60000 / 1000)).padStart(2, "0")}.${String(ms % 1000).padStart(3, "0")}`;
test("a new time flashes the row for a moment, but nothing flashes when the overlay first opens", () => {
let clock = 1_000_000;
const marks = createOverlayLiveMarks({ now: () => clock });
const row = { key: "d1", lastTimestamp: 500 };
assert.equal(marks.observe([row]).get("d1").passingAgeMs, null, "first sight: no flash");
clock += 100;
assert.equal(marks.observe([row]).get("d1").passingAgeMs, null, "same time again: no flash");
clock += 100;
assert.equal(marks.observe([{ ...row, lastTimestamp: 14_000 }]).get("d1").passingAgeMs, 0);
clock += 250;
const mark = marks.observe([{ ...row, lastTimestamp: 14_000 }]).get("d1");
assert.equal(mark.passingAgeMs, 250, "a re-render keeps the flash going");
assert.deepEqual(passingFlashAttrs(mark), { className: " is-passing", style: ' style="--pass-delay:-250ms"' });
clock += PASSING_FLASH_MS;
assert.equal(marks.observe([{ ...row, lastTimestamp: 14_000 }]).get("d1").passingAgeMs, null);
});
test("pit: a running clock from this computer's time, then the stop time for a few seconds", () => {
let clock = 2_000_000;
const marks = createOverlayLiveMarks({ now: () => clock });
marks.observe([{ key: "d1", lastTimestamp: 1, pitStops: 0 }]);
clock += 1000;
const inPit = marks.observe([{ key: "d1", lastTimestamp: 1, pitActive: true, pitEnteredAt: 42, pitStops: 0 }]).get("d1");
assert.deepEqual(inPit.pit, { active: true, startAt: clock }, "the decoder's entry time is not used once the overlay saw the entry");
assert.match(renderLiveMarkBadges(inPit, { formatLap, escapeHtml, nowMs: clock + 12_400 }), /data-pit-clock="\d+".*0:12\.4/s);
clock += 24_000;
const out = marks.observe([{ key: "d1", lastTimestamp: 1, pitActive: false, pitStops: 1, lastPitStopMs: 24_512 }]).get("d1");
assert.equal(out.pit.stopMs, 24_512);
assert.match(renderLiveMarkBadges(out, { formatLap, escapeHtml }), /is-done.*0:24\.512/s);
clock += 5000;
assert.equal(marks.observe([{ key: "d1", lastTimestamp: 1, pitStops: 1, lastPitStopMs: 24_512 }]).get("d1").pit, null);
});
test("a car already in the pits when the overlay opens gets its clock from the entry time", () => {
const clock = 3_000_000;
const marks = createOverlayLiveMarks({ now: () => clock });
assert.equal(marks.observe([{ key: "d1", pitActive: true, pitEnteredAt: clock - 8000 }]).get("d1").pit.startAt, clock - 8000);
const odd = createOverlayLiveMarks({ now: () => clock });
assert.equal(odd.observe([{ key: "d1", pitActive: true, pitEnteredAt: clock + 60_000 }]).get("d1").pit.startAt, clock, "a decoder clock ahead of ours starts at 0");
});
test("a new split shows for a few seconds with its gain against the previous lap", () => {
let clock = 4_000_000;
const marks = createOverlayLiveMarks({ now: () => clock });
marks.observe([{ key: "d1", lastSplitTimestamp: 10 }]);
clock += 50;
const mark = marks.observe([{ key: "d1", lastSplitTimestamp: 20, lastSplitMs: 5123, lastSplitDeltaMs: -120 }]).get("d1");
assert.match(renderLiveMarkBadges(mark, { formatLap, escapeHtml }), /S 0:05\.123 <i class="is-faster">−0\.120/);
clock += 4000;
assert.equal(marks.observe([{ key: "d1", lastSplitTimestamp: 20, lastSplitMs: 5123 }]).get("d1").split, null);
});
test("formatPitClock", () => {
assert.equal(formatPitClock(12_480), "0:12.4");
assert.equal(formatPitClock(75_000), "1:15.0");
assert.equal(formatPitClock(-5), "0:00.0");
});
+1
View File
@@ -2,6 +2,7 @@ import "./auth.test.js";
import "./backend_url.test.js";
import "./houseofrc_logic.test.js";
import "./stint_laps_view.test.js";
import "./overlay_live_marks.test.js";
import "./judging_penalties.test.js";
import "./practice_rank.test.js";
import "./team_race_logic.test.js";