feat(race-setup): list sessions in running order and move them with up/down (1.49.0)
This commit is contained in:
1 parent
e199f3aa1a
commit
bb0fa7ede4
14 files changed
+104
-14
No files matched your search
+24
-1
@@ -768,7 +768,30 @@ export function generateQualifyingForRace(event, { buildPracticeStandings, getEv
|
||||
// The order a race's sessions are run in: practice, then qualifying round by round (Q1 H1,
|
||||
// Q1 H2, Q2 H1 ... - generation stores them heat by heat), then finals leg by leg with the
|
||||
// lowest final first (C1, B1, A1, C2 ...). Anything else keeps the order it was created in.
|
||||
export function orderSessionsForRunning(sessions = []) {
|
||||
// manualOrder (event.sessionOrder, set with ▲▼ in Race Setup) overrides it for the sessions it
|
||||
// lists; a session made later keeps its own place, e.g. a recreated Q1 H2 after Q1 H1.
|
||||
export function orderSessionsForRunning(sessions = [], manualOrder = []) {
|
||||
const auto = orderSessionsAutomatically(sessions);
|
||||
const byId = new Map(auto.map((session) => [session.id, session]));
|
||||
const listed = [...new Set(manualOrder || [])].filter((id) => byId.has(id)).map((id) => byId.get(id));
|
||||
if (!listed.length) return auto;
|
||||
const listedIds = new Set(listed.map((session) => session.id));
|
||||
let next = 0;
|
||||
return auto.map((session) => (listedIds.has(session.id) ? listed[next++] : session));
|
||||
}
|
||||
|
||||
// Moves one session a step up (-1) or down (+1) in the running order; returns the new manual
|
||||
// order (every session id) to store on the event.
|
||||
export function moveSessionInRunningOrder(sessions, manualOrder, sessionId, step) {
|
||||
const ids = orderSessionsForRunning(sessions, manualOrder).map((session) => session.id);
|
||||
const index = ids.indexOf(sessionId);
|
||||
const other = index + step;
|
||||
if (index < 0 || other < 0 || other >= ids.length) return ids;
|
||||
[ids[index], ids[other]] = [ids[other], ids[index]];
|
||||
return ids;
|
||||
}
|
||||
|
||||
function orderSessionsAutomatically(sessions = []) {
|
||||
const key = (session, index) => {
|
||||
if (["practice", "free_practice", "open_practice"].includes(session.type)) return [0, 0, 0, index];
|
||||
if (session.type === "qualification") {
|
||||
|
||||
Reference in new issue
Block a user