feat(audio): quick lap time call at each passing, 17 six / 18 flat (1.62.0)
This commit is contained in:
1 parent
94ec278f53
commit
6142b14e47
10 files changed
+101
-10
No files matched your search
+20
-1
@@ -17,7 +17,7 @@ export const RACE_AUDIO_EVENT_DEFINITIONS = Object.freeze([
|
||||
event("prologue_hold", "start", "high", true, "effects/warning.wav"), event("prologue_resumed", "start", "normal"),
|
||||
event("prologue_cancelled", "start", "normal"), event("clock_running", "start", "high"),
|
||||
event("heat_call", "start", "normal"),
|
||||
event("transponder_pass", "race", "pass", false, "effects/transponder_pass.wav"), event("lap_completed", "race", "pass", false),
|
||||
event("transponder_pass", "race", "pass", false, "effects/transponder_pass.wav"), event("lap_completed", "race", "pass"),
|
||||
event("personal_best", "race", "low", true, "effects/personal_best.wav", 1500),
|
||||
event("fastest_lap", "race", "normal", true, "effects/fastest_lap_trophy.wav", 1500),
|
||||
event("track_record", "race", "normal", true, "effects/track_record_fanfare.wav", 2000),
|
||||
@@ -99,6 +99,9 @@ export function normalizeRaceAudioSettings(value = {}) {
|
||||
raceCallouts: source.raceCallouts === "full" ? "full" : "passing",
|
||||
// Practice hype calls (practice_hype_logic.js); never in qualifying or finals.
|
||||
practiceHype: source.practiceHype !== false,
|
||||
// Short lap time per passing, "Anders, 17 six": "practice" (default), "always" or "off".
|
||||
lapTimeCalls: ["practice", "always", "off"].includes(source.lapTimeCalls) ? source.lapTimeCalls : "practice",
|
||||
lapTimeCallName: source.lapTimeCallName === true,
|
||||
// Qualifying and finals: "both" = when the leader changes and every 2 minutes,
|
||||
// "change" = only when the leader changes, "off" = never (unless raceCallouts is "full").
|
||||
raceLeaderCalls: ["off", "change", "both"].includes(source.raceLeaderCalls) ? source.raceLeaderCalls : "both",
|
||||
@@ -125,6 +128,7 @@ export function isSilencedDuringRace(eventKey, settings, session) {
|
||||
const audio = normalizeRaceAudioSettings(settings);
|
||||
const practice = Boolean(session) && PRACTICE_TYPES.has(String(session.type || ""));
|
||||
if (PRACTICE_HYPE_SET.has(eventKey)) return !practice || !audio.practiceHype;
|
||||
if (eventKey === "lap_completed") return audio.lapTimeCalls === "off" || (audio.lapTimeCalls === "practice" && !practice);
|
||||
if (!session || practice) return false;
|
||||
if (eventKey === "leader_update") return audio.raceLeaderCalls !== "both";
|
||||
if (eventKey === "new_leader" && audio.raceLeaderCalls !== "off") return false;
|
||||
@@ -132,6 +136,18 @@ export function isSilencedDuringRace(eventKey, settings, session) {
|
||||
return RACE_PASSING_CALLOUT_EVENTS.includes(eventKey);
|
||||
}
|
||||
|
||||
// The quick passing call used at race tracks: seconds and tenths, "17 six", "18 flat"
|
||||
// ("17 sex", "18 jämnt"). Over a minute: "1 05 two".
|
||||
const TENTHS = { en: ["flat", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"], sv: ["jämnt", "ett", "två", "tre", "fyra", "fem", "sex", "sju", "åtta", "nio"] };
|
||||
export function formatShortLapCall(ms, language = "sv") {
|
||||
const value = Math.max(0, Math.floor(Number(ms) || 0));
|
||||
if (!value) return "";
|
||||
const minutes = Math.floor(value / 60000);
|
||||
const seconds = Math.floor((value % 60000) / 1000);
|
||||
const tenth = TENTHS[language === "en" ? "en" : "sv"][Math.floor((value % 1000) / 100)];
|
||||
return minutes ? `${minutes} ${String(seconds).padStart(2, "0")} ${tenth}` : `${seconds} ${tenth}`;
|
||||
}
|
||||
|
||||
// A lap time as the speaker says it: "17,18" (sv) / "17.18" (en), not "0:17.180", which voices
|
||||
// read as "zero 17 comma 180". Hundredths, cut not rounded, as on the timing screens.
|
||||
export function formatSpokenLapTime(ms, language = "sv") {
|
||||
@@ -263,6 +279,9 @@ export function createRaceAudioEngine(options = {}) {
|
||||
async function enqueueVoice(key, eventOptions = {}) {
|
||||
const voice = await resolveVoice(key, eventOptions);
|
||||
if (!voice) return false;
|
||||
// Quick calls (the lap time per passing) are only said when the voice is free: a lap time
|
||||
// said late is worse than none.
|
||||
if (eventOptions.skipIfBusy && (currentVoice || voiceQueue.length)) return false;
|
||||
return new Promise((resolve) => {
|
||||
const group = String(eventOptions.group || "");
|
||||
const task = { ...voice, group, sequence: voiceSequence += 1, resolve, expiresAt: eventOptions.maxDelayMs ? Number(eventOptions.queuedAt ?? now()) + Number(eventOptions.maxDelayMs) : 0 };
|
||||
|
||||
Reference in new issue
Block a user