From 99222d9d9b418b21d7032d2062a512e967b94dea Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Sat, 31 Oct 2026 18:25:03 +0100 Subject: [PATCH] Confirm role selection in the action bar before submitting --- test/browser.mjs | 13 +++++++++++-- viewer/style.css | 5 +++++ viewer/ui.js | 29 +++++++++++++---------------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/test/browser.mjs b/test/browser.mjs index f5e2dd3..a1499e1 100644 --- a/test/browser.mjs +++ b/test/browser.mjs @@ -383,12 +383,20 @@ try { assert.equal(await overflow(), false); await page.screenshot({ path: `.local/qa/${width}-role-picker.png` }); await page.keyboard.press("Escape"); + // Even safe roles require confirmation; cancelling must not submit a move. + await page.locator('.shared-board [data-role-id="recruiter"]').click(); + assert.equal(await page.locator(".action-dock [data-confirm-role]").count(), 1); + assert.equal(await page.locator("dialog[open]").count(), 0); + assert.deepEqual(await page.evaluate(() => played), []); + await page.locator("[data-cancel-role]").click(); + assert.deepEqual(await page.evaluate(() => played), []); const craftsman = page.locator('[data-role-id="craftsman"]'); assert.equal(await craftsman.locator(".role-warning").count(), 1); await craftsman.click(); - assert.equal(await page.locator("[data-confirm-role]").count(), 1); + assert.equal(await page.locator(".action-dock [data-confirm-role]").count(), 1); + assert.equal(await page.locator("dialog[open]").count(), 0); assert.deepEqual(await page.evaluate(() => played), []); - await page.locator(".modal-body [data-close]").click(); + await page.locator("[data-cancel-role]").click(); assert.deepEqual(await page.evaluate(() => played), []); await craftsman.click(); // A newer game state invalidates an open warning; it must not send a stale choice. @@ -422,6 +430,7 @@ try { `.pr-modal [data-move="${encodeURIComponent(JSON.stringify(m))}"]`, ) .click(); + await page.locator(".action-dock [data-confirm-role]").click(); assert.deepEqual(await page.evaluate(() => played.at(-1)), m); let s = E.move(original, m, 0); while (s.tasks[0].kind !== "recruit") s = E.moveAI(s); diff --git a/viewer/style.css b/viewer/style.css index 6797bbd..ed894cb 100644 --- a/viewer/style.css +++ b/viewer/style.css @@ -2875,3 +2875,8 @@ body:has(.pr-game) { .pr-game .vp-supply-status { display: flex; align-items: center; justify-content: flex-end; gap: 8px; } .pr-game .final-round-badge { color: #f0ca79; background: #e1b25a1a; border-radius: 5px; padding: 4px 7px; font-size: 12px; font-weight: 600; white-space: nowrap; } + +.pr-game .role.role-pending { + outline: 2px solid var(--gold); + outline-offset: -2px; +} diff --git a/viewer/ui.js b/viewer/ui.js index 33df08c..d7f66a3 100644 --- a/viewer/ui.js +++ b/viewer/ui.js @@ -705,7 +705,7 @@ export function mountGame( : state.role), acting = allowed(), warning = m && acting ? state.roleWarnings?.[r.id] : null; - return ``; + return ``; } function recruitmentPreview() { const shares = recruitmentShares(state, seat); @@ -869,6 +869,11 @@ export function mountGame( function bottom() { if (state.finished) return `
${t("finished")}
`; + if (roleConfirmation && isTurn()) { + const m = roleConfirmation.move; + const warning = state.roleWarnings?.[m.id]; + return `
${icon(m.id, 26)}${t(m.id)}${warning ? `${icon("warning", 16)} ${t.html(warning.reason)}` : ""}
`; + } const can = isTurn(), task = state.tasks[0], pass = state.legal.find((m) => m.type === "pass" && !m.decline?.length); @@ -1102,22 +1107,9 @@ export function mountGame( }${id === "recruiter" ? `

${t("ruleWorkerPool")}

` : ""}${id === "trader" ? `
${t("baseSalePrices")}
${GOODS.map((good, price) => `${icon(good, 22)}${icon("arrow", 14)}${metric("coin", price)}`).join("")}
` : ""}${privilege ? `
${t(solo ? "roleNote" : "privilege")}

${t.rolePrivilegeHtml(id)}

` : ""}`; } function confirmRole(m) { - const warning = state.roleWarnings?.[m.id]; - if (!warning) return false; - show( - t("roleWarningTitle"), - ` -
${icon(m.id, 36)}${t(m.id)}
-

${t.html(warning.reason)}

- ${warning.coins ? `

${t("roleCoinsStill")} ${metric("coin", warning.coins)}

` : ""} - ${warning.bonuses.length ? `
${t("roleBonusesStill")}${warning.bonuses.map((b) => `
${t(b.building)} ${b.coins ? metric("coin", b.coins) : ""}${b.vp ? metric("vp", b.vp) : ""}
`).join("")}
` : ""} - ${m.id !== "smuggler" ? `

${t("roleWarningOthers")}

` : ""} -
- `, - "role-warning", - ); + hide(modal); roleConfirmation = { move: m, seat, historyLength: state.historyLength }; - body.querySelector("[data-close]").focus(); + render(); return true; } function rolesHelp() { @@ -1468,6 +1460,11 @@ export function mountGame( ) ) return; + if (el.hasAttribute("data-cancel-role")) { + roleConfirmation = null; + render(); + return; + } if (el.hasAttribute("data-confirm-role")) { const confirmation = roleConfirmation; if (