Add mobile board player tabs and resource summary
This commit is contained in:
parent
8001dce5e1
commit
12b6e4a15e
4 changed files with 449 additions and 15 deletions
185
test/browser.mjs
185
test/browser.mjs
|
|
@ -77,7 +77,10 @@ try {
|
|||
(s) => host.emit("state", s),
|
||||
E.stripSecret(original, 0),
|
||||
);
|
||||
const idleSlot = await page.locator("span.worker-slot").first().boundingBox();
|
||||
const idleSlot = await page
|
||||
.locator("span.worker-slot")
|
||||
.first()
|
||||
.boundingBox();
|
||||
assert.equal(idleSlot.width, 32);
|
||||
assert.equal(idleSlot.height, 32);
|
||||
await page.locator('.offer[data-plantation-info="quarry"]').click();
|
||||
|
|
@ -248,6 +251,14 @@ try {
|
|||
resourceCards.players[0].goods.corn = 2;
|
||||
resourceCards.players[0].reserve = { w: 2, c: 1 };
|
||||
resourceCards.players[1].goods.sugar = 3;
|
||||
resourceCards.players[1].goods.coffee = 1;
|
||||
resourceCards.players[1].coins = 7;
|
||||
resourceCards.players[1].reserve = { w: 3, c: 2 };
|
||||
resourceCards.players[1].estates = [
|
||||
{ id: "fruit", w: 1, c: 0 },
|
||||
{ id: "tobacco", w: 0, c: 0 },
|
||||
];
|
||||
resourceCards.players[1].buildings = [{ id: "smallFruit", w: 1, c: 0 }];
|
||||
await page.evaluate(
|
||||
(s) => host.emit("state", s),
|
||||
E.stripSecret(resourceCards, 0),
|
||||
|
|
@ -274,11 +285,11 @@ try {
|
|||
.boundingBox();
|
||||
assert.equal(reserveBox.y, goodsBox.y, "reserve shares the stock row");
|
||||
}
|
||||
assert.equal(
|
||||
assert.deepEqual(
|
||||
await page
|
||||
.locator('.player-strip [data-player="1"] .player-card-goods .metric')
|
||||
.innerText(),
|
||||
"3",
|
||||
.allTextContents(),
|
||||
["3", "1"],
|
||||
);
|
||||
assert.equal(
|
||||
await page
|
||||
|
|
@ -286,7 +297,131 @@ try {
|
|||
.count(),
|
||||
0,
|
||||
);
|
||||
assert.equal(await page.locator(".player-board .inventory").count(), 0);
|
||||
// Inspect another board without returning to the top player strip.
|
||||
const boardTabs = page.locator(".board-player-tabs");
|
||||
const boardTab = (seat) =>
|
||||
boardTabs.locator(`button[data-board-player="${seat}"]`);
|
||||
assert.equal(await boardTabs.getAttribute("role"), "group");
|
||||
assert.equal(await boardTabs.getAttribute("aria-label"), "Joueurs");
|
||||
assert.equal(await boardTabs.getByRole("button").count(), 3);
|
||||
assert.deepEqual(
|
||||
await boardTabs.locator("button").evaluateAll((buttons) =>
|
||||
buttons.map((button) => ({
|
||||
name: button.querySelector(":scope > span:last-child").textContent,
|
||||
title: button.title,
|
||||
pressed: button.getAttribute("aria-pressed"),
|
||||
markers: button.querySelectorAll(".player-marker").length,
|
||||
})),
|
||||
),
|
||||
resourceCards.players.map((p, seat) => ({
|
||||
name: p.name,
|
||||
title: p.name,
|
||||
pressed: String(seat === 0),
|
||||
markers: 1,
|
||||
})),
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator(".player-board").getAttribute("aria-label"),
|
||||
resourceCards.players[0].name,
|
||||
);
|
||||
await page.evaluate(() => {
|
||||
const board = document.querySelector(".player-board");
|
||||
scrollTo(0, scrollY + board.getBoundingClientRect().top - 100);
|
||||
});
|
||||
const beforeSwitch = await page.evaluate(() => scrollY);
|
||||
const beforeInspect = await page.evaluate(() => played.length);
|
||||
await boardTab(1).click();
|
||||
assert.equal(await boardTab(1).getAttribute("aria-pressed"), "true");
|
||||
assert.equal(await boardTab(0).getAttribute("aria-pressed"), "false");
|
||||
assert.equal(
|
||||
await page.locator(".player-board").getAttribute("aria-label"),
|
||||
resourceCards.players[1].name,
|
||||
);
|
||||
assert.ok(
|
||||
Math.abs((await page.evaluate(() => scrollY)) - beforeSwitch) < 2,
|
||||
"switching at the board preserves scrolling position",
|
||||
);
|
||||
assert.equal(await page.locator('[data-player="1"].selected').count(), 1);
|
||||
assert.deepEqual(
|
||||
await page.locator(".board-player-resources > .metric").allTextContents(),
|
||||
["7", "3", "2"],
|
||||
"board resources belong to the selected player",
|
||||
);
|
||||
assert.deepEqual(
|
||||
await page.locator(".board-player-goods .metric").allTextContents(),
|
||||
["0", "0", "3", "0", "1"],
|
||||
"all stock types are visible, including zeroes",
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator(".board-player-resources .score-hidden").count(),
|
||||
1,
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator(".board-player-resources [data-score]").count(),
|
||||
0,
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator('.player-board [data-building="smallFruit"]').count(),
|
||||
1,
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator(".player-board .estate.tobacco").count(),
|
||||
1,
|
||||
);
|
||||
assert.equal(
|
||||
await boardTab(1).evaluate((el) => el === document.activeElement),
|
||||
true,
|
||||
);
|
||||
if (width <= 760) {
|
||||
assert.ok(
|
||||
(await page.locator(".player-summary").innerText()).includes(
|
||||
resourceCards.players[0].name,
|
||||
),
|
||||
);
|
||||
await page.screenshot({
|
||||
path: `.local/qa/${width}-board-player-switcher.png`,
|
||||
});
|
||||
}
|
||||
// Live updates must not reset the board under inspection.
|
||||
resourceCards.players[1].goods.coffee = 2;
|
||||
await page.evaluate(
|
||||
(s) => host.emit("state", s),
|
||||
E.stripSecret(resourceCards, 0),
|
||||
);
|
||||
assert.equal(await boardTab(1).getAttribute("aria-pressed"), "true");
|
||||
assert.deepEqual(
|
||||
await page.locator(".board-player-goods .metric").allTextContents(),
|
||||
["0", "0", "3", "0", "2"],
|
||||
);
|
||||
assert.ok(
|
||||
Math.abs((await page.evaluate(() => scrollY)) - beforeSwitch) < 2,
|
||||
"live updates preserve scrolling position",
|
||||
);
|
||||
// These are ordinary toggle buttons: Tab moves focus, Enter selects a board.
|
||||
await boardTab(1).focus();
|
||||
await page.keyboard.press("Tab");
|
||||
assert.equal(
|
||||
await boardTab(2).evaluate((el) => el === document.activeElement),
|
||||
true,
|
||||
);
|
||||
assert.equal(await boardTab(1).getAttribute("aria-pressed"), "true");
|
||||
await page.keyboard.press("Enter");
|
||||
assert.equal(await boardTab(2).getAttribute("aria-pressed"), "true");
|
||||
assert.equal(await boardTabs.locator('[aria-pressed="true"]').count(), 1);
|
||||
assert.ok(
|
||||
Math.abs((await page.evaluate(() => scrollY)) - beforeSwitch) < 2,
|
||||
"keyboard board switching preserves scrolling position",
|
||||
);
|
||||
await boardTab(0).click();
|
||||
assert.equal(await page.evaluate(() => played.length), beforeInspect);
|
||||
assert.equal(
|
||||
await page.locator('.board-player-resources [data-score="0"]').count(),
|
||||
1,
|
||||
);
|
||||
assert.deepEqual(
|
||||
await page.locator(".board-player-goods .metric").allTextContents(),
|
||||
["2", "0", "0", "0", "0"],
|
||||
);
|
||||
const scoreState = structuredClone(resourceCards);
|
||||
scoreState.players[0].vp = 4;
|
||||
scoreState.players[0].buildings = [{ id: "smallSugar", w: 0, c: 0 }];
|
||||
|
|
@ -306,6 +441,11 @@ try {
|
|||
0,
|
||||
);
|
||||
await page.locator('[data-player="1"] .player-name').click();
|
||||
assert.equal(
|
||||
await boardTab(1).getAttribute("aria-pressed"),
|
||||
"true",
|
||||
"top strip also updates the board tabs",
|
||||
);
|
||||
await page.locator('.player-strip [data-score="0"]').press("Enter");
|
||||
assert.equal(await page.locator(".score-detail").count(), 1);
|
||||
assert.match(
|
||||
|
|
@ -557,8 +697,16 @@ try {
|
|||
await page.evaluate((s) => host.emit("state", s), E.stripSecret(s, 0));
|
||||
await page.locator("[data-confirm-assign]").waitFor({ state: "visible" });
|
||||
const activeSlot = await page.locator("[data-slot]").first().boundingBox();
|
||||
assert.equal(activeSlot.width, idleSlot.width, "placement keeps slot width");
|
||||
assert.equal(activeSlot.height, idleSlot.height, "placement keeps slot height");
|
||||
assert.equal(
|
||||
activeSlot.width,
|
||||
idleSlot.width,
|
||||
"placement keeps slot width",
|
||||
);
|
||||
assert.equal(
|
||||
activeSlot.height,
|
||||
idleSlot.height,
|
||||
"placement keeps slot height",
|
||||
);
|
||||
const reserveCount = page.locator(
|
||||
'.player-strip [data-player="0"] .player-card-reserve .metric',
|
||||
);
|
||||
|
|
@ -578,6 +726,29 @@ try {
|
|||
"0",
|
||||
"the card follows the draft allocation",
|
||||
);
|
||||
assert.equal(
|
||||
await page
|
||||
.locator('.board-player-resources > .metric[title^="Ouvriers"]')
|
||||
.innerText(),
|
||||
"0",
|
||||
);
|
||||
const movesBeforeBoardSwitch = await page.evaluate(() => played.length);
|
||||
await boardTab(1).click();
|
||||
assert.equal(
|
||||
await page.locator(".player-board [data-slot]").count(),
|
||||
0,
|
||||
"opponent slots stay read-only",
|
||||
);
|
||||
await boardTab(0).click();
|
||||
assert.equal(
|
||||
await page.locator('[data-slot="e0:0"].w').count(),
|
||||
1,
|
||||
"inspection preserves unfinished placement",
|
||||
);
|
||||
assert.equal(
|
||||
await page.evaluate(() => played.length),
|
||||
movesBeforeBoardSwitch,
|
||||
);
|
||||
assert.equal(
|
||||
await page
|
||||
.locator('[data-production-good="corn"] .production-output')
|
||||
|
|
|
|||
|
|
@ -25,6 +25,17 @@ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|||
const browser = await chromium.launch();
|
||||
const errors = [];
|
||||
let state = engine.init(5, [], {}, "locale-mobile");
|
||||
const playerNames = [
|
||||
"María Fernanda de la Cruz",
|
||||
"Alexandria Montgomery-Wellington",
|
||||
"Nguyễn Thị Minh Phương",
|
||||
"نام طولانی بازیکن چهارم",
|
||||
'Long player name <&> "five"',
|
||||
];
|
||||
state.players.forEach((player, seat) => {
|
||||
player.name = playerNames[seat];
|
||||
});
|
||||
state.players[4].goods.corn = 1;
|
||||
state = engine.stripSecret(state, 0);
|
||||
const page = await browser.newPage({
|
||||
viewport: { width: 320, height: 640 },
|
||||
|
|
@ -37,6 +48,8 @@ try {
|
|||
await page.goto(`http://127.0.0.1:${server.address().port}`);
|
||||
await page.evaluate((s) => {
|
||||
window.host = puertorico.launch("#game");
|
||||
window.played = [];
|
||||
host.on("move", (move) => played.push(move));
|
||||
host.emit("player", { index: 0 });
|
||||
host.emit("avatars", ["/avatar.svg", "/avatar.svg"]);
|
||||
host.emit("preferences", {
|
||||
|
|
@ -103,6 +116,20 @@ try {
|
|||
`${label}: dialog width`,
|
||||
);
|
||||
};
|
||||
const boardTabs = page.locator(".board-player-tabs");
|
||||
const boardTab = (seat) =>
|
||||
boardTabs.locator(`button[data-board-player="${seat}"]`);
|
||||
const tabFullyVisible = (tab) =>
|
||||
tab.evaluate((button) => {
|
||||
const row = button.parentElement;
|
||||
const rowBounds = row.getBoundingClientRect();
|
||||
const tabBounds = button.getBoundingClientRect();
|
||||
const left = rowBounds.left + row.clientLeft;
|
||||
return (
|
||||
tabBounds.left >= left - 1 &&
|
||||
tabBounds.right <= left + row.clientWidth + 1
|
||||
);
|
||||
});
|
||||
for (const locale of supportedLocales) {
|
||||
await page.evaluate((locale) => {
|
||||
host.emit("preferences", { locale, colorBlind: true });
|
||||
|
|
@ -115,6 +142,74 @@ try {
|
|||
locale === "fa" ? "rtl" : "ltr",
|
||||
);
|
||||
await fits(`${locale}: five-player board`);
|
||||
assert.equal(await boardTabs.getAttribute("role"), "group");
|
||||
assert.equal(await boardTabs.getAttribute("aria-label"), t("players"));
|
||||
assert.equal(await boardTabs.getByRole("button").count(), 5);
|
||||
assert.equal(await boardTab(0).getAttribute("aria-pressed"), "true");
|
||||
assert.ok(
|
||||
await boardTabs.evaluate((row) => row.scrollWidth > row.clientWidth),
|
||||
`${locale}: five long names scroll within the tab row`,
|
||||
);
|
||||
const rowBox = await boardTabs.boundingBox();
|
||||
for (let seat = 0; seat < playerNames.length; seat++) {
|
||||
const tab = boardTab(seat);
|
||||
assert.equal(await tab.getAttribute("title"), playerNames[seat]);
|
||||
assert.equal(
|
||||
await tab.locator(":scope > span:last-child").textContent(),
|
||||
playerNames[seat],
|
||||
);
|
||||
assert.equal(await tab.locator(".player-marker").count(), 1);
|
||||
const tabBox = await tab.boundingBox();
|
||||
assert.ok(tabBox.height >= 44, `${locale}: touch-sized player tab`);
|
||||
assert.ok(tabBox.width >= 88, `${locale}: player name remains readable`);
|
||||
const clearance = rowBox.y + rowBox.height - tabBox.y - tabBox.height;
|
||||
assert.ok(
|
||||
clearance >= 2 - 1 && clearance <= 7,
|
||||
`${locale}: compact scrollbar clearance below the tab border`,
|
||||
);
|
||||
}
|
||||
await boardTab(4).click();
|
||||
assert.equal(await boardTab(4).getAttribute("aria-pressed"), "true");
|
||||
assert.equal(await boardTabs.locator('[aria-pressed="true"]').count(), 1);
|
||||
assert.equal(
|
||||
await page.locator(".player-board").getAttribute("aria-label"),
|
||||
state.players[4].name,
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator('.player-strip [data-player="4"].selected').count(),
|
||||
1,
|
||||
);
|
||||
assert.equal(await page.locator(".board-player-goods .metric").count(), 5);
|
||||
assert.ok(
|
||||
await tabFullyVisible(boardTab(4)),
|
||||
`${locale}: selected fifth tab is fully visible`,
|
||||
);
|
||||
// Force the selected tab offscreen and return to the page top. Rendering
|
||||
// must reveal it within the row without bringing the board into view.
|
||||
await boardTabs.evaluate((row) => {
|
||||
row.scrollLeft = 0;
|
||||
scrollTo(0, 0);
|
||||
});
|
||||
assert.equal(await tabFullyVisible(boardTab(4)), false);
|
||||
const beforeRender = await page.evaluate(() => scrollY);
|
||||
state.players[4].goods.corn++;
|
||||
await page.evaluate((s) => host.emit("state", s), state);
|
||||
assert.ok(
|
||||
await tabFullyVisible(boardTab(4)),
|
||||
`${locale}: rendering reveals the selected fifth tab`,
|
||||
);
|
||||
assert.ok(
|
||||
Math.abs((await page.evaluate(() => scrollY)) - beforeRender) < 2,
|
||||
`${locale}: rendering the selected tab never scrolls the page`,
|
||||
);
|
||||
assert.equal(await boardTab(4).getAttribute("aria-pressed"), "true");
|
||||
assert.equal(
|
||||
await page.locator(".board-player-goods .metric").first().innerText(),
|
||||
String(state.players[4].goods.corn),
|
||||
);
|
||||
await fits(`${locale}: long selected player name`);
|
||||
await boardTab(0).click();
|
||||
assert.deepEqual(await page.evaluate(() => played), []);
|
||||
for (const selector of [".festival-section", ".production-overview"]) {
|
||||
assert.equal(
|
||||
await page.locator(selector).getAttribute("open"),
|
||||
|
|
@ -167,7 +262,7 @@ try {
|
|||
scrollTo(0, 0);
|
||||
});
|
||||
const session = await page.context().newCDPSession(page);
|
||||
const swipe = async (x, y, distance) => {
|
||||
const swipe = async (x, y, dx, dy) => {
|
||||
await session.send("Input.dispatchTouchEvent", {
|
||||
type: "touchStart",
|
||||
touchPoints: [{ x, y }],
|
||||
|
|
@ -175,7 +270,7 @@ try {
|
|||
for (let step = 1; step <= 8; step++) {
|
||||
await session.send("Input.dispatchTouchEvent", {
|
||||
type: "touchMove",
|
||||
touchPoints: [{ x, y: y - (distance * step) / 8 }],
|
||||
touchPoints: [{ x: x + (dx * step) / 8, y: y + (dy * step) / 8 }],
|
||||
});
|
||||
await page.waitForTimeout(20);
|
||||
}
|
||||
|
|
@ -185,14 +280,82 @@ try {
|
|||
});
|
||||
await page.waitForTimeout(100);
|
||||
};
|
||||
const disabled = page.locator('.offer[data-plantation-info]').first();
|
||||
for (const locale of ["fr", "fa"]) {
|
||||
await page.evaluate((locale) => {
|
||||
host.emit("preferences", { locale });
|
||||
const row = document.querySelector(".board-player-tabs");
|
||||
row.scrollLeft = 0;
|
||||
scrollTo(0, scrollY + row.getBoundingClientRect().top - 260);
|
||||
}, locale);
|
||||
await page.waitForTimeout(100);
|
||||
const rowBox = await boardTabs.boundingBox();
|
||||
const beforeSwipe = await page.evaluate(() => ({
|
||||
y: scrollY,
|
||||
left: document.querySelector(".board-player-tabs").scrollLeft,
|
||||
selected: document.querySelector(
|
||||
'.board-player-tabs [aria-pressed="true"]',
|
||||
).dataset.boardPlayer,
|
||||
moves: played.length,
|
||||
}));
|
||||
const rtl = locale === "fa";
|
||||
await swipe(
|
||||
rowBox.x + (rtl ? 20 : rowBox.width - 20),
|
||||
rowBox.y + rowBox.height / 2,
|
||||
(rowBox.width - 40) * (rtl ? 1 : -1),
|
||||
0,
|
||||
);
|
||||
assert.ok(
|
||||
Math.abs(
|
||||
(await boardTabs.evaluate((row) => row.scrollLeft)) - beforeSwipe.left,
|
||||
) > 40,
|
||||
`${locale}: a native horizontal swipe scrolls the player tabs`,
|
||||
);
|
||||
assert.equal(
|
||||
await boardTabs
|
||||
.locator('[aria-pressed="true"]')
|
||||
.getAttribute("data-board-player"),
|
||||
beforeSwipe.selected,
|
||||
`${locale}: swiping does not select a different board`,
|
||||
);
|
||||
assert.equal(await page.evaluate(() => played.length), beforeSwipe.moves);
|
||||
assert.ok(
|
||||
Math.abs((await page.evaluate(() => scrollY)) - beforeSwipe.y) < 2,
|
||||
`${locale}: horizontal swiping does not move the page vertically`,
|
||||
);
|
||||
await fits(`${locale}: horizontally scrolled tabs`);
|
||||
await page.waitForTimeout(200);
|
||||
const beforeVerticalSwipe = await page.evaluate(() => scrollY);
|
||||
await swipe(
|
||||
rowBox.x + rowBox.width / 2,
|
||||
rowBox.y + rowBox.height / 2,
|
||||
0,
|
||||
-160,
|
||||
);
|
||||
assert.ok(
|
||||
(await page.evaluate(() => scrollY)) > beforeVerticalSwipe,
|
||||
`${locale}: player tabs still allow native vertical page scrolling`,
|
||||
);
|
||||
assert.equal(
|
||||
await boardTabs
|
||||
.locator('[aria-pressed="true"]')
|
||||
.getAttribute("data-board-player"),
|
||||
beforeSwipe.selected,
|
||||
);
|
||||
assert.equal(await page.evaluate(() => played.length), beforeSwipe.moves);
|
||||
}
|
||||
await page.evaluate(() => {
|
||||
host.emit("preferences", { locale: "fr" });
|
||||
scrollTo(0, 0);
|
||||
});
|
||||
const disabled = page.locator(".offer[data-plantation-info]").first();
|
||||
await disabled.scrollIntoViewIfNeeded();
|
||||
const box = await disabled.boundingBox();
|
||||
const before = await page.evaluate(() => scrollY);
|
||||
await swipe(
|
||||
box.x + box.width / 2,
|
||||
Math.min(540, box.y + box.height / 2),
|
||||
180,
|
||||
0,
|
||||
-180,
|
||||
);
|
||||
assert.ok(
|
||||
(await page.evaluate(() => scrollY)) > before,
|
||||
|
|
@ -205,7 +368,8 @@ try {
|
|||
await swipe(
|
||||
modalBox.x + modalBox.width / 2,
|
||||
modalBox.y + modalBox.height * 0.8,
|
||||
modalBox.height * 0.5,
|
||||
0,
|
||||
-modalBox.height * 0.5,
|
||||
);
|
||||
assert.ok(
|
||||
(await body.evaluate((el) => el.scrollTop)) > 0,
|
||||
|
|
|
|||
|
|
@ -723,6 +723,91 @@ body:has(.pr-game) {
|
|||
border-top: 3px solid var(--foliage);
|
||||
background-image: linear-gradient(110deg, #c6b3760d, transparent 60%);
|
||||
}
|
||||
.pr-game .player-board.panel {
|
||||
padding-block-start: 4px;
|
||||
}
|
||||
.pr-game .player-board > .board-player-header {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 6px;
|
||||
}
|
||||
.pr-game .board-player-header > .board-player-tabs {
|
||||
min-width: 0;
|
||||
flex-wrap: nowrap;
|
||||
gap: 4px;
|
||||
overflow-x: auto;
|
||||
overscroll-behavior-x: contain;
|
||||
scrollbar-width: thin;
|
||||
/* Keep overlay scrollbars below the selected tab's border. */
|
||||
padding: 0 0 8px;
|
||||
}
|
||||
/* Use an edge-aligned track instead of the native overlay scrollbar inset. */
|
||||
@supports selector(::-webkit-scrollbar) {
|
||||
.pr-game .board-player-header > .board-player-tabs {
|
||||
scrollbar-width: auto;
|
||||
/* This track reserves its own height, unlike an overlay scrollbar. */
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
}
|
||||
.pr-game .board-player-tabs::-webkit-scrollbar {
|
||||
height: 4px;
|
||||
}
|
||||
.pr-game .board-player-tabs::-webkit-scrollbar-track {
|
||||
margin: 0;
|
||||
background: transparent;
|
||||
}
|
||||
.pr-game .board-player-tabs::-webkit-scrollbar-thumb {
|
||||
background: var(--line);
|
||||
border-radius: 2px;
|
||||
}
|
||||
.pr-game .board-player-tabs::-webkit-scrollbar-button {
|
||||
display: none;
|
||||
width: 0;
|
||||
}
|
||||
.pr-game [data-board-player] {
|
||||
flex: 1 0 auto;
|
||||
min-width: 88px;
|
||||
max-width: 160px;
|
||||
min-height: 44px;
|
||||
padding: 7px 9px;
|
||||
gap: 5px;
|
||||
border: 1px solid transparent;
|
||||
border-bottom: 3px solid transparent;
|
||||
border-radius: 6px 6px 0 0;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.pr-game [data-board-player]:focus-visible {
|
||||
outline-offset: -3px;
|
||||
}
|
||||
.pr-game [data-board-player] > span:last-child {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.pr-game [data-board-player][aria-pressed="true"] {
|
||||
background: var(--selected);
|
||||
border-color: var(--gold);
|
||||
color: var(--ink);
|
||||
}
|
||||
.pr-game .board-player-header > .board-player-resources,
|
||||
.pr-game .board-player-header > .board-player-goods {
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.pr-game .board-player-header > .board-player-resources {
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
.pr-game .board-player-header > .board-player-goods {
|
||||
grid-column: 1 / -1;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.pr-game .board-player-header .metric {
|
||||
margin: 0;
|
||||
}
|
||||
.pr-game .player-board h3 {
|
||||
color: var(--foliage);
|
||||
}
|
||||
|
|
|
|||
20
viewer/ui.js
20
viewer/ui.js
|
|
@ -665,9 +665,13 @@ export function mountGame(
|
|||
};
|
||||
return `<h3>${t("countryside")} <small>${a.estates.filter((x) => (!x.vpArea && x.id !== "quarry") || !a.puertoma).length}/${a.puertoma ? 10 : 12}</small></h3><div class="estates">${a.estates.map((x, i) => `<article class="estate ${x.id}" title="${esc(t(x.id))}">${icon(GOODS.includes(x.id) ? `field-${x.id}` : x.id, 36)}<span class="estate-name">${t(x.id)}</span>${x.id !== "forest" ? peopleSlots(`e${i}`, x, a.puertoma ? (x.vpArea ? 0 : estateCapacity(x.id)) : 1) : ""}</article>`).join("")}${Array.from({ length: Math.max(0, (a.puertoma ? 10 : 12) - a.estates.length) }, () => '<span class="estate empty-estate"></span>').join("")}</div><h3>${t("city")} <small>${a.puertoma ? a.buildings.length : citySize(a)}/${a.puertoma ? 8 : 12}</small></h3><div class="city-grid">${a.buildings.map((x, i) => `<article class="owned-building ${B[x.id].size === 2 ? "expanded" : ""}"><button type="button" data-building="${x.id}" class="building-face" title="${esc(x.id === "monument" ? t(x.id) : t.effect(x.id))}">${buildingPictogram(x.id, 28)}<span class="owned-building-name">${t(x.id)}</span>${effectBadge(i)}</button><div class="owned-building-bottom">${a.puertoma ? `<small>${t("level")} ${x.level}</small>` : peopleSlots(`b${i}`, x, B[x.id].workers)}${pointsBadge(B[x.id].vp)}</div></article>`).join("")}${a.buildings.length ? "" : `<div class="empty-city">${town}<span>${t("emptyCity")}</span></div>`}</div>`;
|
||||
}
|
||||
function boardPlayerHeader(a) {
|
||||
const reserve = playerReserve(a, view);
|
||||
return `<header class="board-player-header"><div class="board-player-tabs" role="group" aria-label="${esc(t("players"))}">${state.players.map((p, i) => `<button type="button" data-board-player="${i}" aria-pressed="${i === view}" title="${esc(p.name)}">${playerMarker(i, true)}<span>${esc(p.name)}</span></button>`).join("")}</div><div class="board-player-resources">${metric("coin", a.coins)}${scoreButton(view)}${!a.puertoma ? `${metric("worker", reserve.w, "reserveWorkers")}${state.expansions.includes("citizens") ? metric("citizen", reserve.c, "reserveCitizens") : ""}` : ""}</div><div class="board-player-goods" role="group" aria-label="${esc(t("stockLabel"))}">${GOODS.map((g) => metric(g, a.goods[g])).join("")}</div></header>`;
|
||||
}
|
||||
function playerBoard() {
|
||||
const a = state.players[view];
|
||||
return `<section class="player-board panel" id="own-board"><header><h2>${playerMarker(view, true)}${esc(a.name)}</h2></header>${productionOverview(a)}${playerAreas(a)}${achievements(a)}${puertomaBoard(a)}<button class="mobile-market-launch" data-market>${icon("building")} ${t("market")}</button></section>`;
|
||||
return `<section class="player-board panel" id="own-board" aria-label="${esc(a.name)}">${boardPlayerHeader(a)}${productionOverview(a)}${playerAreas(a)}${achievements(a)}${puertomaBoard(a)}<button class="mobile-market-launch" data-market>${icon("building")} ${t("market")}</button></section>`;
|
||||
}
|
||||
function achievements(a) {
|
||||
if (!a.achievements) return "";
|
||||
|
|
@ -1045,6 +1049,16 @@ export function mountGame(
|
|||
return !from.isEqualNode(to);
|
||||
},
|
||||
});
|
||||
// Reveal the selected tab horizontally without scrolling the board/page.
|
||||
const tabs = content.querySelector(".board-player-tabs"),
|
||||
selectedTab = tabs.querySelector('[aria-pressed="true"]');
|
||||
if (selectedTab) {
|
||||
const row = tabs.getBoundingClientRect(),
|
||||
tab = selectedTab.getBoundingClientRect();
|
||||
if (tab.left < row.left + 4) tabs.scrollLeft += tab.left - row.left - 4;
|
||||
else if (tab.right > row.right - 4)
|
||||
tabs.scrollLeft += tab.right - row.right + 4;
|
||||
}
|
||||
if (pending)
|
||||
for (const button of content.querySelectorAll(".action-dock button"))
|
||||
button.disabled = true;
|
||||
|
|
@ -1384,9 +1398,9 @@ export function mountGame(
|
|||
);
|
||||
return;
|
||||
}
|
||||
const card = event.target.closest("[data-player]");
|
||||
const card = event.target.closest("[data-player], [data-board-player]");
|
||||
if (card) {
|
||||
view = Number(card.dataset.player);
|
||||
view = Number(card.dataset.player ?? card.dataset.boardPlayer);
|
||||
render();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue