Publish player rules and complete BGS metadata
This commit is contained in:
parent
de9c00fdb8
commit
568f4f8644
8 changed files with 217 additions and 9 deletions
|
|
@ -73,3 +73,12 @@ 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.
|
||||
|
||||
`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.
|
||||
|
|
|
|||
|
|
@ -1,12 +1,20 @@
|
|||
{
|
||||
"label": "🏝️ Puerto Rico",
|
||||
"public": false,
|
||||
"players": [1, 2, 3, 4, 5],
|
||||
"description": "Choose roles, develop your island, produce goods and ship them for points. Includes all six expansions and solo play against two Puertomas.",
|
||||
"rules": "Choose a role: all players perform its action, and you receive a privilege. Plant, recruit, build, produce, trade and ship. Most points from shipping, buildings and bonuses wins.",
|
||||
"credits": "Andreas Seyfarth · Awaken Realms · Ravensburger",
|
||||
"players": [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
],
|
||||
"description": "Choose roles to develop your island, produce goods, and ship them for victory points. Every role helps your rivals too, so timing matters as much as building a strong economy. This adaptation of Puerto Rico 1897: Special Edition includes all six expansions and solo play against two Puertomas.",
|
||||
"rules": "[How to play](/page/puerto-rico/rules)",
|
||||
"credits": "**Game designer:** Andreas Seyfarth.\n\n**Publishers:** [Awaken Realms](https://awakenrealms.com/games/awaken-realms/puerto-rico) and [alea / Ravensburger](https://www.ravensburger.com/).\n\n**Achievements and Festival Activities:** Andreas Seyfarth and Tomasz Zawadzki.\n\n**Solo design:** John Albertson, Xavi Bordes, David Digby, Nick Shaw, and Dávid Turczi.",
|
||||
"links": {
|
||||
"publisher": "https://awakenrealms.com/games/awaken-realms/puerto-rico"
|
||||
"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"
|
||||
},
|
||||
"viewer": {
|
||||
"url": "",
|
||||
|
|
@ -15,7 +23,9 @@
|
|||
"fullScreenMobile": true,
|
||||
"replayable": true,
|
||||
"chat": true,
|
||||
"integratedControls": ["chat"],
|
||||
"integratedControls": [
|
||||
"chat"
|
||||
],
|
||||
"dependencies": {
|
||||
"scripts": [],
|
||||
"stylesheets": []
|
||||
|
|
@ -44,5 +54,9 @@
|
|||
"type": "checkbox",
|
||||
"default": false
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"eurogame",
|
||||
"economic"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@
|
|||
"build": "node scripts/build.mjs",
|
||||
"dev": "node scripts/dev.mjs",
|
||||
"test:browser": "node test/browser.mjs && node test/locales-browser.mjs",
|
||||
"publish:private": "pnpm build && node scripts/publish-private.mjs"
|
||||
"publish:private": "pnpm build && node scripts/publish-private.mjs",
|
||||
"publish:metadata": "node scripts/publish-metadata.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
|
|
|
|||
39
scripts/publish-cms.mjs
Normal file
39
scripts/publish-cms.mjs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { rulesPages, rulesPageName } from "./rules-pages.mjs";
|
||||
|
||||
export async function publishCmsRules(token) {
|
||||
const pages = rulesPages();
|
||||
const headers = {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
const backup = {};
|
||||
const base = `https://admin.boardgamers.space/api/admin/page/${encodeURIComponent(rulesPageName)}`;
|
||||
// Keep the prior authored pages recoverable before replacing any language.
|
||||
for (const lang of Object.keys(pages)) {
|
||||
const response = await fetch(`${base}/${lang}`, { headers });
|
||||
if (!response.ok && response.status !== 404)
|
||||
throw Error(`CMS read ${lang}: ${response.status}`);
|
||||
backup[lang] = response.ok ? await response.json() : null;
|
||||
}
|
||||
await mkdir(".local/release", { recursive: true });
|
||||
await writeFile(
|
||||
`.local/release/cms-before-${Date.now()}.json`,
|
||||
JSON.stringify(backup, null, 2),
|
||||
);
|
||||
for (const [lang, page] of Object.entries(pages)) {
|
||||
const response = await fetch(`${base}/${lang}`, {
|
||||
method: "PUT",
|
||||
headers,
|
||||
body: JSON.stringify(page),
|
||||
});
|
||||
if (!response.ok) throw Error(`CMS write ${lang}: ${response.status}`);
|
||||
const read = await fetch(`${base}/${lang}`, { headers });
|
||||
if (!read.ok) throw Error(`CMS verify ${lang}: ${read.status}`);
|
||||
const saved = await read.json();
|
||||
assert.equal(saved.title, page.title);
|
||||
assert.equal(saved.content, page.content);
|
||||
}
|
||||
return Object.keys(pages);
|
||||
}
|
||||
65
scripts/publish-metadata.mjs
Normal file
65
scripts/publish-metadata.mjs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import { readFile, mkdir, writeFile } from "node:fs/promises";
|
||||
import { homedir } from "node:os";
|
||||
import assert from "node:assert/strict";
|
||||
import { releaseMetadata } from "./release-metadata.mjs";
|
||||
import { publishCmsRules } from "./publish-cms.mjs";
|
||||
|
||||
const token = (await readFile(`${homedir()}/.bgs`, "utf8")).trim();
|
||||
const headers = {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
const base = "https://admin.boardgamers.space/api/admin/gameinfo/puerto-rico";
|
||||
async function api(path, body) {
|
||||
const response = await fetch(base + path, {
|
||||
method: body ? "PUT" : "GET",
|
||||
headers,
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
});
|
||||
if (!response.ok)
|
||||
throw Object.assign(Error(`${path}: ${response.status}`), {
|
||||
status: response.status,
|
||||
});
|
||||
return response.json();
|
||||
}
|
||||
const before = await api("/meta");
|
||||
await mkdir(".local/release", { recursive: true });
|
||||
await writeFile(
|
||||
`.local/release/metadata-before-${Date.now()}.json`,
|
||||
JSON.stringify(before, null, 2),
|
||||
);
|
||||
const languages = await publishCmsRules(token);
|
||||
const { metadata, translations } = 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),
|
||||
);
|
||||
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({
|
||||
rulesPage: "https://boardgamers.space/page/puerto-rico/rules",
|
||||
languages,
|
||||
tags: saved.tags,
|
||||
translationsPending,
|
||||
}),
|
||||
);
|
||||
|
|
@ -2,6 +2,7 @@ import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|||
import { homedir } from "node:os";
|
||||
import { createHash } from "node:crypto";
|
||||
import assert from "node:assert/strict";
|
||||
import { publishCmsRules } from "./publish-cms.mjs";
|
||||
import { releaseMetadata } from "./release-metadata.mjs";
|
||||
import { supportedLocales } from "../viewer/i18n.js";
|
||||
import { packageEngine } from "./package-engine.mjs";
|
||||
|
|
@ -71,6 +72,7 @@ await api("/1", "PUT", {
|
|||
});
|
||||
// Listed in the beta catalog; the actual playable version stays private.
|
||||
const { metadata, translations } = await releaseMetadata();
|
||||
await publishCmsRules(token);
|
||||
await api("/meta", "PUT", metadata);
|
||||
await api(
|
||||
"/assets/pictogram?name=Puerto%20Rico",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { readFile } from "node:fs/promises";
|
||||
import { rulesPageUrl } from "./rules-pages.mjs";
|
||||
import { supportedLocales } from "../viewer/i18n.js";
|
||||
|
||||
export async function releaseMetadata() {
|
||||
|
|
@ -24,8 +25,8 @@ export async function releaseMetadata() {
|
|||
if (!catalog[`metadata.${key}`])
|
||||
throw Error(`Missing ${locale} metadata.${key}`);
|
||||
translations[locale.split("-")[0]] = {
|
||||
description: catalog["metadata.description"],
|
||||
rules: catalog["metadata.rules"],
|
||||
description: `${catalog["metadata.description"]} ${catalog.ruleTiming}`,
|
||||
rules: `[${catalog.rules}](${rulesPageUrl})`,
|
||||
credits: source.credits,
|
||||
optionTranslations: {
|
||||
"options.chooseBuildings": catalog["metadata.chooseBuildings"],
|
||||
|
|
@ -42,6 +43,7 @@ export async function releaseMetadata() {
|
|||
rules: source.rules,
|
||||
credits: source.credits,
|
||||
links: source.links,
|
||||
tags: source.tags,
|
||||
unlisted: null,
|
||||
},
|
||||
translations,
|
||||
|
|
|
|||
76
scripts/rules-pages.mjs
Normal file
76
scripts/rules-pages.mjs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import { supportedLocales, translator } from "../viewer/i18n.js";
|
||||
|
||||
// BGS discovers game help by this exact <game>:rules CMS name.
|
||||
export const rulesPageName = "puerto-rico:rules";
|
||||
export const rulesPageUrl = "/page/puerto-rico/rules";
|
||||
const rulebook =
|
||||
"https://awakenrealms.com/images/download/puerto-rico/EN/EN_PR_Rulebook_210x285mm_bleed3mm%20%5B44%20pages%5D.pdf";
|
||||
const errata =
|
||||
"https://awakenrealms.com/images/download/puerto-rico/EN/PR_Others_Errata_297x210mm_bleed3mm.pdf";
|
||||
|
||||
// Reuse the human-authored, reviewed rules translations, not translation APIs.
|
||||
// Leave individual building effects and component counts to the board itself.
|
||||
export function rulesPages() {
|
||||
return Object.fromEntries(
|
||||
supportedLocales.map((locale) => {
|
||||
const t = translator(locale);
|
||||
const section = (title, ...paragraphs) =>
|
||||
`## ${t(title)}\n\n${paragraphs.join("\n\n")}`;
|
||||
const roles = [
|
||||
"planter",
|
||||
"recruiter",
|
||||
"builder",
|
||||
"craftsman",
|
||||
"trader",
|
||||
"captain",
|
||||
"adventurer",
|
||||
"smuggler",
|
||||
];
|
||||
const content = [
|
||||
`# Puerto Rico — ${t("rules")}`,
|
||||
section("ruleGoalTitle", t("ruleGoal")),
|
||||
section(
|
||||
"ruleRoundTitle",
|
||||
[t("ruleChoose"), t("ruleFollow"), t("ruleNext")].join(" "),
|
||||
`**2 ${t("players").toLocaleLowerCase(locale)}:** ${t("ruleNextTwo")}`,
|
||||
`${t("ruleReset")} ${t("ruleSmugglerCoin")}`,
|
||||
t("ruleOptional"),
|
||||
),
|
||||
roles
|
||||
.map(
|
||||
(role) =>
|
||||
`- **${t(role)}:** ${t.roleAction(role)}${t.rolePrivilege(role) ? ` **${t("privilege")}:** ${t.rolePrivilege(role)}` : ""}`,
|
||||
)
|
||||
.join("\n"),
|
||||
section(
|
||||
"ruleProductionTitle",
|
||||
t("productionIntro"),
|
||||
t("productionPair"),
|
||||
t("ruleActivation"),
|
||||
),
|
||||
section(
|
||||
"ruleGoodsTitle",
|
||||
`**${t("ruleSellTitle")}:** ${t("ruleSell")}`,
|
||||
`**${t("ruleShipTitle")}:** ${t("ruleShip")} ${t("ruleShipLimits")}`,
|
||||
),
|
||||
section(
|
||||
"ruleEditionTitle",
|
||||
t("ruleCitizens"),
|
||||
`${t("ruleFestival")} ${t("festivalReservedHelp")}`,
|
||||
t("achievementHelp"),
|
||||
),
|
||||
section(
|
||||
"ruleEndTitle",
|
||||
`${t("ruleEnd")} ${t("ruleEndCitizens")}`,
|
||||
`${t("ruleScore")} ${t("ruleScoreCitizens")}`,
|
||||
),
|
||||
`## ${t("puertoma")}\n\n${t("puertomaHelp")}`,
|
||||
`[${t("rules")} (PDF · EN)](${rulebook}) · [Errata (EN)](${errata})`,
|
||||
].join("\n\n");
|
||||
return [
|
||||
locale.split("-")[0],
|
||||
{ title: `Puerto Rico — ${t("rules")}`, content },
|
||||
];
|
||||
}),
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue