feat(engine): add achievement icons and reproducible portraits
This commit is contained in:
parent
a5dc982cd3
commit
5499837e23
10 changed files with 701 additions and 11 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@ batch/replay/
|
|||
batch/dist/
|
||||
.pnpm-store
|
||||
.playwright-mcp/
|
||||
/artifacts/achievement-portraits/
|
||||
|
|
|
|||
|
|
@ -7,8 +7,11 @@ or a claim that achievements have been enabled on the hosted service.
|
|||
|
||||
## Hook contract
|
||||
|
||||
- `achievementDefinitions()` returns `{ revision: 1, achievements }`. Each definition
|
||||
has string `id`, `name`, and `description` fields. The complete 36-entry catalog is
|
||||
- `achievementDefinitions()` returns `{ revision: 2, achievements }`. Each definition
|
||||
has string `id`, `name`, and `description` fields and an optional strict `icon`:
|
||||
`{ type: "asset", key: string }` or `{ type: "text", text: string }`. Asset keys
|
||||
match `^[a-z0-9][a-z0-9-]{0,63}$`; text matches `^[A-Za-z0-9]{1,4}$`. No URLs,
|
||||
style, crop, HTML, or SVG payloads are accepted. The complete 36-entry catalog is
|
||||
returned regardless of the current game's ruleset or selected factions.
|
||||
- `achievements(data)` accepts an `Engine` or serialized engine state and returns
|
||||
`{ seat, earned, outcome? }[]`. `earned` contains catalog IDs. The structural
|
||||
|
|
@ -38,12 +41,20 @@ player order after removing Automa players; they are not raw engine player numbe
|
|||
Automa never receives a result. Dropped humans retain their human seat index and
|
||||
return `{ seat, earned: [] }`, with no outcome, rather than shifting later seats.
|
||||
|
||||
## Revision 1 catalog (36 IDs)
|
||||
## Revision 2 catalog (36 stable IDs)
|
||||
|
||||
IDs follow BGS's `^[a-z0-9][a-z0-9-]{0,63}$` validator: lowercase letters,
|
||||
ASCII digits, and hyphens, at most 64 characters. All 36 IDs are unique. The
|
||||
pre-publication dotted spellings were replaced with hyphens; they are not aliases
|
||||
and were never published. The initial manifest therefore remains revision 1.
|
||||
and were never published. Revision 2 adds icons without changing revision 1's IDs
|
||||
or earned predicates: 18 faction asset references, four 150/200 text emblems,
|
||||
and no icon on the remaining 14 definitions.
|
||||
|
||||
**Deployment order:** the platform icon contract (platform commit
|
||||
`fca050c9509c1dec3afd8d4631cc57245f834f29`, platform PR
|
||||
[578](https://codeberg.org/boardgamers/boardgamers/pulls/578)) must be deployed
|
||||
before activating this revision-2 manifest. Older strict validators reject `icon`.
|
||||
No production assets or achievement activation are implied by this source change.
|
||||
|
||||
### Faction victories (18)
|
||||
|
||||
|
|
@ -140,6 +151,57 @@ substitute for a physical colony. Gaiaformers and Lantids' shared/additional min
|
|||
do not satisfy this main-ownership requirement. Lantids' additional mines instead
|
||||
count toward their separate shared-civilization feat.
|
||||
|
||||
## Portrait assets and release procedure
|
||||
|
||||
Faction win icons reference **named game assets**, not viewer-bundle URLs:
|
||||
`achievement-faction-<faction-id>`. Score badges use platform-rendered text `150`
|
||||
or `200`, shared across the two rulesets, and require no uploaded image.
|
||||
|
||||
Source artwork is in `viewer/src/assets/factions/*.jpg`, with provenance in
|
||||
[`viewer/src/assets/factions/README.md`](../viewer/src/assets/factions/README.md).
|
||||
Artwork is by Dennis Lohausen, published by Feuerland Spiele, used with publisher
|
||||
permission as confirmed by BGS; it is **not** covered by the source-code license.
|
||||
The faction `moweyds` intentionally maps to source file `mowyeds.jpg`.
|
||||
|
||||
Generate local release inputs (no network requests or uploads):
|
||||
|
||||
```sh
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm run generate:achievement-portraits
|
||||
pnpm run test:achievement-portraits
|
||||
```
|
||||
|
||||
The generator crops a 167×167 square at x=13, y=0 from each 392×167 header,
|
||||
matching the existing viewer's left-side portrait framing. Outputs are square
|
||||
raster PNGs without a baked-in circular mask; the platform controls presentation.
|
||||
Outputs are written to `artifacts/achievement-portraits/`: 18
|
||||
`achievement-faction-<id>.png` files, `contact-sheet.png` (all 18 labeled crops),
|
||||
and `manifest.json` recording source/output hashes, crop coordinates and toolchain.
|
||||
Review all 18 crops on the generated contact sheet before uploading. Generated
|
||||
assets are ignored build outputs, not committed artwork copies. The source map,
|
||||
crop coordinates and dependency lockfile are the reproducible inputs.
|
||||
|
||||
**Release only after separate publication authorization:**
|
||||
|
||||
1. Deploy the platform's revision-2 icon support first; do not activate this
|
||||
engine's icon manifest against an older strict schema.
|
||||
2. Generate and visually inspect the portraits locally. Keep the generated
|
||||
input/output hash manifest with the release verification record.
|
||||
3. For each generated `achievement-faction-<id>.png`, upload its raw bytes to
|
||||
`PUT /api/admin/gameinfo/gaia-project/assets/achievement-faction-<id>` with
|
||||
`Content-Type: image/png` and the authorized admin bearer token. This is the
|
||||
**version-independent named game asset** endpoint, not `/gaia-project/3/viewer`.
|
||||
Do not upload the contact sheet or hash manifest as achievement images.
|
||||
4. BGS re-encodes images to WebP and records the content-hashed URL under the
|
||||
metadata asset key. Verify all 18 keys resolve to the expected portraits and
|
||||
verify the platform fallback for a missing asset. Do not invent public URLs
|
||||
or embed them in engine definitions; viewer-bundle retention is irrelevant.
|
||||
5. Only then publish/activate the engine/catalog through the normal authorized
|
||||
release workflow and verify portraits and 150/200 emblems in the platform UI.
|
||||
|
||||
This PR generates inputs only: no named asset is claimed to exist in production,
|
||||
and no upload, engine publication, npm publication or BGS activation is performed.
|
||||
|
||||
## Verification and scope
|
||||
|
||||
Predicate tests may construct or modify final-state counters, scores, ownership,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Javascript engine for Gaia Project.
|
|||
|
||||
## Achievements
|
||||
|
||||
See the [achievement hooks and revision 1 catalog](../docs/achievements.md) for the
|
||||
See the [achievement hooks and revision 2 catalog](../docs/achievements.md) for the
|
||||
optional BGS contract, completion requirements, award semantics, and verification scope.
|
||||
|
||||
## Play online at
|
||||
|
|
|
|||
|
|
@ -54,10 +54,10 @@ function solo(difficulty = "automa"): Record<string, any> {
|
|||
}
|
||||
|
||||
describe("BGS achievement hooks", () => {
|
||||
it("exports a complete, unique, isolated revision-1 catalog", () => {
|
||||
it("exports a complete, unique, isolated revision-2 catalog", () => {
|
||||
const manifest = achievementDefinitions();
|
||||
const ids = manifest.achievements.map((definition) => definition.id);
|
||||
expect(manifest.revision).to.equal(1);
|
||||
expect(manifest.revision).to.equal(2);
|
||||
expect(ids).to.have.length(36);
|
||||
expect(new Set(ids).size).to.equal(ids.length);
|
||||
// BGS packages/protocol/achievements.ts: achievementIdSchema.
|
||||
|
|
@ -69,6 +69,46 @@ describe("BGS achievement hooks", () => {
|
|||
expect(achievementDefinitions().achievements[0].name).not.to.equal("mutated");
|
||||
});
|
||||
|
||||
it("adds only 18 named faction assets and four score text emblems without changing IDs", () => {
|
||||
const definitions = achievementDefinitions().achievements;
|
||||
const assets = definitions.filter((definition) => definition.icon?.type === "asset");
|
||||
const texts = definitions.filter((definition) => definition.icon?.type === "text");
|
||||
expect(assets).to.have.length(18);
|
||||
expect(texts).to.have.length(4);
|
||||
for (const faction of Faction.values(Expansion.All)) {
|
||||
expect(definitions.find((definition) => definition.id === `win-faction-${faction}`).icon).to.deep.equal({
|
||||
type: "asset",
|
||||
key: `achievement-faction-${faction}`,
|
||||
});
|
||||
}
|
||||
for (const mode of ["base", "lost-fleet"]) {
|
||||
for (const score of [150, 200]) {
|
||||
expect(definitions.find((definition) => definition.id === `score-${mode}-${score}`).icon).to.deep.equal({
|
||||
type: "text",
|
||||
text: String(score),
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const definition of definitions) {
|
||||
const icon = definition.icon;
|
||||
if (icon?.type === "asset") {
|
||||
expect(Object.keys(icon).sort()).to.deep.equal(["key", "type"]);
|
||||
expect(icon.key).to.match(/^[a-z0-9][a-z0-9-]{0,63}$/);
|
||||
} else if (icon?.type === "text") {
|
||||
expect(Object.keys(icon).sort()).to.deep.equal(["text", "type"]);
|
||||
expect(icon.text).to.match(/^[A-Za-z0-9]{1,4}$/);
|
||||
} else {
|
||||
expect(definition).not.to.have.property("icon");
|
||||
expect(definition.id.startsWith("win-faction-") || definition.id.startsWith("score-")).to.equal(false);
|
||||
}
|
||||
}
|
||||
const first = assets[0];
|
||||
if (first.icon.type === "asset") first.icon.key = "mutated";
|
||||
expect(
|
||||
achievementDefinitions().achievements.find((definition) => definition.id === first.id).icon
|
||||
).not.to.deep.equal(first.icon);
|
||||
});
|
||||
|
||||
it("hydrates the existing completed fixture, agrees with wrapper outcomes, and is deterministic", () => {
|
||||
const data = state();
|
||||
const engine = Engine.fromData(state());
|
||||
|
|
|
|||
|
|
@ -3,10 +3,13 @@ import Engine from "./engine";
|
|||
import { Building, Expansion, Faction, Phase, Planet, ResearchField, Round } from "./enums";
|
||||
|
||||
// Structural BGS protocol types: optional named exports need no runtime protocol dependency.
|
||||
export type AchievementIcon = { type: "asset"; key: string } | { type: "text"; text: string };
|
||||
|
||||
export interface AchievementDefinition {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
icon?: AchievementIcon;
|
||||
}
|
||||
|
||||
export interface AchievementManifest {
|
||||
|
|
@ -52,6 +55,7 @@ function displayName(id: string): string {
|
|||
export function achievementDefinitions(): AchievementManifest {
|
||||
const definitions: AchievementDefinition[] = Faction.values(Expansion.All).map((faction) => ({
|
||||
id: `win-faction-${faction}`,
|
||||
icon: { type: "asset", key: `achievement-faction-${faction}` },
|
||||
name: `${displayName(faction)} Victory`,
|
||||
description: `Win as ${displayName(faction)}. Shared first place counts; either ruleset qualifies.`,
|
||||
}));
|
||||
|
|
@ -65,6 +69,7 @@ export function achievementDefinitions(): AchievementManifest {
|
|||
for (const threshold of [150, 200]) {
|
||||
definitions.push({
|
||||
id: `score-${mode}-${threshold}`,
|
||||
icon: { type: "text", text: String(threshold) },
|
||||
name: `${name}: ${threshold} Points`,
|
||||
description: `Finish a ${name} game with at least ${threshold} final victory points, after auction deductions. No win required.`,
|
||||
});
|
||||
|
|
@ -118,7 +123,7 @@ export function achievementDefinitions(): AchievementManifest {
|
|||
description: "As Bescods, finish at level 3 or higher on all six research tracks. No win required.",
|
||||
}
|
||||
);
|
||||
return { revision: 1, achievements: definitions };
|
||||
return { revision: 2, achievements: definitions };
|
||||
}
|
||||
|
||||
/** Evaluate authoritative completed state only; never advance play or recompute final scoring. */
|
||||
|
|
|
|||
|
|
@ -7,13 +7,16 @@
|
|||
"prettier": "prettier --write .",
|
||||
"prettier-check": "prettier --check .",
|
||||
"test": "vitest run",
|
||||
"test:locales": "node scripts/check-locales.mjs viewer/src/localization && node --test scripts/localization.test.mjs"
|
||||
"test:locales": "node scripts/check-locales.mjs viewer/src/localization && node --test scripts/localization.test.mjs",
|
||||
"generate:achievement-portraits": "node scripts/generate-achievement-portraits.mjs",
|
||||
"test:achievement-portraits": "node --test scripts/achievement-portraits.test.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"husky": "^5.0.9",
|
||||
"lint-staged": "^10.5.4",
|
||||
"prettier": "^3.9.6",
|
||||
"prettier-plugin-organize-imports": "^4.3.0",
|
||||
"sharp": "0.34.5",
|
||||
"typescript": "^5.9.3",
|
||||
"vue-tsc": "^2.2.12"
|
||||
},
|
||||
|
|
|
|||
296
pnpm-lock.yaml
generated
296
pnpm-lock.yaml
generated
|
|
@ -20,6 +20,9 @@ importers:
|
|||
prettier-plugin-organize-imports:
|
||||
specifier: ^4.3.0
|
||||
version: 4.3.0(prettier@3.9.6)(typescript@5.9.3)(vue-tsc@2.2.12(typescript@5.9.3))
|
||||
sharp:
|
||||
specifier: 0.34.5
|
||||
version: 0.34.5
|
||||
typescript:
|
||||
specifier: ^5.9.3
|
||||
version: 5.9.3
|
||||
|
|
@ -6950,6 +6953,167 @@ packages:
|
|||
zod@4.6.2:
|
||||
resolution: {integrity: sha512-lh5RCAGFa1Cm2hjtNwLQhSs/AsqdWnTQaBER9fEwN/88pSh7KOtJavtBx/0VlkN/uFd61SwYmljLMDAsHlvzBQ==}
|
||||
|
||||
'@emnapi/runtime@1.11.3':
|
||||
resolution: {integrity: sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==}
|
||||
|
||||
'@img/colour@1.1.0':
|
||||
resolution: {integrity: sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
'@img/sharp-darwin-arm64@0.34.5':
|
||||
resolution: {integrity: sha512-imtQ3WMJXbMY4fxb/Ndp6HBTNVtWCUI0WdobyheGf5+ad6xX8VIDO8u2xE4qc/fr08CKG/7dDseFtn6M6g/r3w==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
'@img/sharp-darwin-x64@0.34.5':
|
||||
resolution: {integrity: sha512-YNEFAF/4KQ/PeW0N+r+aVVsoIY0/qxxikF2SWdp+NRkmMB7y9LBZAVqQ4yhGCm/H3H270OSykqmQMKLBhBJDEw==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
'@img/sharp-libvips-darwin-arm64@1.2.4':
|
||||
resolution: {integrity: sha512-zqjjo7RatFfFoP0MkQ51jfuFZBnVE2pRiaydKJ1G/rHZvnsrHAOcQALIi9sA5co5xenQdTugCvtb1cuf78Vf4g==}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
'@img/sharp-libvips-darwin-x64@1.2.4':
|
||||
resolution: {integrity: sha512-1IOd5xfVhlGwX+zXv2N93k0yMONvUlANylbJw1eTah8K/Jtpi15KC+WSiaX/nBmbm2HxRM1gZ0nSdjSsrZbGKg==}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
'@img/sharp-libvips-linux-arm64@1.2.4':
|
||||
resolution: {integrity: sha512-excjX8DfsIcJ10x1Kzr4RcWe1edC9PquDRRPx3YVCvQv+U5p7Yin2s32ftzikXojb1PIFc/9Mt28/y+iRklkrw==}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-libvips-linux-arm@1.2.4':
|
||||
resolution: {integrity: sha512-bFI7xcKFELdiNCVov8e44Ia4u2byA+l3XtsAj+Q8tfCwO6BQ8iDojYdvoPMqsKDkuoOo+X6HZA0s0q11ANMQ8A==}
|
||||
cpu: [arm]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-libvips-linux-ppc64@1.2.4':
|
||||
resolution: {integrity: sha512-FMuvGijLDYG6lW+b/UvyilUWu5Ayu+3r2d1S8notiGCIyYU/76eig1UfMmkZ7vwgOrzKzlQbFSuQfgm7GYUPpA==}
|
||||
cpu: [ppc64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-libvips-linux-riscv64@1.2.4':
|
||||
resolution: {integrity: sha512-oVDbcR4zUC0ce82teubSm+x6ETixtKZBh/qbREIOcI3cULzDyb18Sr/Wcyx7NRQeQzOiHTNbZFF1UwPS2scyGA==}
|
||||
cpu: [riscv64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-libvips-linux-s390x@1.2.4':
|
||||
resolution: {integrity: sha512-qmp9VrzgPgMoGZyPvrQHqk02uyjA0/QrTO26Tqk6l4ZV0MPWIW6LTkqOIov+J1yEu7MbFQaDpwdwJKhbJvuRxQ==}
|
||||
cpu: [s390x]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-libvips-linux-x64@1.2.4':
|
||||
resolution: {integrity: sha512-tJxiiLsmHc9Ax1bz3oaOYBURTXGIRDODBqhveVHonrHJ9/+k89qbLl0bcJns+e4t4rvaNBxaEZsFtSfAdquPrw==}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-libvips-linuxmusl-arm64@1.2.4':
|
||||
resolution: {integrity: sha512-FVQHuwx1IIuNow9QAbYUzJ+En8KcVm9Lk5+uGUQJHaZmMECZmOlix9HnH7n1TRkXMS0pGxIJokIVB9SuqZGGXw==}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
'@img/sharp-libvips-linuxmusl-x64@1.2.4':
|
||||
resolution: {integrity: sha512-+LpyBk7L44ZIXwz/VYfglaX/okxezESc6UxDSoyo2Ks6Jxc4Y7sGjpgU9s4PMgqgjj1gZCylTieNamqA1MF7Dg==}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
'@img/sharp-linux-arm64@0.34.5':
|
||||
resolution: {integrity: sha512-bKQzaJRY/bkPOXyKx5EVup7qkaojECG6NLYswgktOZjaXecSAeCWiZwwiFf3/Y+O1HrauiE3FVsGxFg8c24rZg==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-linux-arm@0.34.5':
|
||||
resolution: {integrity: sha512-9dLqsvwtg1uuXBGZKsxem9595+ujv0sJ6Vi8wcTANSFpwV/GONat5eCkzQo/1O6zRIkh0m/8+5BjrRr7jDUSZw==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-linux-ppc64@0.34.5':
|
||||
resolution: {integrity: sha512-7zznwNaqW6YtsfrGGDA6BRkISKAAE1Jo0QdpNYXNMHu2+0dTrPflTLNkpc8l7MUP5M16ZJcUvysVWWrMefZquA==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [ppc64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-linux-riscv64@0.34.5':
|
||||
resolution: {integrity: sha512-51gJuLPTKa7piYPaVs8GmByo7/U7/7TZOq+cnXJIHZKavIRHAP77e3N2HEl3dgiqdD/w0yUfiJnII77PuDDFdw==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [riscv64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-linux-s390x@0.34.5':
|
||||
resolution: {integrity: sha512-nQtCk0PdKfho3eC5MrbQoigJ2gd1CgddUMkabUj+rBevs8tZ2cULOx46E7oyX+04WGfABgIwmMC0VqieTiR4jg==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [s390x]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-linux-x64@0.34.5':
|
||||
resolution: {integrity: sha512-MEzd8HPKxVxVenwAa+JRPwEC7QFjoPWuS5NZnBt6B3pu7EG2Ge0id1oLHZpPJdn3OQK+BQDiw9zStiHBTJQQQQ==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@img/sharp-linuxmusl-arm64@0.34.5':
|
||||
resolution: {integrity: sha512-fprJR6GtRsMt6Kyfq44IsChVZeGN97gTD331weR1ex1c1rypDEABN6Tm2xa1wE6lYb5DdEnk03NZPqA7Id21yg==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
'@img/sharp-linuxmusl-x64@0.34.5':
|
||||
resolution: {integrity: sha512-Jg8wNT1MUzIvhBFxViqrEhWDGzqymo3sV7z7ZsaWbZNDLXRJZoRGrjulp60YYtV4wfY8VIKcWidjojlLcWrd8Q==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
'@img/sharp-wasm32@0.34.5':
|
||||
resolution: {integrity: sha512-OdWTEiVkY2PHwqkbBI8frFxQQFekHaSSkUIJkwzclWZe64O1X4UlUjqqqLaPbUpMOQk6FBu/HtlGXNblIs0huw==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [wasm32]
|
||||
|
||||
'@img/sharp-win32-arm64@0.34.5':
|
||||
resolution: {integrity: sha512-WQ3AgWCWYSb2yt+IG8mnC6Jdk9Whs7O0gxphblsLvdhSpSTtmu69ZG1Gkb6NuvxsNACwiPV6cNSZNzt0KPsw7g==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm64]
|
||||
os: [win32]
|
||||
|
||||
'@img/sharp-win32-ia32@0.34.5':
|
||||
resolution: {integrity: sha512-FV9m/7NmeCmSHDD5j4+4pNI8Cp3aW+JvLoXcTUo0IqyjSfAZJ8dIUmijx1qaJsIiU+Hosw6xM5KijAWRJCSgNg==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [ia32]
|
||||
os: [win32]
|
||||
|
||||
'@img/sharp-win32-x64@0.34.5':
|
||||
resolution: {integrity: sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
|
||||
sharp@0.34.5:
|
||||
resolution: {integrity: sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
|
||||
|
||||
snapshots:
|
||||
|
||||
'@achrinza/node-ipc@9.2.2':
|
||||
|
|
@ -15098,3 +15262,135 @@ snapshots:
|
|||
strip-indent: 2.0.0
|
||||
|
||||
zod@4.6.2: {}
|
||||
|
||||
'@emnapi/runtime@1.11.3':
|
||||
dependencies:
|
||||
tslib: 2.8.1
|
||||
optional: true
|
||||
|
||||
'@img/colour@1.1.0': {}
|
||||
|
||||
'@img/sharp-darwin-arm64@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-darwin-arm64': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-darwin-x64@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-darwin-x64': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-darwin-arm64@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-darwin-x64@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-arm64@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-arm@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-ppc64@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-riscv64@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-s390x@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-x64@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linuxmusl-arm64@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linuxmusl-x64@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-arm64@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-arm64': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-arm@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-arm': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-ppc64@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-ppc64': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-riscv64@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-riscv64': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-s390x@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-s390x': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-x64@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-x64': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linuxmusl-arm64@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linuxmusl-arm64': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linuxmusl-x64@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linuxmusl-x64': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-wasm32@0.34.5':
|
||||
dependencies:
|
||||
'@emnapi/runtime': 1.11.3
|
||||
optional: true
|
||||
|
||||
'@img/sharp-win32-arm64@0.34.5':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-win32-ia32@0.34.5':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-win32-x64@0.34.5':
|
||||
optional: true
|
||||
|
||||
sharp@0.34.5:
|
||||
dependencies:
|
||||
'@img/colour': 1.1.0
|
||||
detect-libc: 2.1.2
|
||||
semver: 7.8.5
|
||||
optionalDependencies:
|
||||
'@img/sharp-darwin-arm64': 0.34.5
|
||||
'@img/sharp-darwin-x64': 0.34.5
|
||||
'@img/sharp-libvips-darwin-arm64': 1.2.4
|
||||
'@img/sharp-libvips-darwin-x64': 1.2.4
|
||||
'@img/sharp-libvips-linux-arm': 1.2.4
|
||||
'@img/sharp-libvips-linux-arm64': 1.2.4
|
||||
'@img/sharp-libvips-linux-ppc64': 1.2.4
|
||||
'@img/sharp-libvips-linux-riscv64': 1.2.4
|
||||
'@img/sharp-libvips-linux-s390x': 1.2.4
|
||||
'@img/sharp-libvips-linux-x64': 1.2.4
|
||||
'@img/sharp-libvips-linuxmusl-arm64': 1.2.4
|
||||
'@img/sharp-libvips-linuxmusl-x64': 1.2.4
|
||||
'@img/sharp-linux-arm': 0.34.5
|
||||
'@img/sharp-linux-arm64': 0.34.5
|
||||
'@img/sharp-linux-ppc64': 0.34.5
|
||||
'@img/sharp-linux-riscv64': 0.34.5
|
||||
'@img/sharp-linux-s390x': 0.34.5
|
||||
'@img/sharp-linux-x64': 0.34.5
|
||||
'@img/sharp-linuxmusl-arm64': 0.34.5
|
||||
'@img/sharp-linuxmusl-x64': 0.34.5
|
||||
'@img/sharp-wasm32': 0.34.5
|
||||
'@img/sharp-win32-arm64': 0.34.5
|
||||
'@img/sharp-win32-ia32': 0.34.5
|
||||
'@img/sharp-win32-x64': 0.34.5
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ packages:
|
|||
- "engine"
|
||||
- "old-ui"
|
||||
# pnpm 11 (resolved via corepack in CI) blocks dependency postinstall scripts by default.
|
||||
# These are all no-op or cosmetic (core-js/ejs banners, an optional native watcher);
|
||||
# allow them so `pnpm install` exits 0.
|
||||
# Allow the existing dependency setup scripts and Sharp's native-library check
|
||||
# (used by the local achievement-portrait generator) so `pnpm install` exits 0.
|
||||
allowBuilds:
|
||||
"@parcel/watcher": true
|
||||
bootstrap-vue: true
|
||||
|
|
@ -13,6 +13,7 @@ allowBuilds:
|
|||
ejs: true
|
||||
esbuild: true
|
||||
nodent-runtime: true
|
||||
sharp: true
|
||||
yorkie: true
|
||||
minimumReleaseAgeExclude:
|
||||
- "@boardgamers/protocol@0.2.2 || 0.3.3 || 0.3.4 || 0.4.0 || 0.4.2 || 0.5.0 || 0.6.0 || 0.6.1 || 0.6.2 || 0.8.1 || 0.10.0"
|
||||
|
|
|
|||
112
scripts/achievement-portraits.test.mjs
Normal file
112
scripts/achievement-portraits.test.mjs
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, readFile, readdir, rm } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import sharp from "sharp";
|
||||
import {
|
||||
CROP,
|
||||
FACTIONS,
|
||||
SOURCE_DIR,
|
||||
generatePortraits,
|
||||
sha256,
|
||||
sourceName,
|
||||
validateCrop,
|
||||
} from "./generate-achievement-portraits.mjs";
|
||||
|
||||
test("18 unique faction mappings, including the legacy Moweyds filename", async () => {
|
||||
assert.equal(FACTIONS.length, 18);
|
||||
assert.equal(new Set(FACTIONS).size, 18);
|
||||
assert.equal(sourceName("moweyds"), "mowyeds.jpg");
|
||||
for (const id of FACTIONS.filter((id) => id !== "moweyds")) assert.equal(sourceName(id), `${id}.jpg`);
|
||||
assert.deepEqual(
|
||||
(await readdir(SOURCE_DIR)).filter((name) => name.endsWith(".jpg")).sort(),
|
||||
FACTIONS.map(sourceName).sort()
|
||||
);
|
||||
assert.deepEqual(CROP, { left: 13, top: 0, width: 167, height: 167 });
|
||||
assert.doesNotThrow(() => validateCrop(392, 167));
|
||||
for (const crop of [
|
||||
{ ...CROP, left: -1 },
|
||||
{ ...CROP, top: 1 },
|
||||
{ ...CROP, left: 226 },
|
||||
{ ...CROP, width: 0 },
|
||||
{ ...CROP, height: 168 },
|
||||
{ ...CROP, left: 1.5 },
|
||||
])
|
||||
assert.throws(() => validateCrop(392, 167, crop), /bounds/);
|
||||
});
|
||||
|
||||
test("generation is byte-deterministic, exact pixel crops, labeled contact sheet, and read-only sources", async () => {
|
||||
const temporary = await mkdtemp(path.join(os.tmpdir(), "achievement-portraits-"));
|
||||
const sourceFiles = await readdir(SOURCE_DIR);
|
||||
const before = new Map(
|
||||
await Promise.all(sourceFiles.map(async (name) => [name, sha256(await readFile(path.join(SOURCE_DIR, name)))]))
|
||||
);
|
||||
try {
|
||||
const first = path.join(temporary, "first");
|
||||
const second = path.join(temporary, "second");
|
||||
const manifest = await generatePortraits(first);
|
||||
assert.deepEqual(await generatePortraits(second), manifest);
|
||||
const expectedFiles = [
|
||||
...FACTIONS.map((id) => `achievement-faction-${id}.png`),
|
||||
"contact-sheet.png",
|
||||
"manifest.json",
|
||||
].sort();
|
||||
assert.deepEqual((await readdir(first)).sort(), expectedFiles);
|
||||
assert.deepEqual((await readdir(second)).sort(), expectedFiles);
|
||||
for (const name of expectedFiles)
|
||||
assert.deepEqual(await readFile(path.join(first, name)), await readFile(path.join(second, name)));
|
||||
assert.deepEqual(JSON.parse(await readFile(path.join(first, "manifest.json"), "utf8")), manifest);
|
||||
assert.equal(manifest.portraits.length, 18);
|
||||
for (const item of manifest.portraits) {
|
||||
const original = await readFile(path.join(SOURCE_DIR, sourceName(item.faction)));
|
||||
assert.equal(item.input.sha256, sha256(original));
|
||||
const source = await sharp(original).removeAlpha().raw().toBuffer({ resolveWithObject: true });
|
||||
assert.equal(source.info.width, 392);
|
||||
assert.equal(source.info.height, 167);
|
||||
const png = await readFile(path.join(first, item.output.path));
|
||||
assert.equal(sha256(png), item.output.sha256);
|
||||
const metadata = await sharp(png).metadata();
|
||||
assert.equal(metadata.format, "png");
|
||||
assert.equal(metadata.width, 167);
|
||||
assert.equal(metadata.height, 167);
|
||||
const actual = await sharp(png).removeAlpha().raw().toBuffer();
|
||||
// Independently slice decoded source scanlines rather than reuse sharp.extract.
|
||||
const expected = Buffer.concat(
|
||||
Array.from({ length: 167 }, (_, y) => {
|
||||
const start = (y * 392 + 13) * source.info.channels;
|
||||
return source.data.subarray(start, start + 167 * source.info.channels);
|
||||
})
|
||||
);
|
||||
assert.deepEqual(actual, expected, item.faction);
|
||||
}
|
||||
const contact = await readFile(path.join(first, "contact-sheet.png"));
|
||||
assert.equal(sha256(contact), manifest.contactSheet.sha256);
|
||||
const metadata = await sharp(contact).metadata();
|
||||
assert.equal(metadata.width, 1146);
|
||||
assert.equal(metadata.height, 615);
|
||||
for (let i = 0; i < 18; i++) {
|
||||
const left = (i % 6) * 191;
|
||||
const top = Math.floor(i / 6) * 205;
|
||||
const portrait = await sharp(contact)
|
||||
.extract({ left: left + 12, top: top + 8, width: 167, height: 167 })
|
||||
.removeAlpha()
|
||||
.raw()
|
||||
.toBuffer();
|
||||
const expected = await sharp(path.join(first, manifest.portraits[i].output.path)).removeAlpha().raw().toBuffer();
|
||||
assert.deepEqual(portrait, expected);
|
||||
const label = await sharp(contact)
|
||||
.extract({ left, top: top + 179, width: 191, height: 20 })
|
||||
.removeAlpha()
|
||||
.raw()
|
||||
.toBuffer();
|
||||
assert.ok(label.includes(240), `Visible label for ${FACTIONS[i]}`);
|
||||
assert.ok(label.includes(24));
|
||||
}
|
||||
} finally {
|
||||
await rm(temporary, { recursive: true, force: true });
|
||||
assert.deepEqual(await readdir(SOURCE_DIR), sourceFiles);
|
||||
for (const [name, hash] of before)
|
||||
assert.equal(sha256(await readFile(path.join(SOURCE_DIR, name))), hash, `Source modified: ${name}`);
|
||||
}
|
||||
});
|
||||
170
scripts/generate-achievement-portraits.mjs
Normal file
170
scripts/generate-achievement-portraits.mjs
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
import { createHash } from "node:crypto";
|
||||
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import sharp from "sharp";
|
||||
|
||||
export const ROOT = fileURLToPath(new URL("../", import.meta.url));
|
||||
export const SOURCE_DIR = path.join(ROOT, "viewer/src/assets/factions");
|
||||
export const OUTPUT_DIR = path.join(ROOT, "artifacts/achievement-portraits");
|
||||
export const CROP = Object.freeze({ left: 13, top: 0, width: 167, height: 167 });
|
||||
export const FACTIONS = Object.freeze([
|
||||
"ambas",
|
||||
"baltaks",
|
||||
"bescods",
|
||||
"darkanians",
|
||||
"firaks",
|
||||
"geodens",
|
||||
"gleens",
|
||||
"hadsch-hallas",
|
||||
"itars",
|
||||
"ivits",
|
||||
"lantids",
|
||||
"moweyds",
|
||||
"nevlas",
|
||||
"space-giants",
|
||||
"taklons",
|
||||
"terrans",
|
||||
"tinkeroids",
|
||||
"xenos",
|
||||
]);
|
||||
export const sourceName = (id) => `${id === "moweyds" ? "mowyeds" : id}.jpg`;
|
||||
export const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
||||
const PNG = Object.freeze({ compressionLevel: 9, adaptiveFiltering: false, palette: false });
|
||||
const CELL = { width: 191, height: 205, columns: 6, rows: 3 };
|
||||
|
||||
// Fixed 5x7 column bitmaps: no system fonts, Pango, markup or SVG rendering.
|
||||
// Labels use uppercase glyphs for the static faction IDs; bit 0 is the top row.
|
||||
const GLYPHS = Object.fromEntries(
|
||||
"A:7e1111117e B:7f49494936 C:3e41414122 D:7f4141221c E:7f49494941 F:7f09090901 G:3e41495132 H:7f0808087f I:00417f4100 J:2040413f01 K:7f08142241 L:7f40404040 M:7f020c027f N:7f0408107f O:3e4141413e P:7f09090906 Q:3e4151215e R:7f09192946 S:4649494931 T:01017f0101 U:3f4040403f V:1f2040201f W:3f4038403f X:6314081463 Y:0708700807 Z:6151494543 -:0808080808"
|
||||
.split(" ")
|
||||
.map((entry) => {
|
||||
const [letter, hex] = entry.split(":");
|
||||
return [letter, Buffer.from(hex, "hex")];
|
||||
})
|
||||
);
|
||||
|
||||
function label(text) {
|
||||
const width = CELL.width;
|
||||
const height = 20;
|
||||
const data = Buffer.alloc(width * height * 3, 24);
|
||||
const scale = 2;
|
||||
const start = Math.floor((width - (text.length * 6 - 1) * scale) / 2);
|
||||
for (const [index, character] of [...text.toUpperCase()].entries()) {
|
||||
const glyph = GLYPHS[character];
|
||||
if (!glyph) throw new Error(`Unsupported label character: ${character}`);
|
||||
for (let x = 0; x < 5; x++)
|
||||
for (let y = 0; y < 7; y++) {
|
||||
if (!(glyph[x] & (1 << y))) continue;
|
||||
for (let dx = 0; dx < scale; dx++)
|
||||
for (let dy = 0; dy < scale; dy++) {
|
||||
const offset = ((y * scale + dy + 3) * width + start + index * 12 + x * scale + dx) * 3;
|
||||
data.fill(240, offset, offset + 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { input: data, raw: { width, height, channels: 3 } };
|
||||
}
|
||||
|
||||
export function validateCrop(width, height, crop = CROP) {
|
||||
if (
|
||||
![width, height, crop.left, crop.top, crop.width, crop.height].every(Number.isInteger) ||
|
||||
crop.left < 0 ||
|
||||
crop.top < 0 ||
|
||||
crop.width <= 0 ||
|
||||
crop.height <= 0 ||
|
||||
crop.left + crop.width > width ||
|
||||
crop.top + crop.height > height
|
||||
) {
|
||||
throw new Error("Crop is outside source bounds");
|
||||
}
|
||||
}
|
||||
|
||||
export async function generatePortraits(outputDir = OUTPUT_DIR) {
|
||||
// Only the destination changes in tests. Source files and crop policy are fixed.
|
||||
const files = (await readdir(SOURCE_DIR)).filter((name) => /\.jpe?g$/i.test(name)).sort();
|
||||
const expected = FACTIONS.map(sourceName).sort();
|
||||
if (JSON.stringify(files) !== JSON.stringify(expected))
|
||||
throw new Error("Expected exactly the 18 mapped faction JPGs");
|
||||
const portraits = [];
|
||||
const composites = [];
|
||||
const outputs = [];
|
||||
for (const [index, faction] of FACTIONS.entries()) {
|
||||
const input = await readFile(path.join(SOURCE_DIR, sourceName(faction)));
|
||||
const metadata = await sharp(input).metadata();
|
||||
if (metadata.width !== 392 || metadata.height !== 167) throw new Error(`Unexpected dimensions: ${faction}`);
|
||||
validateCrop(metadata.width, metadata.height);
|
||||
const png = await sharp(input).extract(CROP).png(PNG).toBuffer();
|
||||
const filename = `achievement-faction-${faction}.png`;
|
||||
outputs.push([filename, png]);
|
||||
portraits.push({
|
||||
faction,
|
||||
input: {
|
||||
path: `viewer/src/assets/factions/${sourceName(faction)}`,
|
||||
sha256: sha256(input),
|
||||
width: 392,
|
||||
height: 167,
|
||||
},
|
||||
crop: CROP,
|
||||
output: { path: filename, sha256: sha256(png), width: 167, height: 167 },
|
||||
});
|
||||
const left = (index % CELL.columns) * CELL.width;
|
||||
const top = Math.floor(index / CELL.columns) * CELL.height;
|
||||
composites.push({ input: png, left: left + 12, top: top + 8 });
|
||||
composites.push({ ...label(faction), left, top: top + 179 });
|
||||
}
|
||||
const contact = await sharp({
|
||||
create: {
|
||||
width: CELL.width * CELL.columns,
|
||||
height: CELL.height * CELL.rows,
|
||||
channels: 3,
|
||||
background: "#181818",
|
||||
},
|
||||
})
|
||||
.composite(composites)
|
||||
.png(PNG)
|
||||
.toBuffer();
|
||||
const manifest = {
|
||||
schemaVersion: 1,
|
||||
generator: {
|
||||
path: "scripts/generate-achievement-portraits.mjs",
|
||||
sha256: sha256(await readFile(fileURLToPath(import.meta.url))),
|
||||
},
|
||||
// No timestamp or absolute path: identical inputs/toolchain give identical artifacts.
|
||||
toolchain: {
|
||||
node: process.versions.node,
|
||||
platform: process.platform,
|
||||
arch: process.arch,
|
||||
libraries: sharp.versions,
|
||||
},
|
||||
png: PNG,
|
||||
portraits,
|
||||
contactSheet: {
|
||||
path: "contact-sheet.png",
|
||||
sha256: sha256(contact),
|
||||
width: CELL.width * CELL.columns,
|
||||
height: CELL.height * CELL.rows,
|
||||
layout: CELL,
|
||||
},
|
||||
};
|
||||
// All inputs are checked and all images rendered before any output is written.
|
||||
await mkdir(outputDir, { recursive: true });
|
||||
for (const [name, bytes] of [
|
||||
...outputs,
|
||||
["contact-sheet.png", contact],
|
||||
["manifest.json", JSON.stringify(manifest, null, 2) + "\n"],
|
||||
]) {
|
||||
await writeFile(path.join(outputDir, name), bytes);
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
if (process.argv.length !== 2) {
|
||||
console.error("Usage: pnpm generate:achievement-portraits (writes artifacts/achievement-portraits)");
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
await generatePortraits();
|
||||
console.log(`Generated 18 portraits, contact-sheet.png and manifest.json in ${OUTPUT_DIR}`);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue