feat(overlay): TV graphics OBS layout with title plate, timing tower and start position (1.76.0)
This commit is contained in:
1 parent
50a99fe33f
commit
3d0ab0c4b7
11 files changed
+144
-8
No files matched your search
+60
-1
@@ -200,6 +200,61 @@ export function getPositionChange(session, startOrder, driverId, currentPosition
|
||||
return startPosition > 0 ? startPosition - currentPosition : null;
|
||||
}
|
||||
|
||||
// TV graphics: a title plate top left and a timing tower top right with real columns -
|
||||
// place / start position, driver, laps, time, best lap and gap - large enough to read on a phone.
|
||||
function renderObsBroadcast({ active, compactRows, startOrder, showStartGrid, fastestRow, elapsedOrRemaining, branding, obsConfig, positionChangeMarkup, deps }) {
|
||||
const { t, escapeHtml, formatLap, getEventName, getSessionGridEntries } = deps;
|
||||
const practice = PRACTICE_TYPES.has(String(active.type || ""));
|
||||
const showStart = obsConfig.showStart && !practice && !showStartGrid && compactRows.some((row) => startOrder.includes(row.driverId));
|
||||
const showResult = obsShowsResult(active, obsConfig);
|
||||
const columns = showStartGrid
|
||||
? [["pos", "2.4em"], ["name", "minmax(0, 1fr)"]]
|
||||
: [
|
||||
["pos", "2.4em"], showStart && ["start", "2.4em"], ["name", "minmax(6em, 1fr)"],
|
||||
obsConfig.showPositionChange && !practice && ["change", "2.6em"], obsConfig.showLaps && ["laps", "max-content"],
|
||||
showResult && ["result", "max-content"], obsConfig.showBest && ["best", "max-content"], obsConfig.showGap && ["gap", "max-content"],
|
||||
].filter(Boolean);
|
||||
const label = { pos: "#", start: t("overlay.col_start"), name: t("table.driver"), change: "", laps: t("table.laps"), result: t("table.result"), best: t("table.best_lap"), gap: t("table.gap") };
|
||||
const cell = (key, html) => `<span class="obs-tv-cell obs-tv-${key}">${html}</span>`;
|
||||
// With laps in their own column the result's "14/" prefix only repeats them.
|
||||
const timeOnly = (value) => (obsConfig.showLaps ? String(value || "").replace(/^\d+\//, "") : String(value || ""));
|
||||
const podium = (place) => (place <= 3 ? ` is-p${place}` : "");
|
||||
const rows = showStartGrid
|
||||
? getSessionGridEntries(active).slice(0, obsConfig.rows).map((entry, idx) => `
|
||||
<div class="obs-tv-row${podium(idx + 1)}">${cell("pos", entry.slot)}${cell("name", escapeHtml(entry.name))}</div>`)
|
||||
: compactRows.map((row, idx) => {
|
||||
const start = startOrder.indexOf(row.driverId) + 1;
|
||||
const values = {
|
||||
pos: idx + 1,
|
||||
start: start ? `<span class="obs-tv-slash">/</span>${start}` : "",
|
||||
name: `${escapeHtml(row.displayName || row.driverName)}${row.heatCarName ? ` <small>🚗 ${escapeHtml(row.heatCarName)}</small>` : ""}${row.suspectPending ? ' <span class="suspect-flag">⚠</span>' : ""}`,
|
||||
change: positionChangeMarkup(row, idx + 1),
|
||||
laps: row.laps ?? 0,
|
||||
result: escapeHtml(timeOnly(row.resultDisplay)),
|
||||
best: Number.isFinite(row.bestLapMs) ? escapeHtml(formatLap(row.bestLapMs)) : "-",
|
||||
gap: escapeHtml(idx === 0 ? "" : row.gapDisplay || row.gapAhead || ""),
|
||||
};
|
||||
return `<div class="obs-tv-row${podium(idx + 1)}${row.driverId === fastestRow?.driverId ? " is-fastest" : ""}">${columns.map(([key]) => cell(key, values[key])).join("")}</div>`;
|
||||
});
|
||||
const eventName = String(getEventName(active.eventId) || "").trim();
|
||||
return `
|
||||
<section class="obs-tv" style="--obs-tv-cols: ${columns.map(([, width]) => width).join(" ")}">
|
||||
<div class="obs-tv-plate">
|
||||
${eventName && eventName !== active.name ? `<p class="obs-tv-event">${escapeHtml(eventName)}</p>` : ""}
|
||||
<h2 class="obs-tv-session">${escapeHtml(active.name)}</h2>
|
||||
</div>
|
||||
<div class="obs-tv-tower">
|
||||
<header class="obs-tv-head">
|
||||
${branding.logoDataUrl ? `<img class="obs-tv-logo" src="${escapeHtml(branding.logoDataUrl)}" alt="logo" />` : `<span class="obs-tv-brand">${escapeHtml(branding.brandName || "RC RaceCore")}</span>`}
|
||||
${obsConfig.showClock ? `<strong class="obs-tv-clock" data-overlay-clock>${elapsedOrRemaining}</strong>` : ""}
|
||||
</header>
|
||||
<div class="obs-tv-row obs-tv-labels">${columns.map(([key]) => cell(key, escapeHtml(label[key]))).join("")}</div>
|
||||
${rows.join("") || `<p class="obs-tv-empty">${t("timing.no_laps")}</p>`}
|
||||
${!showStartGrid && obsConfig.showFastest && fastestRow ? `<footer class="obs-tv-foot">${t("overlay.fastest_lap")}: <strong>${escapeHtml(formatLap(fastestRow.bestLapMs))}</strong> · ${escapeHtml(fastestRow.displayName || fastestRow.driverName || "")}</footer>` : ""}
|
||||
</div>
|
||||
</section>`;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@@ -224,7 +279,7 @@ export function renderObsOverlay(active, leaderboard, result, sessionTiming, bra
|
||||
formatTeamActiveMemberLabel,
|
||||
} = deps;
|
||||
const obsConfig = getObsOverlayConfig();
|
||||
const startOrder = active && obsConfig.showPositionChange ? getSessionGridOrder(active) : [];
|
||||
const startOrder = active && (obsConfig.showPositionChange || obsConfig.showStart) ? getSessionGridOrder(active) : [];
|
||||
const positionChangeMarkup = (row, position) => {
|
||||
const change = obsConfig.showPositionChange ? getPositionChange(active, startOrder, row.driverId, position) : null;
|
||||
if (!change) return "";
|
||||
@@ -243,6 +298,10 @@ export function renderObsOverlay(active, leaderboard, result, sessionTiming, bra
|
||||
? formatCountdownLocal(sessionTiming?.followUpRemainingMs ?? 0)
|
||||
: formatCountdownLocal(sessionTiming?.remainingMs ?? 0);
|
||||
|
||||
if (obsConfig.layout === "broadcast") {
|
||||
return renderObsBroadcast({ active, compactRows, startOrder, showStartGrid, fastestRow, elapsedOrRemaining, branding, obsConfig, positionChangeMarkup, deps });
|
||||
}
|
||||
|
||||
if (obsConfig.layout === "grid") {
|
||||
return `
|
||||
<section class="overlay-obs-layout overlay-obs-layout-grid">
|
||||
|
||||
Reference in new issue
Block a user