import { translate } from "./i18n.js"; import { pictogram } from "./icons.js"; // Shared by the embedded BGS tutorial and the standalone /learn guide. // Keep both introductory overviews in place throughout planning and playback. export function tutorialMissionHeader(chapter, step, locale) { const t = (key, params) => translate(locale, key, params); const overview = ["basics", "planning-phases"].includes(chapter) ? missionOverview(t) : ""; const scope = ["basics", "first-shot", "energy", "planning-phases"].includes(chapter) ? `${t("timing.exercise", { turns: chapter === "planning-phases" ? 7 : chapter === "energy" ? 4 : 3 })}` : ""; return overview + scope; } function missionOverview(t) { return `
${[ ["clock", "plan"], ["lock", "lock"], ["step", "play"], ] .map( ([icon, key], i) => `${i ? `` : ""}
${pictogram(icon)}${t(`overview.${key}`)}${t(`overview.${key}_detail`)}
`, ) .join( "", )}
${t("overview.turns")}
${[ { first: 1, last: 3 }, { first: 4, last: 7 }, { first: 8, last: 12 }, ] .map( ({ first, last }, i) => `
${Array.from({ length: last - first + 1 }, (_, n) => `${first + n}`).join("")}
`, ) .join("")}
${pictogram("step")}
`; } // Frames describe the *next* resolution operation. Only a captured `appear` // frame closes a whole turn (crew actions alone do not finish threat movement). // Use the displayed prefix, never the live cursor, clock, or planned cards. export function missionTurnProgress(frames = [], lastTurn = 12) { const completed = new Set(frames.filter((frame) => frame.step === "appear" && frame.turn > 0 && frame.turn <= lastTurn).map((frame) => frame.turn)); const displayed = frames.at(-1); return { completed, current: displayed && displayed.turn <= lastTurn && !completed.has(displayed.turn) ? displayed.turn : 0 }; } export function updateTutorialMissionProgress(root, frames, locale, lastTurn = 12) { const { completed, current } = missionTurnProgress(frames, lastTurn); for (const cell of root.querySelectorAll("[data-mission-turn]")) { const turn = Number(cell.dataset.missionTurn); const done = completed.has(turn); const active = turn === current; cell.classList.toggle("completed", done); cell.classList.toggle("current", active); if (active) cell.setAttribute("aria-current", "step"); else cell.removeAttribute("aria-current"); const label = translate(locale, done ? "overview.turn_completed" : active ? "overview.turn_current" : "program.selected_turn", { turn }); cell.setAttribute("aria-label", label); cell.setAttribute("title", label); cell.parentElement.classList.toggle("progressed", [...cell.parentElement.children].some((sibling) => sibling.classList.contains("completed") || sibling.classList.contains("current"))); } }