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 `
${icon("warning", 15)}${esc([...new Intl.Segmenter(t.locale, { granularity: "sentence" }).segment(t(state.roleWarnings[m.id].reason))][0].segment)}
` : ""}${t(task.kind)} · ${state.players[seat].achievements.length}/4
${t("privilege")} · ${esc(owner.name)} +${metric("worker", bonus)}
` : ""}