Format WOD étendu : EMOM « tout à chaque intervalle », repos entre les tours ; Chelsea et Barbara (4e)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-23 01:59:27 +01:00
co-authored by Claude Opus 5.5
parent db0b6f954c
commit 7678e580b7
13 changed files with 167 additions and 24 deletions
+2 -1
View File
@@ -57,6 +57,7 @@ import { scoreLabel } from "../domain/wod.js";
* @property {number|null} reps
* @property {number|null} kg
* @property {boolean} capped
* @property {number[]} [marks] tours avec repos : secondes courues à la fin de chaque tour
*/
/** Durée par défaut d'une série au temps quand le programme n'en donne pas. */
@@ -187,7 +188,7 @@ export function createDraft(session, state, date, warmupSteps) {
/** @param {import("../domain/wod.js").WodFormat} format @returns {DraftWod} */
export function emptyWod(format) {
return { format: structuredClone(format), startedAt: null, banked: 0, rx: true, seconds: null, rounds: null, reps: null, kg: null, capped: false };
return { format: structuredClone(format), startedAt: null, banked: 0, rx: true, seconds: null, rounds: null, reps: null, kg: null, capped: false, marks: [] };
}
/**
+25 -7
View File
@@ -6,7 +6,7 @@
import { h, replace, vibrate } from "./dom.js";
import { resolveExercise } from "../domain/program.js";
import { clockText, currentMovement, formatHint, formatLabel, formatSeconds, parseClock, scoreFields, scoreLabel, wodClock, wodKey } from "../domain/wod.js";
import { clockText, currentMovement, movesInTurn, formatHint, formatLabel, formatSeconds, parseClock, scoreFields, scoreLabel, wodClock, wodKey } from "../domain/wod.js";
import { wodRecords } from "../domain/analysis.js";
import { usesLoad, wodElapsed } from "./session-draft.js";
import { kg, parseAmount, shortDay } from "./format.js";
@@ -25,6 +25,10 @@ export function wodPanel({ draft, session, store, onChange }) {
const format = w.format;
const fields = scoreFields(format);
const total = formatSeconds(format);
// Tours avec repos entre deux (Barbara) : « Tour fini » lance le repos.
const rested = format.type === "rounds" && (format.rest ?? 0) > 0;
const marks = () => (w.marks ??= []);
const clockAt = (/** @type {number} */ elapsed) => wodClock(format, elapsed, marks());
// Le même WOD déjà fait (même nom, même format) : son record, à battre.
const record = wodRecords(store.getState()).find((r) => r.key === wodKey(session.name, format)) ?? null;
@@ -117,7 +121,7 @@ export function wodPanel({ draft, session, store, onChange }) {
};
/** Arrêt du chrono : For Time et tours prennent le temps comme score. */
const finishWod = () => {
const elapsed = Math.round(Math.max(0, wodElapsed(w, Date.now())));
const elapsed = Math.round(Math.max(0, clockAt(wodElapsed(w, Date.now())).elapsed));
pause();
if (fields.seconds) {
w.seconds = total !== null ? Math.min(elapsed, total) : elapsed;
@@ -134,6 +138,7 @@ export function wodPanel({ draft, session, store, onChange }) {
w.startedAt = null;
w.banked = 0;
w.capped = false;
w.marks = [];
onChange();
void keepAwake(false);
stopTicking();
@@ -149,9 +154,11 @@ export function wodPanel({ draft, session, store, onChange }) {
const paint = () => {
const now = Date.now();
const pre = w.startedAt !== null && w.startedAt > now ? Math.ceil((w.startedAt - now) / 1000) : 0;
const c = wodClock(format, pre ? 0 : wodElapsed(w, now));
const c = clockAt(pre ? 0 : wodElapsed(w, now));
const movement = currentMovement(c, moves.length);
moves.forEach((m, i) => m.classList.toggle("wod-move--now", running() && !pre && i === movement));
// À tour de rôle (EMOM, Tabata) : le mouvement de l'intervalle ; EMOM « tout » : tous.
const all = format.type === "emom" && !movesInTurn(format) && c.phase === "work";
moves.forEach((m, i) => m.classList.toggle("wod-move--now", running() && !pre && (all || (movesInTurn(format) && i === movement))));
if (pre) {
time.textContent = String(pre);
@@ -161,7 +168,7 @@ export function wodPanel({ draft, session, store, onChange }) {
} else {
// For Time et tours : on mesure un temps, le chrono monte. Sinon il descend.
const up = format.type === "fortime" || format.type === "rounds";
time.textContent = clockText(up || c.remaining === null ? c.elapsed : c.remaining);
time.textContent = clockText(c.phase === "rest" && rested ? /** @type {number} */ (c.remaining) : up || c.remaining === null ? c.elapsed : c.remaining);
phase.textContent = phaseText(format, c);
if (running()) {
if (last.phase === "pre" || (last.phase && (c.phase !== last.phase || c.round !== last.round))) {
@@ -175,7 +182,7 @@ export function wodPanel({ draft, session, store, onChange }) {
clockBox.classList.toggle("wod-clock--rest", c.phase === "rest");
clockBox.classList.toggle("wod-clock--done", c.phase === "done");
if (c.phase === "done" && running()) {
if (c.phase === "done" && running() && !rested) {
// fin du format : For Time au cap, AMRAP, EMOM, Tabata terminés
w.banked = /** @type {number} */ (total);
w.startedAt = null;
@@ -185,15 +192,25 @@ export function wodPanel({ draft, session, store, onChange }) {
stopTicking();
paintScore();
}
lastPhase = c.phase;
paintButtons(c.phase === "done");
};
let lastPhase = "";
/** Fin d'un tour (Barbara) : le repos commence ; le dernier tour arrête le chrono. */
const roundDone = () => {
marks().push(wodElapsed(w, Date.now()));
if (marks().length >= (format.rounds ?? 1)) return finishWod();
onChange();
paint();
};
const paintButtons = (/** @type {boolean} */ done) => {
const btn = (/** @type {string} */ label, /** @type {() => void} */ fn, cls = "btn") => h("button", { type: "button", class: cls, on: { click: fn } }, label);
replace(buttons,
!done && !running() && btn(w.banked > 0 ? "Reprendre" : "Démarrer", start, "btn btn--primary btn--lg"),
running() && btn("Pause", pause),
running() && (format.type === "fortime" || format.type === "rounds") && btn("Fini !", finishWod, "btn btn--primary btn--lg"),
running() && !rested && (format.type === "fortime" || format.type === "rounds") && btn("Fini !", finishWod, "btn btn--primary btn--lg"),
running() && rested && lastPhase === "work" && btn(marks().length + 1 >= (format.rounds ?? 1) ? "Fini !" : "Tour fini", roundDone, "btn btn--primary btn--lg"),
(w.banked > 0 || running()) && btn("Zéro", () => void reset(), "btn btn--ghost"));
};
@@ -291,6 +308,7 @@ export function phaseText(format, c) {
case "emom": return `Intervalle ${c.round}/${c.rounds}`;
case "tabata": return `${c.phase === "rest" ? "Repos" : "Effort"} · tour ${c.round}/${c.rounds}`;
case "fortime": return format.capMinutes ? `Chrono · cap ${format.capMinutes} min` : "Chrono";
case "rounds": return c.round === null ? "Chrono" : c.phase === "rest" ? `Repos · puis tour ${c.round}/${c.rounds}` : `Tour ${c.round}/${c.rounds}`;
default: return "Chrono";
}
}