diff --git a/README.md b/README.md index 5a65f8c..e8a05c4 100644 --- a/README.md +++ b/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. diff --git a/bgs/game.json b/bgs/game.json index c309234..eda9696 100644 --- a/bgs/game.json +++ b/bgs/game.json @@ -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 } diff --git a/package.json b/package.json index aee69db..d65ab3d 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1a97e39..b5b3d2d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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 diff --git a/scripts/publish-gallery.mjs b/scripts/publish-gallery.mjs new file mode 100644 index 0000000..00aef63 --- /dev/null +++ b/scripts/publish-gallery.mjs @@ -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))); +} diff --git a/scripts/publish-metadata.mjs b/scripts/publish-metadata.mjs index 0b34409..7ceb161 100644 --- a/scripts/publish-metadata.mjs +++ b/scripts/publish-metadata.mjs @@ -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({ diff --git a/scripts/publish-private.mjs b/scripts/publish-private.mjs index eac3c74..4e22135 100644 --- a/scripts/publish-private.mjs +++ b/scripts/publish-private.mjs @@ -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)); diff --git a/scripts/release-gallery.mjs b/scripts/release-gallery.mjs new file mode 100644 index 0000000..15b2d63 --- /dev/null +++ b/scripts/release-gallery.mjs @@ -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") + : '
', + ); +}); +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(); +} diff --git a/scripts/release-metadata.mjs b/scripts/release-metadata.mjs index 32d942e..84559a6 100644 --- a/scripts/release-metadata.mjs +++ b/scripts/release-metadata.mjs @@ -64,6 +64,7 @@ export async function releaseMetadata() { credits: source.credits, links: source.links, tags: source.tags, + releaseYear: source.releaseYear, unlisted: null, }, translations, diff --git a/scripts/translate-platform-metadata.mjs b/scripts/translate-platform-metadata.mjs new file mode 100644 index 0000000..212b239 --- /dev/null +++ b/scripts/translate-platform-metadata.mjs @@ -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; +} diff --git a/vendor/boardgamers-protocol-0.11.0.tgz b/vendor/boardgamers-protocol-0.11.0.tgz new file mode 100644 index 0000000..c6a2f5b Binary files /dev/null and b/vendor/boardgamers-protocol-0.11.0.tgz differ diff --git a/vendor/provenance.json b/vendor/provenance.json new file mode 100644 index 0000000..f4ed5c5 --- /dev/null +++ b/vendor/provenance.json @@ -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." +} diff --git a/viewer/ui.js b/viewer/ui.js index 867c743..d08f79d 100644 --- a/viewer/ui.js +++ b/viewer/ui.js @@ -157,7 +157,10 @@ export function mountGame( ? `` : 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) ? `` : `${metric("vp", "?")}`; @@ -439,7 +442,8 @@ export function mountGame( function actionButton(m) { if (m.type === "produce") return `${moveButton(m, `${t("produce")}${goodsRow(m.goods)}`, "check", "primary produce-action", t("produce"))}`; - 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 ``; @@ -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 `