From bfbcf25275c0f2d6d9d7b6fc8bd1e13dcb8bb179 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Mon, 12 Oct 2026 22:58:23 +0200 Subject: [PATCH] Unify role cards and show recruitment previews and inline warnings --- test/browser.mjs | 12 ++++++++ test/recruitment-preview.test.js | 21 +++++++++++++ viewer/recruitment.js | 16 ++++++++++ viewer/style.css | 50 ++++++++++++++++++++++--------- viewer/ui.js | 51 ++++++++++++++++---------------- 5 files changed, 110 insertions(+), 40 deletions(-) create mode 100644 test/recruitment-preview.test.js create mode 100644 viewer/recruitment.js diff --git a/test/browser.mjs b/test/browser.mjs index cdf1d7f..bb34861 100644 --- a/test/browser.mjs +++ b/test/browser.mjs @@ -366,6 +366,18 @@ try { () => document.documentElement.scrollWidth > innerWidth + 1, ); assert.equal(await overflow(), false, `No page overflow at ${width}`); + await page.locator(".action-dock [data-actions]").click(); + assert.ok(await page.locator(".role-picker .role").count() > 0); + assert.ok(await page.locator(".role-choice-warning").count() > 0); + assert.equal(await page.locator(".recruitment-shares > span").count(), original.players.length); + assert.equal( + await page.locator('.role-picker [data-role-id="recruiter"]').innerHTML(), + await page.locator('.shared-board [data-role-id="recruiter"]').innerHTML(), + "role picker reuses board role cards", + ); + assert.equal(await overflow(), false); + await page.screenshot({ path: `.local/qa/${width}-role-picker.png` }); + await page.keyboard.press("Escape"); const craftsman = page.locator('[data-role-id="craftsman"]'); assert.equal(await craftsman.locator(".role-warning").count(), 1); await craftsman.click(); diff --git a/test/recruitment-preview.test.js b/test/recruitment-preview.test.js new file mode 100644 index 0000000..5aeb5f6 --- /dev/null +++ b/test/recruitment-preview.test.js @@ -0,0 +1,21 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { recruitmentShares, recruitmentBonus } from "../viewer/recruitment.js"; + +test("recruitment preview distributes the mixed register starting at the chooser", () => { + const state = { + players: Array.from({ length: 3 }, () => ({ buildings: [] })), + register: { w: 3, c: 2 }, + workerSupply: 10, + }; + assert.deepEqual(recruitmentShares(state, 1), [1, 2, 2]); + assert.equal(recruitmentBonus(state, 1), 1); + state.players[1].buildings.push({ id: "publishingHouse", w: 1, c: 0 }); + assert.equal(recruitmentBonus(state, 1), 2); + state.workerSupply = 1; + assert.equal(recruitmentBonus(state, 1), 1); + state.workerSupply = 0; + assert.equal(recruitmentBonus(state, 1), 0); + state.register = { w: 0, c: 0 }; + assert.deepEqual(recruitmentShares(state, 1), [0, 0, 0]); +}); diff --git a/viewer/recruitment.js b/viewer/recruitment.js new file mode 100644 index 0000000..c799913 --- /dev/null +++ b/viewer/recruitment.js @@ -0,0 +1,16 @@ +// Distribution from the work register, before optional building/role bonuses. +export function recruitmentShares(state, chooser) { + const total = state.register.w + state.register.c; + const n = state.players.length; + return state.players.map( + (_, i) => + Math.floor(total / n) + ((i - chooser + n) % n < total % n ? 1 : 0), + ); +} + +export function recruitmentBonus(state, chooser) { + const publishing = state.players[chooser].buildings.some( + (b) => b.id === "publishingHouse" && b.w + b.c > 0, + ); + return Math.min(state.workerSupply, publishing ? 2 : 1); +} diff --git a/viewer/style.css b/viewer/style.css index f4e0d13..e85c550 100644 --- a/viewer/style.css +++ b/viewer/style.css @@ -496,20 +496,6 @@ body:has(.pr-game) { color: var(--muted); font-size: 12px; } -.pr-game .coin-badge { - position: absolute; - right: -12px; - top: -5px; - background: #e4bd6c; - color: #423212; - border-radius: 50%; - font-size: 11px; - font-weight: bold; - min-width: 19px; - height: 19px; - display: grid; - place-items: center; -} .pr-game .role small { max-width: 100%; overflow: hidden; @@ -2791,3 +2777,39 @@ body:has(.pr-game) { align-items: center; gap: 5px; } + +.pr-game .role-coins { + position: absolute; + inset-inline-start: calc(100% - 5px); + top: -4px; + white-space: nowrap; + font-weight: bold; +} +.pr-game .role-coins .metric { gap: 1px; } +.pr-game .role-coins .icon { width: 16px; height: 16px; } +.pr-game .role-recruits { font-size: 11px; } +.pr-game .role-recruits .icon { width: 15px; height: 15px; } +.pr-game .role-picker { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: auto; align-items: start; } +.pr-game .role-choice { min-width: 0; } +.pr-game .role-choice > .role { width: 100%; min-height: 82px; } +.pr-game .role-choice-warning { + font-size: 12px; + line-height: 1.4; + margin: 8px 0 0; + overflow-wrap: anywhere; +} +.pr-game .role-choice-warning > .icon { margin-inline-end: 4px; vertical-align: middle; } +.pr-game .recruitment-preview { border-top: 1px solid var(--line); padding-top: 12px; } +.pr-game .recruitment-preview h3 { display: flex; align-items: center; gap: 6px; } +.pr-game .recruitment-shares { display: flex; flex-wrap: wrap; gap: 8px 16px; } +.pr-game .recruitment-shares > span { display: flex; align-items: center; gap: 6px; min-width: 0; } +.pr-game .recruitment-shares b { overflow-wrap: anywhere; } +.pr-game .recruitment-preview p { font-size: 12px; margin-bottom: 0; } +@media (max-width: 600px) { + .pr-game .role-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); } +} +.pr-game .role-recruits, .pr-game .recruitment-count, .pr-game .role-recruits > span { + display: inline-flex; + align-items: center; + gap: 2px; +} diff --git a/viewer/ui.js b/viewer/ui.js index 59c5fed..cac6fdb 100644 --- a/viewer/ui.js +++ b/viewer/ui.js @@ -1,3 +1,4 @@ +import { recruitmentShares, recruitmentBonus } from "./recruitment.js"; import { showBuildingPayment } from "./building-payment.js"; import { FORCE_DARK_THEME } from "./theme.js"; import { mergePreferences, imageUrl } from "./platform.js"; @@ -437,17 +438,7 @@ export function mountGame( function actionButton(m) { if (m.type === "produce") return `${moveButton(m, moveLabel(m), "craftsman", "primary")}`; - if (m.type === "role") { - const role = state.roles.find((r) => r.id === m.id); - const warning = state.roleWarnings?.[m.id]; - return moveButton( - m, - `${t(m.id)}${role.coins ? metric("coin", role.coins) : ""}${warning ? icon("warning", 18) : ""}`, - m.id === "adventurer2" ? "adventurer" : m.id, - "", - warning ? `${t(m.id)} — ${t(warning.reason)}` : "", - ); - } + if (m.type === "role") return roleCard(state.roles.find((r) => r.id === m.id)); const compact = compactAction(m); return compact ? moveButton(m, compact[0], null, "compact-action", compact[1]) @@ -477,6 +468,8 @@ export function mountGame( if (!allowed()) return ""; const task = state.tasks[0], moves = actionMoves(); + if (task.kind === "role") + return `
${moves.map((m) => `
${actionButton(m)}${state.roleWarnings?.[m.id] ? `

${icon("warning", 15)}${esc([...new Intl.Segmenter(t.locale, { granularity: "sentence" }).segment(t(state.roleWarnings[m.id].reason))][0].segment)}

` : ""}
`).join("")}
${moves.some((m) => m.id === "recruiter") ? recruitmentPreview() : ""}`; if (["achievementChoose", "achievementDraft"].includes(task.kind)) return `

${t(task.kind)} · ${state.players[seat].achievements.length}/4

${moves .map((m) => { @@ -614,25 +607,31 @@ export function mountGame( function plantationHelp(id) { return `${t(id)} — ${t(id === "quarry" ? "quarryHelp" : id === "forest" ? "forestHelp" : id === "corn" ? "cornHelp" : "plantationHelp")}`; } + function recruitmentCount(n) { + return `${icon(!state.register.w && state.register.c ? "citizen" : "worker", 16)}${state.register.w && state.register.c ? icon("citizen", 16) : ""}${n}`; + } + function roleCard(r) { + const m = state.legal.find((m) => m.type === "role" && m.id === r.id), + selected = r.taken !== null, + current = !state.finished && state.tasks[0]?.kind !== "role" && + r.id === (state.role === "adventurer" + ? state.events.filter((e) => e.type === "role").at(-1)?.id : state.role), + acting = allowed(), + warning = m && acting ? state.roleWarnings?.[r.id] : null; + return ``; + } + function recruitmentPreview() { + const shares = recruitmentShares(state, seat); + const owner = state.players[seat]; + const bonus = recruitmentBonus(state, seat); + return `

${icon("recruiter", 20)}${t("recruitmentPool")}

${state.players.map((p, i) => `${playerMarker(i, true)}${esc(p.name)}${recruitmentCount(shares[i])}`).join("")}
${bonus ? `

${t("privilege")} · ${esc(owner.name)} +${metric("worker", bonus)}

` : ""}
`; + } function sharedBoard() { const festivalTag = desktopLayout.matches ? "section" : "details"; const festivalHeadingTag = desktopLayout.matches ? "header" : "summary"; - const acting = allowed(), - task = state.tasks[0]; - const currentRole = - !state.finished && task && task.kind !== "role" - ? state.role === "adventurer" - ? state.events.filter((e) => e.type === "role").at(-1)?.id - : state.role - : null; + const acting = allowed(), task = state.tasks[0]; return `
${state.roles - .map((r) => { - const m = state.legal.find((m) => m.type === "role" && m.id === r.id), - selected = r.taken !== null, - current = r.id === currentRole, - warning = m && acting ? state.roleWarnings?.[r.id] : null; - return ``; - }) + .map(roleCard) .join( "", )}
${icon("recruiter", 20)}${t("recruitmentPool")}${metric("worker", state.register.w, "registerWorkers")}${state.register.c ? metric("citizen", state.register.c, "registerCitizens") : ""}

${t("harborTitle")}

${metric("vp", Math.max(0, state.vpSupply), "vpSupply")}
${t("goodsSupply")}${GOODS.map((g) => `${metric(g, state.supply[g])}`).join("")}
${state.ships.map((sh, i) => `
${shipGraphic(sh)}
${sh.good ? icon(sh.good, 25) : icon("ship", 25)}${sh.amount} / ${sh.capacity}
`).join("")}
${icon("trader", 18)} ${t("tradingHouse")}${Array.from({ length: 4 }, (_, i) => `${state.trade[i] ? icon(state.trade[i], 26) : "·"}`).join("")}
${icon("planter", 20)}

${t("plantedOffer")}

${state.offer