feat(layouts): optional min/max lap time per track layout for practice

Each layout can carry its own lap window (set on creation, editable in
Settings, saved from Race Day during practice). Open/Free practice on
that layout uses it; races always keep the event's values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
larssandandClaude Opus 5.5 committed 2026-10-07 20:33:22 +02:00
1 parent 8601954ea2
commit 9d79bcb4d3
13 files changed
+174 -15

No files matched your search

+15
View File
@@ -9,9 +9,24 @@ export function normalizeTrackLayout(layout, { uid } = {}) {
id: String(layout?.id || (uid ? uid("layout") : "")),
label: String(layout?.label || "").trim(),
startedAt: Number.isFinite(Number(layout?.startedAt)) ? Number(layout.startedAt) : Date.now(),
// Optional lap window for practice on this layout (a rebuilt track is often shorter or
// longer); 0 = not set, the event's own min/max lap time applies.
minLapMs: Math.max(0, Math.round(Number(layout?.minLapMs) || 0)),
maxLapMs: Math.max(0, Math.round(Number(layout?.maxLapMs) || 0)),
};
}
// Practice sessions use their layout's min/max lap time where it is set; race sessions
// always keep the event's (set by race control, never changed mid-race by a layout).
export function getLayoutLapWindowOverride(layouts, session) {
if (!session || !isPracticeSessionType(session.type) || !session.trackLayoutId) return {};
const layout = (Array.isArray(layouts) ? layouts : []).find((item) => item?.id === session.trackLayoutId);
const override = {};
if (Number(layout?.minLapMs) > 0) override.minLapMs = Number(layout.minLapMs);
if (Number(layout?.maxLapMs) > 0) override.maxLapMs = Number(layout.maxLapMs);
return override;
}
export function normalizeTrackLayouts(layouts, { uid } = {}) {
const list = (Array.isArray(layouts) ? layouts : [])
.map((layout) => normalizeTrackLayout(layout, { uid }))