/** * games/index.mjs — the games the platform supports, and the check that holds each one's * feature list to its module's declared capabilities. * * PLAN.md §16, phase 17. Each game has a file of its own (`uo.mjs`, `rust.mjs`) written in * that game's words, which only that game's pages render. This file is what the core pages * read instead: the game's name and where its page is, which D63 lets any page say. * * The order is the order the games were supported in, and every list of games on the site * follows it. */ import platform from '../platform.json' with { type: 'json' }; import * as uo from './uo.mjs'; import * as rust from './rust.mjs'; /** * @typedef {object} Game * @property {'uo'|'rust'} key A key of `platform.json`'s `games`. * @property {string} name The game's own name, from `platform.json`. * @property {string} href Its marketing page. * @property {string} docs Its docs group. * @property {string} release Its module's release, from `platform.json`. * @property {string} blurb One sentence in core's words, for the core pages' game cards. * @property {import('../capabilities.mjs').Capability[]} features */ /** @type {Game[]} */ export const games = [ { key: 'uo', name: platform.games.uo.name, href: '/modules/uo/', docs: '/docs/ultima-online/', release: platform.releases['Module-uo'], blurb: 'The first module, and the one the seam was cut around: the server’s live state, its ' + 'economy and its players’ own groups, extracted from the site without changing a URL.', features: uo.features, }, { key: 'rust', name: platform.games.rust.name, href: '/modules/rust/', docs: '/docs/rust/', release: platform.releases['Module-Rust'], blurb: 'Any number of servers, each with its own sidecar: a live feed, leaderboards that ' + 'outlast a reset, a live map, and permissions and events run from the site.', features: [...rust.features, ...rust.staffFeatures], }, ]; for (const key of Object.keys(platform.games)) { if (!games.some((game) => game.key === key)) { throw new Error(`src/data/games/index.mjs has no entry for "${key}", which platform.json's games declares.`); } } /** One game by key, or a build failure naming it. @param {string} key */ export function gameByKey(key) { const game = games.find((candidate) => candidate.key === key); if (game) return game; throw new Error(`src/data/games/index.mjs has no game "${key}". Known: ${games.map((g) => g.key).join(', ')}.`); } /** * Fails the build when a game's feature list and its module's declared capabilities * disagree, in either direction. * * Called from the pages rather than a check script, for the reason phase 3 gave: the failure * should reach whoever is editing the page, and an Astro build error names the component. It * also means `astro build` alone cannot skip it. * * @param {string} key */ export function assertGameCoverage(key) { const game = gameByKey(key); const declared = platform.games[key].module.capabilities; const claimed = new Set(game.features.flatMap((item) => item.caps || [])); const unlisted = declared.filter((cap) => !claimed.has(cap)); const invented = [...claimed].filter((cap) => !declared.includes(cap)); if (!unlisted.length && !invented.length) return; const lines = []; if (unlisted.length) { lines.push( `the module declares ${unlisted.map((c) => `"${c}"`).join(', ')}, which no feature on ` + `its page claims — the site is under-selling what it can show.`, ); } if (invented.length) { lines.push( `the page claims ${invented.map((c) => `"${c}"`).join(', ')}, which the module no ` + `longer declares — the site is advertising something that is gone (§1).`, ); } throw new Error( `src/data/games/${key}.mjs disagrees with platform.json's games.${key}.module.capabilities:\n` + lines.map((line) => ` - ${line}`).join('\n') + `\n\nUpdate the features in src/data/games/${key}.mjs, or the JSON if the module itself changed.\n`, ); }