diff --git a/README.md b/README.md index f109e99..cb7c045 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ npm run dev Open . Start with **Flight school / École de vol**: eight exercises use the real engine. Start with **Planning turns**: one crew member, a highlighted destination, two movement actions, and an empty turn. Choose left, right or a deck change to reach the destination; try the start/pause practice clock, then watch each turn execute. A missed destination can be retried. The later exercises have editable programs and a teammate already maintaining the computer; they cover firing, energy, malfunctions, battlebots/interceptors, double actions, phasing and specializations. -For a full mission, expand **Local session / Session locale**. Select 1–5 humans, the crew, mission, threat pools and optional modules. In solo, you control four androids and have access to the full action deck. In multiplayer testing, open another tab with `?seat=1`, etc. Readiness lasts two minutes; everyone must be ready together. The local mission starts after a three-second countdown. If someone misses the window, the crew keeps waiting. Select a card half, then a turn. Advance individual phases to lock previous turns, or let the shared clock do so. After programming, the captain can resolve one step at a time or finish the mission; everyone can inspect the replay and log. +For a full mission, expand **Local session / Session locale**. Select 1–5 humans, the crew, mission, threat pools and optional modules. In solo, you control four androids and have access to the full action deck. In multiplayer testing, open another tab with `?seat=1`, etc. Readiness lasts two minutes; everyone must be ready together. The local mission starts after a three-second countdown. If someone misses the window, the crew keeps waiting. Click a card half to fill the next empty editable turn. Click a filled turn to clear it; Backspace undoes your last placement for the selected crew member. Left/right arrow keys queue horizontal movement; up/down queue a deck change, using an available card. Typing in fields is unaffected. Shift-click or Combine retains multi-card selection; then choose a turn. Advance individual phases to lock previous turns, or let the shared clock do so. After programming, the captain can resolve one step at a time or finish the mission; everyone can inspect the replay and log. Training starts with its clock paused. **Start practice clock** and **Pause clock** control time only in training; normal missions retain their shared, continuous clock. You can also advance lesson phases explicitly. diff --git a/preview/app.js b/preview/app.js index c3ab083..db34fba 100644 --- a/preview/app.js +++ b/preview/app.js @@ -38,6 +38,7 @@ export function mountConsole(root, host = null) { received = 0, key = "", selected = [], + placements = [], handFilter = "all", lessons = [], careerKey = "", @@ -480,6 +481,7 @@ export function mountConsole(root, host = null) { return ``; }) .join(""); + $("#program").setAttribute("aria-keyshortcuts", "ArrowLeft ArrowRight ArrowUp ArrowDown Backspace"); $("#player-help").textContent = planning ? selected.length ? t( @@ -487,8 +489,8 @@ export function mountConsole(root, host = null) { "Choose a turn for this card.", ) : t( - "Choisissez une carte, puis un tour.", - "Choose a card, then a turn.", + "Cliquez une carte pour remplir le prochain tour. Cliquez un tour rempli pour l’effacer ; Retour arrière annule le dernier ajout.", + "Click a card to fill the next turn. Click a filled turn to clear it; Backspace undoes the last placement.", ) : view.stage === "presence" ? t( @@ -944,6 +946,47 @@ export function mountConsole(root, host = null) { function rerender() { if (view) render(view, true); } + const editableTurns = () => [...root.querySelectorAll("#program [data-turn]:not(:disabled)")] + .filter(button => button.getClientRects().length > 0) + .map(button => Number(button.dataset.turn)); + async function placeCard(turn, cards) { + const owner = crew; + await command("program", { crew: owner, turn, slotVersion: view.game.programs[owner][turn - 1].revision, cards }); + placements.push({ crew: owner, turn, ids: cards.map(c => c.id).join(",") }); + selected = []; + rerender(); + } + const handlePlanningKey = event => { + if (!["Backspace", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key) || event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return; + if (event.target.closest?.("input, textarea, select, [contenteditable]:not([contenteditable=false]), dialog")) return; + if (root.querySelector("dialog[open]")) return; + const editable = editableTurns(); + if (!editable.length) return; + event.preventDefault(); + if (pending || event.repeat) return; + if (event.key !== "Backspace") { + const action = { ArrowLeft: "red", ArrowRight: "blue", ArrowUp: "lift", ArrowDown: "lift" }[event.key]; + const turn = editable.find(n => !view.game.programs[crew][n - 1].cards.length); + const hand = [...(view.game.hand ?? []), ...(view.game.androidCards ?? []).filter(c => c.owner === crew)]; + const card = hand.find(c => c.sides.some(side => side.length === 1 && side[0] === action)); + if (turn !== undefined && card) { + const side = card.sides.findIndex(side => side.length === 1 && side[0] === action); + perform(() => placeCard(turn, [{ id: card.id, side }])); + } + return; + } + const matches = placements.filter(p => p.crew === crew && editable.includes(p.turn) && + view.game.programs[crew][p.turn - 1].cards.map(c => c.id).join(",") === p.ids); + const turn = matches.at(-1)?.turn ?? editable.filter(n => view.game.programs[crew][n - 1].cards.length).at(-1); + if (!turn) return; + event.preventDefault(); + perform(async () => { + await command("remove", { crew, turn, slotVersion: view.game.programs[crew][turn - 1].revision }); + selected = []; + rerender(); + }); + }; + root.ownerDocument.addEventListener("keydown", handlePlanningKey); listenRoot("click", (e) => { const el = e.target.closest("button"); if (host && ["ready-all", "next-event", "open-setup"].includes(el?.id)) @@ -1172,12 +1215,18 @@ export function mountConsole(root, host = null) { ...selected.filter((c) => c.id !== choice.id), choice, ].slice(-2); - else + else { + const turn = editableTurns().find(n => !view.game.programs[crew][n - 1].cards.length); + if (turn !== undefined) { + perform(() => placeCard(turn, [choice])); + return; + } selected = selected.some( (c) => c.id === choice.id && c.side === choice.side, ) ? [] : [choice]; + } rerender(); return; } @@ -1185,12 +1234,8 @@ export function mountConsole(root, host = null) { const turn = Number(el.dataset.turn), slot = view.game.programs[crew][turn - 1]; perform(async () => { - await command(selected.length ? "program" : "remove", { - crew, - turn, - slotVersion: slot.revision, - ...(selected.length ? { cards: selected } : {}), - }); + if (selected.length) await placeCard(turn, selected); + else if (slot.cards.length) await command("remove", { crew, turn, slotVersion: slot.revision }); selected = []; rerender(); }); @@ -1419,6 +1464,7 @@ export function mountConsole(root, host = null) { rerender(); }, destroy() { + root.ownerDocument.removeEventListener("keydown", handlePlanningKey); navigation.destroy(); for (const id of intervals) clearInterval(id); for (const [type, fn] of rootListeners) diff --git a/preview/basics.js b/preview/basics.js index 1bd74ec..06448f2 100644 --- a/preview/basics.js +++ b/preview/basics.js @@ -11,7 +11,7 @@ export function basicsView(view, locale, { started, picked, shipMarkup }) { const control = (id, glyph, description, disabled = false) => ``; if (view.tutorial.nativeStep === 0) return ""; if (playing) return ""; - return `
${pictogram("cards")} ${placed}/2${control("basics-run", "step", t("Exécuter le programme", "Run program"), placed !== 2)}
${t("Préparation", "Planning")}
${control("lesson-clock", view.tutorial.clockRunning ? "pause" : "clock", view.tutorial.clockRunning ? t("Pause", "Pause") : t("Lancer le chrono", "Start clock"))}
`; + return `
←→↑↓⌫
${pictogram("cards")} ${placed}/2${control("basics-run", "step", t("Exécuter le programme", "Run program"), placed !== 2)}
${t("Préparation", "Planning")}
${control("lesson-clock", view.tutorial.clockRunning ? "pause" : "clock", view.tutorial.clockRunning ? t("Pause", "Pause") : t("Lancer le chrono", "Start clock"))}
`; } const intro = !started && !placed && !playing; const ready = placed === 2; diff --git a/preview/style.css b/preview/style.css index 52d7e9e..b566f20 100644 --- a/preview/style.css +++ b/preview/style.css @@ -2408,3 +2408,6 @@ input:not([type="checkbox"]):not([type="range"]) { min-height: 68px; width: 100%; } + +.planning-shortcuts { display: flex; gap: 6px; margin-top: 12px; color: var(--muted); } +.planning-shortcuts kbd { min-width: 25px; text-align: center; padding: 2px 5px; border: 1px solid var(--line); border-radius: 4px; font: inherit; font-size: 12px; }