Complete private release checklist, gallery and native chat integration
This commit is contained in:
parent
b86ec19341
commit
7b94489836
13 changed files with 265 additions and 80 deletions
20
README.md
20
README.md
|
|
@ -62,7 +62,7 @@ This private version still needs broader playtesting. The Festival marker interp
|
|||
|
||||
`pnpm publish:private` builds the bundles, packages only the self-contained engine and its manifest, checks complete 1–5-player games from the extracted package, and uploads the engine/viewer to BGS. The script reads the admin token from `~/.bgs` without logging it, preserves the existing game/request identity, refuses to replace a public version, and verifies the private/listed flags and CDN bytes. It grants beta access to `coyotte508` if needed. Metadata snapshots and package artifacts stay in ignored `.local/release/`.
|
||||
|
||||
The hosted bundle has no local preview controls or runtime asset dependencies. Global BGS locale and color-blind preferences are handled by the viewer; expansion switches remain internal. Tutorials are not yet registered.
|
||||
The hosted bundle has no local preview controls or runtime asset dependencies. Global BGS locale and color-blind preferences are handled by the viewer; expansion switches remain internal. Four playable tutorial chapters are registered.
|
||||
|
||||
Enable “Show everyone’s VP” at game creation to reveal accumulated VP tokens to all players and spectators. It is off by default; uncompleted Achievement cards remain private. For a separate local preview with visible VP, add `&showVP=true` to the URL.
|
||||
|
||||
|
|
@ -72,16 +72,13 @@ The journal retains the latest 200 events. Older score contributions are accumul
|
|||
|
||||
Chat opens from the button next to the journal. On a host/SDK exposing `openChat` and advertising `platformChat`, it opens the native BGS chat. Protocol 0.9 hosts retain the functional SDK chat dialog. Native chat requires the corresponding platform PR and a protocol package upgrade; no unsupported messages are sent to older hosts.
|
||||
|
||||
The publisher sets **Puerto Rico** as the title and **1897 Special Edition** as the subtitle, uploads the original tightly cropped vector pictogram, and selects it as the BGS icon. It uploads hand-written metadata and setup-label translations through the manual translation endpoint. If an older host returns 404 for that endpoint, the game upload completes and the script explicitly reports `translationsPending`; the overlays remain ready in `.local/release/manual-translations.json`. Run the publisher again after the platform endpoint is deployed to apply them. It never calls automatic translation endpoints.
|
||||
The publisher sets **Puerto Rico** as the title and **1897 Special Edition** as the subtitle, uploads the tightly cropped vector pictogram, and selects it as the BGS icon. Catalog description, credits and setup labels use the platform metadata translation service, skipping translations whose source hash is current. Game UI, engine messages, tutorial content and CMS rules use directly authored translations; they never go through that service.
|
||||
|
||||
`pnpm publish:metadata` updates the description, credits, links, tags and the
|
||||
`puerto-rico:rules` CMS page in all 16 supported languages without uploading the
|
||||
engine or viewer. Rules content is assembled from the manually authored player
|
||||
instructions in `viewer/locales`; it contains no interface walkthrough. The rules
|
||||
field contains only a link to `/page/puerto-rico/rules`. Both publication commands
|
||||
back up existing CMS pages before updating them. Game metadata language overlays
|
||||
remain queued in `.local/release/manual-translations.json` when the host does not
|
||||
yet expose the manual translation endpoint; no translation API is used.
|
||||
`pnpm publish:metadata` updates the description, credits, links, tags and the `puerto-rico:rules` CMS page in all 16 supported languages without uploading the engine or viewer. The rules field contains only a link to `/page/puerto-rico/rules`. Both publication commands back up existing CMS pages before updating them.
|
||||
|
||||
`pnpm release:gallery` creates three distinct screenshots of the built viewer (board, building market, mobile) in ignored `.local/release/gallery/`, using a deterministic isolated game. It also checks protocol diagnostics, native chat opening and hiding chat during analysis. Review the images, then run `pnpm publish:gallery` to upload them and verify anonymous image access. Dark variants are unnecessary while the viewer forces the same dark theme for everyone.
|
||||
|
||||
The protocol SDK is pinned as a reproducible artifact under `vendor/`, with its source revision in `vendor/provenance.json`. Replace this file dependency with the equivalent registry version when published.
|
||||
|
||||
## Playable tutorials
|
||||
|
||||
|
|
@ -104,5 +101,4 @@ preview server (or replace the chapter ID above). `pnpm test` covers legality,
|
|||
conservation, replay, progress and translation completeness. `pnpm test:tutorials`
|
||||
plays every chapter through the actual controls on mobile and desktop and checks
|
||||
all languages at 320 px. `pnpm publish:private` registers the chapter metadata with
|
||||
the viewer; translated BGS chapter-list labels use the same pending manual
|
||||
metadata endpoint as other game translations.
|
||||
the viewer; translated BGS chapter-list labels use the platform metadata service.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
"links": {
|
||||
"publisher": "https://awakenrealms.com/games/awaken-realms/puerto-rico",
|
||||
"source": "https://codeberg.org/boardgamers/puerto-rico",
|
||||
"bgg": "https://boardgamegeek.com/boardgame/415843/puerto-rico-1897-special-edition"
|
||||
"bgg": "https://boardgamegeek.com/boardgame/415843/puerto-rico-1897-special-edition",
|
||||
"purchase": "https://gamefound.com/en/projects/awaken-realms/puerto-rico-special-edition"
|
||||
},
|
||||
"viewer": {
|
||||
"url": "",
|
||||
|
|
@ -67,7 +68,7 @@
|
|||
"default": false
|
||||
}
|
||||
],
|
||||
"tags": ["eurogame", "economic"],
|
||||
"tags": ["eurogame", "economic", "role-selection"],
|
||||
"tutorial": {
|
||||
"chapters": [
|
||||
{
|
||||
|
|
@ -95,5 +96,6 @@
|
|||
"description": "Solve a coffee shortage using the Smuggler and a Festival objective."
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"releaseYear": 2025
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/puerto-rico",
|
||||
"version": "0.3.3",
|
||||
"version": "0.3.4",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Puerto Rico 1897 Special Edition for Boardgamers Space",
|
||||
|
|
@ -11,10 +11,12 @@
|
|||
"test:browser": "node test/browser.mjs && node test/locales-browser.mjs",
|
||||
"publish:private": "pnpm build && node scripts/publish-private.mjs",
|
||||
"publish:metadata": "node scripts/publish-metadata.mjs",
|
||||
"test:tutorials": "node test/tutorial-browser.mjs"
|
||||
"test:tutorials": "node test/tutorial-browser.mjs",
|
||||
"release:gallery": "pnpm build && node scripts/release-gallery.mjs",
|
||||
"publish:gallery": "node scripts/publish-gallery.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"@boardgamers/protocol": "file:vendor/boardgamers-protocol-0.11.0.tgz",
|
||||
"@noble/hashes": "2.0.1",
|
||||
"morphdom": "2.7.8"
|
||||
},
|
||||
|
|
|
|||
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
|
|
@ -9,8 +9,8 @@ importers:
|
|||
.:
|
||||
dependencies:
|
||||
'@boardgamers/protocol':
|
||||
specifier: 0.9.0
|
||||
version: 0.9.0
|
||||
specifier: file:vendor/boardgamers-protocol-0.11.0.tgz
|
||||
version: file:vendor/boardgamers-protocol-0.11.0.tgz
|
||||
'@noble/hashes':
|
||||
specifier: 2.0.1
|
||||
version: 2.0.1
|
||||
|
|
@ -30,8 +30,9 @@ importers:
|
|||
|
||||
packages:
|
||||
|
||||
'@boardgamers/protocol@0.9.0':
|
||||
resolution: {integrity: sha512-xDQMui0xqqRF/ERIJ7Rm79JonMA2+6zn1CrgxpM6Oy3SpFKF6i0Wo6oAyYYqMveqiWJCkC0WvHlePclVfbH/IQ==}
|
||||
'@boardgamers/protocol@file:vendor/boardgamers-protocol-0.11.0.tgz':
|
||||
resolution: {integrity: sha512-WmLTORnjHONvGjx24DzDylB1EQV9EO53rHKlouVX+Y59fIYAVkR1TZ9YbUo1es+jS7YYb0iFSHB3c8aOGxAgKQ==, tarball: file:vendor/boardgamers-protocol-0.11.0.tgz}
|
||||
version: 0.11.0
|
||||
|
||||
'@esbuild/aix-ppc64@0.28.2':
|
||||
resolution: {integrity: sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==}
|
||||
|
|
@ -226,7 +227,7 @@ packages:
|
|||
|
||||
snapshots:
|
||||
|
||||
'@boardgamers/protocol@0.9.0':
|
||||
'@boardgamers/protocol@file:vendor/boardgamers-protocol-0.11.0.tgz':
|
||||
dependencies:
|
||||
zod: 4.6.5
|
||||
|
||||
|
|
|
|||
46
scripts/publish-gallery.mjs
Normal file
46
scripts/publish-gallery.mjs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { readFile } from "node:fs/promises";
|
||||
import assert from "node:assert/strict";
|
||||
export async function publishGallery(token) {
|
||||
const base = "https://admin.boardgamers.space/api/admin/gameinfo/puerto-rico";
|
||||
const headers = { Authorization: `Bearer ${token}` };
|
||||
const gallery = [];
|
||||
for (const [name, caption] of [
|
||||
["board", "Develop your island and choose roles"],
|
||||
["buildings", "Plan your city in the building market"],
|
||||
["mobile", "Play on mobile"],
|
||||
]) {
|
||||
const asset = `screenshot-release-${name}`;
|
||||
const response = await fetch(`${base}/assets/${asset}`, {
|
||||
method: "PUT",
|
||||
headers: { ...headers, "Content-Type": "image/png" },
|
||||
body: await readFile(`.local/release/gallery/${name}.png`),
|
||||
});
|
||||
if (!response.ok) throw Error(`Screenshot ${name}: ${response.status}`);
|
||||
gallery.push({ asset, caption });
|
||||
}
|
||||
const response = await fetch(`${base}/gallery`, {
|
||||
method: "PUT",
|
||||
headers: { ...headers, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ gallery }),
|
||||
});
|
||||
if (!response.ok) throw Error(`Gallery save: ${response.status}`);
|
||||
const saved = await (await fetch(`${base}/1`, { headers })).json();
|
||||
assert.deepEqual(saved.gallery, gallery);
|
||||
for (const { asset } of gallery)
|
||||
assert(
|
||||
(await fetch(saved.assets[asset].url)).ok,
|
||||
`Public screenshot ${asset}`,
|
||||
);
|
||||
return gallery;
|
||||
}
|
||||
|
||||
// Also usable independently after generating the release gallery.
|
||||
if (
|
||||
process.argv[1] &&
|
||||
import.meta.url ===
|
||||
(await import("node:url")).pathToFileURL(process.argv[1]).href
|
||||
) {
|
||||
const { homedir } = await import("node:os");
|
||||
const token = (await readFile(`${homedir()}/.bgs`, "utf8")).trim();
|
||||
console.log(JSON.stringify(await publishGallery(token)));
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { translatePlatformMetadata } from "./translate-platform-metadata.mjs";
|
||||
import { readFile, mkdir, writeFile } from "node:fs/promises";
|
||||
import { homedir } from "node:os";
|
||||
import assert from "node:assert/strict";
|
||||
|
|
@ -29,31 +30,14 @@ await writeFile(
|
|||
JSON.stringify(before, null, 2),
|
||||
);
|
||||
const languages = await publishCmsRules(token);
|
||||
const { metadata, translations } = await releaseMetadata();
|
||||
const { metadata } = await releaseMetadata();
|
||||
await api("/meta", metadata);
|
||||
let translationsPending = false;
|
||||
for (const [lang, overlay] of Object.entries(translations)) {
|
||||
try {
|
||||
await api(`/meta/translations/${lang}`, overlay);
|
||||
} catch (error) {
|
||||
if (error.status !== 404) throw error;
|
||||
translationsPending = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await writeFile(
|
||||
".local/release/manual-translations.json",
|
||||
JSON.stringify(translations, null, 2),
|
||||
);
|
||||
await translatePlatformMetadata(token, metadata);
|
||||
const translationsPending = false;
|
||||
const saved = await api("/meta");
|
||||
for (const [key, value] of Object.entries(metadata)) {
|
||||
if (value !== null) assert.deepEqual(saved[key], value, key);
|
||||
}
|
||||
if (!translationsPending)
|
||||
for (const [lang, overlay] of Object.entries(translations)) {
|
||||
for (const key of ["description", "rules", "credits"])
|
||||
assert.equal(saved.translations?.[lang]?.[key], overlay[key]);
|
||||
}
|
||||
assert.equal(saved.iconMode, before.iconMode);
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { translatePlatformMetadata } from "./translate-platform-metadata.mjs";
|
||||
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
||||
import { homedir } from "node:os";
|
||||
import { createHash } from "node:crypto";
|
||||
|
|
@ -71,7 +72,7 @@ await api("/1", "PUT", {
|
|||
viewer: { ...defaults.viewer, url: uploaded.url, scriptBytes: bytes.length },
|
||||
});
|
||||
// Listed in the beta catalog; the actual playable version stays private.
|
||||
const { metadata, translations } = await releaseMetadata();
|
||||
const { metadata } = await releaseMetadata();
|
||||
await publishCmsRules(token);
|
||||
await api("/meta", "PUT", metadata);
|
||||
await api(
|
||||
|
|
@ -82,22 +83,8 @@ await api(
|
|||
"image/svg+xml",
|
||||
);
|
||||
await api("/icon", "PUT", { mode: "pictogram" });
|
||||
let translationsPending = false;
|
||||
for (const [lang, translation] of Object.entries(translations)) {
|
||||
try {
|
||||
await api(`/meta/translations/${lang}`, "PUT", translation);
|
||||
} catch (error) {
|
||||
// Older hosts do not yet expose the manual translation endpoint. Keep the
|
||||
// manually authored overlays ready to upload once the platform PR is live.
|
||||
if (error.status !== 404) throw error;
|
||||
translationsPending = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await writeFile(
|
||||
".local/release/manual-translations.json",
|
||||
JSON.stringify(translations, null, 2),
|
||||
);
|
||||
await translatePlatformMetadata(token, metadata);
|
||||
const translationsPending = false;
|
||||
const access = await api("/beta-users");
|
||||
if (!access.some((u) => u.username === "coyotte508"))
|
||||
await api("/beta-users", "POST", { usernameOrEmail: "coyotte508" });
|
||||
|
|
@ -121,16 +108,6 @@ assert.equal(
|
|||
assert.deepEqual(published.preferences, defaults.preferences);
|
||||
assert.deepEqual(published.settings, defaults.settings);
|
||||
assert.deepEqual(published.tutorial, defaults.tutorial);
|
||||
if (!translationsPending) {
|
||||
for (const [lang, translation] of Object.entries(translations)) {
|
||||
assert.equal(
|
||||
meta.translations?.[lang]?.description,
|
||||
translation.description,
|
||||
);
|
||||
for (const [key, label] of Object.entries(translation.optionTranslations))
|
||||
assert.equal(meta.optionTranslations?.[lang]?.[key]?.label, label);
|
||||
}
|
||||
}
|
||||
const downloaded = await fetch(uploaded.url);
|
||||
assert.ok(downloaded.ok, `CDN ${downloaded.status}`);
|
||||
assert.equal(hash(Buffer.from(await downloaded.arrayBuffer())), hash(bytes));
|
||||
|
|
|
|||
94
scripts/release-gallery.mjs
Normal file
94
scripts/release-gallery.mjs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { chromium } from "playwright";
|
||||
import { createServer } from "node:http";
|
||||
import { readFile, mkdir, writeFile } from "node:fs/promises";
|
||||
import * as E from "../engine/index.js";
|
||||
import { RELEASE } from "../release-config.js";
|
||||
const server = createServer(async (req, res) => {
|
||||
res.setHeader(
|
||||
"Content-Type",
|
||||
req.url === "/viewer.js" ? "text/javascript" : "text/html",
|
||||
);
|
||||
res.end(
|
||||
req.url === "/viewer.js"
|
||||
? await readFile("dist/viewer.js")
|
||||
: '<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style>body{margin:0}</style><div id="game"></div><script src="/viewer.js"></script>',
|
||||
);
|
||||
});
|
||||
await new Promise((r) => server.listen(0, "127.0.0.1", r));
|
||||
const browser = await chromium.launch();
|
||||
const errors = [],
|
||||
checks = [];
|
||||
await mkdir(".local/release/gallery", { recursive: true });
|
||||
let state = E.init(3, RELEASE.expansions, RELEASE.options, "release-gallery");
|
||||
for (let n = 0; n < 1000 && !state.finished; n++) {
|
||||
if (state.round >= 6 && state.tasks[0]?.kind === "build") break;
|
||||
state = E.moveAI(state);
|
||||
}
|
||||
assert(!state.finished);
|
||||
const seat = state.tasks[0].p;
|
||||
try {
|
||||
for (const [width, height] of [
|
||||
[1440, 1000],
|
||||
[390, 844],
|
||||
]) {
|
||||
const page = await browser.newPage({
|
||||
viewport: { width, height },
|
||||
hasTouch: width < 700,
|
||||
});
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}`);
|
||||
await page.evaluate(
|
||||
({ state, seat }) => {
|
||||
window.host = puertorico.launch("#game");
|
||||
host.emit("player", { index: seat });
|
||||
host.emit("preferences", { locale: "en", sound: false });
|
||||
host.emit("state", state);
|
||||
},
|
||||
{ state: E.stripSecret(state, seat), seat },
|
||||
);
|
||||
await page.locator(".player-strip").waitFor();
|
||||
await page.waitForTimeout(300);
|
||||
await page.screenshot({
|
||||
path: `.local/release/gallery/${width === 1440 ? "board" : "mobile"}.png`,
|
||||
});
|
||||
checks.push({
|
||||
width,
|
||||
diagnostics: await page.evaluate(() => puertorico.diagnostics()),
|
||||
});
|
||||
if (width === 1440) {
|
||||
await page.locator(".action-dock [data-market]").click();
|
||||
await page.screenshot({ path: ".local/release/gallery/buildings.png" });
|
||||
}
|
||||
assert.equal(
|
||||
await page.evaluate(
|
||||
() => document.documentElement.scrollWidth > innerWidth,
|
||||
),
|
||||
false,
|
||||
);
|
||||
await page.keyboard.press("Escape");
|
||||
await page.evaluate(() => {
|
||||
window.chatRequests = 0;
|
||||
host.on("chat:open", () => chatRequests++);
|
||||
host.emit("preferences", {
|
||||
locale: "en",
|
||||
sound: false,
|
||||
platformChat: true,
|
||||
});
|
||||
});
|
||||
await page.locator('[data-panel="chat"]').click();
|
||||
assert.equal(await page.evaluate(() => chatRequests), 1);
|
||||
assert.equal(await page.locator(".pr-chat[open]").count(), 0);
|
||||
await page.evaluate(() => host.emit("preferences", { analysis: true }));
|
||||
assert.equal(await page.locator('[data-panel="chat"]').count(), 0);
|
||||
await page.close();
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
await writeFile(
|
||||
".local/release/gallery/checks.json",
|
||||
JSON.stringify({ errors, checks }, null, 2),
|
||||
);
|
||||
} finally {
|
||||
await browser.close();
|
||||
server.close();
|
||||
}
|
||||
|
|
@ -64,6 +64,7 @@ export async function releaseMetadata() {
|
|||
credits: source.credits,
|
||||
links: source.links,
|
||||
tags: source.tags,
|
||||
releaseYear: source.releaseYear,
|
||||
unlisted: null,
|
||||
},
|
||||
translations,
|
||||
|
|
|
|||
51
scripts/translate-platform-metadata.mjs
Normal file
51
scripts/translate-platform-metadata.mjs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { createHash } from "node:crypto";
|
||||
import assert from "node:assert/strict";
|
||||
import { supportedLocales } from "../viewer/i18n.js";
|
||||
|
||||
// Only catalog prose and host setup labels go through the platform translation service.
|
||||
// Viewer, engine, tutorials and CMS rules retain their authored translations.
|
||||
export async function translatePlatformMetadata(
|
||||
token,
|
||||
metadata,
|
||||
locales = supportedLocales,
|
||||
) {
|
||||
const base = "https://admin.boardgamers.space/api/admin/gameinfo/puerto-rico";
|
||||
const headers = {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
const source = Object.fromEntries(
|
||||
["description", "rules", "credits"]
|
||||
.filter((k) => metadata[k])
|
||||
.map((k) => [k, metadata[k]]),
|
||||
);
|
||||
const hash = createHash("sha256")
|
||||
.update(JSON.stringify(source))
|
||||
.digest("hex")
|
||||
.slice(0, 16);
|
||||
async function read() {
|
||||
const response = await fetch(`${base}/meta`, { headers });
|
||||
if (!response.ok) throw Error(`Metadata read: ${response.status}`);
|
||||
return response.json();
|
||||
}
|
||||
let current = await read();
|
||||
for (const locale of locales.filter((l) => l !== "en")) {
|
||||
const lang = locale.split("-")[0];
|
||||
if (current.translations?.[lang]?.translatedFrom?.hash === hash) continue;
|
||||
const response = await fetch(`${base}/meta/translate`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({ targetLang: lang }),
|
||||
});
|
||||
if (!response.ok)
|
||||
throw Error(`Platform metadata translation ${lang}: ${response.status}`);
|
||||
current = await read();
|
||||
assert.equal(
|
||||
current.translations?.[lang]?.translatedFrom?.hash,
|
||||
hash,
|
||||
lang,
|
||||
);
|
||||
console.log(`Platform metadata translated: ${locale}`);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
BIN
vendor/boardgamers-protocol-0.11.0.tgz
vendored
Normal file
BIN
vendor/boardgamers-protocol-0.11.0.tgz
vendored
Normal file
Binary file not shown.
10
vendor/provenance.json
vendored
Normal file
10
vendor/provenance.json
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"package": "@boardgamers/protocol",
|
||||
"version": "0.11.0",
|
||||
"source": "https://codeberg.org/boardgamers/boardgamers",
|
||||
"commit": "38de11d3",
|
||||
"directory": "packages/protocol",
|
||||
"pullRequest": "https://codeberg.org/boardgamers/boardgamers/pulls/571",
|
||||
"build": "pnpm --filter @boardgamers/protocol build && npm pack",
|
||||
"reason": "Pinned SDK artifact includes native chat opening. Registry publishing credentials were unavailable; replace with the registry dependency once 0.11.0 is published."
|
||||
}
|
||||
41
viewer/ui.js
41
viewer/ui.js
|
|
@ -157,7 +157,10 @@ export function mountGame(
|
|||
? `<span class="building-type-icon" role="img" title="${label}" aria-label="${label}">${drawing}</span>`
|
||||
: drawing;
|
||||
};
|
||||
const scoreButton = (i, n = state.finished ? state.results?.[i]?.total : state.players[i].vp) =>
|
||||
const scoreButton = (
|
||||
i,
|
||||
n = state.finished ? state.results?.[i]?.total : state.players[i].vp,
|
||||
) =>
|
||||
Number.isFinite(n)
|
||||
? `<button type="button" class="score-button" data-score="${i}" title="${esc(t("scoreDetails"))}" aria-label="${esc(`${t("scoreDetails")} · ${state.players[i].name} : ${n}`)}">${scoreToken(n)}</button>`
|
||||
: `<span title="${esc(t("scoreHidden"))}">${metric("vp", "?")}</span>`;
|
||||
|
|
@ -439,7 +442,8 @@ export function mountGame(
|
|||
function actionButton(m) {
|
||||
if (m.type === "produce")
|
||||
return `${moveButton(m, `<span class="produce-label">${t("produce")}</span><span class="produce-goods">${goodsRow(m.goods)}</span>`, "check", "primary produce-action", t("produce"))}<button class="quiet production-custom" data-custom-production="${encode(m)}" title="${esc(t("selectQty"))}" aria-label="${esc(t("selectQty"))}" ${allowed() ? "" : "disabled"}>${icon("edit")}<span>${t("selectQty")}</span></button>`;
|
||||
if (m.type === "role") return roleCard(state.roles.find((r) => r.id === m.id));
|
||||
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])
|
||||
|
|
@ -614,9 +618,13 @@ export function mountGame(
|
|||
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),
|
||||
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 `<button data-role-id="${r.id}" class="role ${selected ? "taken" : ""} ${current ? "current" : ""} ${m ? "available" : ""}" ${current ? 'aria-current="step"' : ""} ${selected ? `title="${esc(t(r.id))} · ${esc(state.players[r.taken].name)}${current ? ` · ${esc(t("currentRole"))}` : ""}"` : warning ? `title="${esc(t(warning.reason))}" aria-label="${esc(t(r.id))} — ${esc(t(warning.reason))}"` : ""} ${m && acting ? `data-move="${encode(m)}"` : `data-role="${r.id}"`}>${current ? `<small class="role-status">${t("currentRole")}</small>` : ""}${warning ? `<span class="role-warning" aria-hidden="true">${icon("warning", 15)}</span>` : ""}<span class="role-icon">${icon(r.id === "adventurer2" ? "adventurer" : r.id, 32)}${r.coins ? `<span class="role-coins">${metric("coin", r.coins)}</span>` : ""}</span><b>${t(r.id)}</b>${r.id === "recruiter" && m ? `<span class="role-recruits">${recruitmentCount(recruitmentShares(state, seat)[seat])}${recruitmentBonus(state, seat) ? ` <span title="${esc(t("privilege"))}">+${metric("worker", recruitmentBonus(state, seat))}</span>` : ""}</span>` : ""}${selected ? playerMarker(r.taken) : ""}</button>`;
|
||||
|
|
@ -630,7 +638,8 @@ export function mountGame(
|
|||
function sharedBoard() {
|
||||
const festivalTag = desktopLayout.matches ? "section" : "details";
|
||||
const festivalHeadingTag = desktopLayout.matches ? "header" : "summary";
|
||||
const acting = allowed(), task = state.tasks[0];
|
||||
const acting = allowed(),
|
||||
task = state.tasks[0];
|
||||
return `<section class="shared-board"><div class="roles">${state.roles
|
||||
.map(roleCard)
|
||||
.join(
|
||||
|
|
@ -868,7 +877,10 @@ export function mountGame(
|
|||
function render(s, awaitingMove = false) {
|
||||
if (s) {
|
||||
state = s.finished
|
||||
? { ...s, results: s.results ?? s.players.map((_, i) => scoreBreakdown(s, i)) }
|
||||
? {
|
||||
...s,
|
||||
results: s.results ?? s.players.map((_, i) => scoreBreakdown(s, i)),
|
||||
}
|
||||
: s;
|
||||
pending = awaitingMove;
|
||||
}
|
||||
|
|
@ -890,7 +902,7 @@ export function mountGame(
|
|||
"is-building",
|
||||
isTurn() && ["build", "draft"].includes(state.tasks[0]?.kind),
|
||||
);
|
||||
const html = `<div class="pr-content"><header class="game-header"><div class="wordmark"><span>PUERTO RICO</span><small>${t("metadata.subtitle")}</small></div><span class="round-indicator">${t("round")} <b>${state.round}</b></span><nav>${["rules", "journal", ...(chat ? ["chat"] : [])].map((id) => `<button class="icon-button" data-panel="${id}" title="${esc(t(id))}" aria-label="${esc(t(id))}">${icon(id)}${id === "chat" ? '<span class="chat-unread" aria-hidden="true" hidden></span>' : ""}</button>`).join("")}</nav></header><div class="player-strip${state.players.length > 3 ? " many-players" : ""}">${state.players.map(playerCard).join("")}</div>${playerSummary()}${localControls ? `<div class="local-controls"><span>${t("local")}</span><button data-local="undo" title="${esc(t("undo"))}" aria-label="${esc(t("undo"))}">${icon("undo", 18)}</button><button data-local="opponents" title="${esc(t("opponents"))}" aria-label="${esc(t("opponents"))}">${icon("pass", 18)}</button><button data-local="reset" title="${esc(t("newGame"))}" aria-label="${esc(t("newGame"))}">${icon("reset", 18)}</button>${FORCE_DARK_THEME ? "" : `<button data-local="dark" title="${esc(t("toggleTheme"))}" aria-label="${esc(t("toggleTheme"))}">${icon("dark", 18)}</button>`}</div>` : ""}<div class="board-layout">${sharedBoard()}${playerBoard()}${market()}</div>${bottom()}</div>`;
|
||||
const html = `<div class="pr-content"><header class="game-header"><div class="wordmark"><span>PUERTO RICO</span><small>${t("metadata.subtitle")}</small></div><span class="round-indicator">${t("round")} <b>${state.round}</b></span><nav>${["rules", "journal", ...(chat && !preferences.analysis ? ["chat"] : [])].map((id) => `<button class="icon-button" data-panel="${id}" title="${esc(t(id))}" aria-label="${esc(t(id))}">${icon(id)}${id === "chat" ? '<span class="chat-unread" aria-hidden="true" hidden></span>' : ""}</button>`).join("")}</nav></header><div class="player-strip${state.players.length > 3 ? " many-players" : ""}">${state.players.map(playerCard).join("")}</div>${playerSummary()}${localControls ? `<div class="local-controls"><span>${t("local")}</span><button data-local="undo" title="${esc(t("undo"))}" aria-label="${esc(t("undo"))}">${icon("undo", 18)}</button><button data-local="opponents" title="${esc(t("opponents"))}" aria-label="${esc(t("opponents"))}">${icon("pass", 18)}</button><button data-local="reset" title="${esc(t("newGame"))}" aria-label="${esc(t("newGame"))}">${icon("reset", 18)}</button>${FORCE_DARK_THEME ? "" : `<button data-local="dark" title="${esc(t("toggleTheme"))}" aria-label="${esc(t("toggleTheme"))}">${icon("dark", 18)}</button>`}</div>` : ""}<div class="board-layout">${sharedBoard()}${playerBoard()}${market()}</div>${bottom()}</div>`;
|
||||
morphdom(content, html, {
|
||||
childrenOnly: true,
|
||||
onBeforeElUpdated(from, to) {
|
||||
|
|
@ -984,7 +996,9 @@ export function mountGame(
|
|||
: null;
|
||||
const b = B[id],
|
||||
moves = state.legal.filter(
|
||||
(m) => ["build", "draft"].includes(m.type) && m.id === id &&
|
||||
(m) =>
|
||||
["build", "draft"].includes(m.type) &&
|
||||
m.id === id &&
|
||||
showBuildingPayment(state.players[seat], m),
|
||||
);
|
||||
show(
|
||||
|
|
@ -1079,7 +1093,9 @@ export function mountGame(
|
|||
r.bonus,
|
||||
)
|
||||
.map(([id, n]) => `<p>${t(id)} <b>${n}</b></p>`)
|
||||
.join("")}<p>${t("tie")} <b>${r.tie}</b></p><button type="button" data-score="${i}">${t("scoreDetails")}</button></article>`,
|
||||
.join(
|
||||
"",
|
||||
)}<p>${t("tie")} <b>${r.tie}</b></p><button type="button" data-score="${i}">${t("scoreDetails")}</button></article>`,
|
||||
)
|
||||
.join("")}</div>`,
|
||||
);
|
||||
|
|
@ -1208,6 +1224,7 @@ export function mountGame(
|
|||
}
|
||||
if (el.dataset.panel) {
|
||||
if (el.dataset.panel === "chat") {
|
||||
if (preferences.analysis) return;
|
||||
if (preferences.platformChat === true && onOpenChat) {
|
||||
onOpenChat();
|
||||
return;
|
||||
|
|
@ -1460,6 +1477,10 @@ export function mountGame(
|
|||
setPreferences(p) {
|
||||
const previousLocale = preferences.locale ?? preferences.language ?? "en";
|
||||
preferences = mergePreferences(preferences, p);
|
||||
if (preferences.analysis) {
|
||||
if (chatDialog.open) dismiss(chatDialog);
|
||||
chat?.setOpen(false);
|
||||
}
|
||||
t = translator(preferences.locale ?? preferences.language ?? "en");
|
||||
shell.lang = t.locale;
|
||||
shell.dir = t.locale === "fa" ? "rtl" : "ltr";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue