8000 perf: menus that show at once, one layout rule for every screen by alexiscolin · Pull Request #1 · alexiscolin/gnogolf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2bf094f
perf(maps): build course maps from the repo, cache community maps
alexiscolin Nov 25, 2026
8dc88e0
feat(menu): show the network and help chips in rounds only
alexiscolin Nov 25, 2026
9e2e326
perf(duel): static portraits, instant maps, board on the picks grid
alexiscolin Nov 25, 2026
399ce26
perf(builder): show the start at once, put building first
alexiscolin Nov 25, 2026
ce66f6a
perf(title): warm the first screens during the title
alexiscolin Nov 25, 2026
8d467fb
fix(duel): fit the whole screen at 1280x800
alexiscolin Nov 25, 2026
4ec60fb
docs: document the course map and portrait scripts
alexiscolin Nov 25, 2026
ad3daa3
perf(title): hold the loader for the next screens' files
alexiscolin Nov 25, 2026
89d78d4
fix(gnomes): show collection thumbnails in panel discs
alexiscolin Nov 25, 2026
624db55
test(shop): no network chip on menu screens
alexiscolin Nov 25, 2026
f6a2e3f
perf(duel): fetch both board pages together
alexiscolin Nov 25, 2026
a079ea5
perf(title): hold for the menu's pictures only
alexiscolin Nov 25, 2026
1f36b42
fix(builder): read drafts before the first paint
alexiscolin Nov 25, 2026
df0dd6d
perf(menu): prefetch rival picks and the Builder on desktop
alexiscolin Nov 25, 2026
60d78a6
fix(menu): prefetch the Builder from the menu, not the title
alexiscolin Nov 25, 2026
f5fb54e
perf(idle): let pending idle jobs be cancelled
alexiscolin Nov 25, 2026
e3ded45
fix(maps): match course maps by data hash, version the cache
alexiscolin Nov 25, 2026
15942de
perf(title): hold for the first screen only, idle-load the rest
alexiscolin Nov 25, 2026
047f460
fix(about): add Feedback next to Support
alexiscolin Nov 25, 2026
4ba5866
fix(duel): never surprise with the same player twice in a row
alexiscolin Nov 25, 2026
8f947fa
fix(builder): say when the checker fails to load, offer a retry
alexiscolin Nov 25, 2026
e4dae88
perf(portraits): render at 2x, cache for a day
alexiscolin Nov 25, 2026
9a670ef
fix(picker): stop the live canvas pulsing while its picture loads
alexiscolin Nov 25, 2026
5aa19a4
feat(menu): stagger the placeholder pulses
alexiscolin Nov 25, 2026
dda1a36
fix(menu): let mode cards fill a phone screen
alexiscolin Nov 25, 2026
a290eaa
fix(builder): clamp badge text to two lines, align the cards
alexiscolin Nov 25, 2026
c60bd00
fix(builder): keep a loading card at its final height
alexiscolin Nov 25, 2026
b484502
feat(menu): squash and stretch the gnome hop
alexiscolin Nov 25, 2026
8455636
fix(duel): keep the eyebrow on short windows like other screens
alexiscolin Nov 25, 2026
be88286
fix(menu): pin the head on every screen, center the body
alexiscolin Nov 25, 2026
ef9ba44
fix(duel): cap the Yourself disc at 160px
alexiscolin Nov 25, 2026
e9dd8ce
fix(builder): fade the top edge like the bottom
alexiscolin Nov 25, 2026
ef6a1e6
fix(duel): never break a pick line on a hanging dot
alexiscolin Nov 25, 2026
04ce188
fix(menu): cancel warm-ups mid-way, stop failed maps pulsing
alexiscolin Nov 25, 2026
922a839
fix(builder): clearer load errors, no pulse on a failed map
alexiscolin Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
3 changes: 2 additions & 1 deletion media/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ code in a headless Chrome, and the gnomes' pictures they made.
| [`lib/`](lib/) | what they share: Chrome over the DevTools protocol (`lib/cdp.mjs`), a page of the game's code (`lib/page.mjs`) |
| [`og/`](og/) | the link cards of the holes, the cups and the home page |
| [`promo/`](promo/) | the trailer: `promo/render.mjs`, its shot lists, the music's credits |
| [`gnomes/`](gnomes/) | the collection's thumbnails (`gnomes/thumbs/`) and turntables, their renderer, the gnomes' link cards, the shop's checks |
| [`gnomes/`](gnomes/) | the collection's thumbnails (`gnomes/thumbs/`) and turntables, their renderer, the game's own gnomes' portraits, the gnomes' link cards, the shop's checks |
| [`gnomes/portrait/`](gnomes/portrait/) | the realm's portrait art (`gno.land/r/gnogolf/gnomes/art.gno`), traced from the client's gnome |
| [`builder/`](builder/) | the palette's pictures, and the Builder's video |

A script's first comment says what it takes and what must be running. From `web/`:
```sh
npm run og # the link cards, into web/public/og/ (the dev server and a local chain running)
npm run gnomes:thumbs # every gnome's thumbnail, into media/gnomes/thumbs/
npm run gnomes:portraits # the game's own gnomes cut out, into web/public/portraits/
npm run gnomes:cards # the gnomes' link cards
npm run builder:tiles # the palette's pictures, into web/public/builder/tiles/
```
Expand Down
39 changes: 39 additions & 0 deletions media/gnomes/portraits.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @ts-check
// The game's own gnomes (web/lib/scene/gnome.ts GNOMES) and a duel's ghost,
// cut out on no background as the picker's stage first shows them, drawn by
// the game's own makeBall in headless Chrome (web/lib/scene/gnome-portrait.ts,
// bundled with a pinned esbuild: no dependency added): a WebP each in
// web/public/portraits/, what a card shows of a gnome at once
// (gnome.ts portraitOf; portraits.test.ts holds each to have one). No dev
// server, no chain. Run it again after a change to how a gnome is drawn.
// node media/gnomes/portraits.mjs
import fs from "node:fs";
import { bundledPage, SEEDED, webpUnder } from "../lib/page.mjs";

const ROOT = new URL("../../", import.meta.url), OUT = new URL("web/public/portraits/", ROOT);
/** The picture's side (a menu panel shows it some 350 CSS pixels tall: sharp on a 2x screen), drawn at RENDER first; its bytes at most. */
const PX = 1024, RENDER = 2048, MAX_BYTES = 30_000;

const ENTRY = `import { makePortraits } from "./web/lib/scene/gnome-portrait";
${SEEDED}
const s = makePortraits(${RENDER});
window.ids = s.ids;
window.shot = (id, px, q) => ((seed = 7), s.shot(id, px, q));
window.ready = true;`;
// (its imports resolve from the repo's root, and read process.env)
const b = await bundledPage(ENTRY, { cwd: ROOT.pathname, name: "portraits.js", define: { "process.env.NODE_ENV": '"production"' }, motion: true, width: 600, height: 600 });

fs.mkdirSync(OUT, { recursive: true });
let bytes = 0, most = 0;
/** @type {string[]} */
const ids = await b.js("ids");
for (const id of ids) {
const img = await webpUnder((q) => b.js(`shot(${JSON.stringify(id)}, ${PX}, ${q})`), MAX_BYTES, 0.9);
fs.writeFileSync(new URL(`${id}.webp`, OUT), img);
bytes += img.length;
most = Math.max(most, img.length);
}
console.log(`${ids.length} portraits, ${Math.round(bytes / 1024)} KB, ${most} B at most`);
if (b.errors.length) console.log("page errors:", b.errors.slice(0, 5));
b.kill();
process.exit(0);
13 changes: 5 additions & 8 deletions media/gnomes/shop-open.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// The gnome shop as a player gets it, checked in headless Chrome against APP: the
// title screen fetching none of it, the shop opened on a slow link and a phone's
// CPU, its toolbar, search and picker in line, never wider than the window,
// offline, and clear of the network chip. Prints PASS or FAIL a check; exits
// offline, and with no network chip (a round's alone). Prints PASS or FAIL a check; exits
// non-zero on a FAIL. With OUT, a frame every 100 ms of the opening and a strip of them.
// APP=https://… node media/gnomes/shop-open.mjs (OUT=<dir> for the frames)
import fs from "node:fs";
import path from "node:path";
import { launch, offline, sleep } from "../lib/cdp.mjs";
import { footprint, gold, misaligned, underChip } from "../lib/rows.mjs";
import { footprint, gold, misaligned } from "../lib/rows.mjs";
const APP = process.env.APP || "http://127.0.0.1:5175", OUT = process.env.OUT || "", TAG = process.env.TAG || "open";
const results = [];
for (const [w, h, mobile] of /** @type {[number, number, boolean][]} */ ([[1440, 900, false], [1024, 768, false], [390, 844, true]])) {
Expand Down Expand Up @@ -214,19 +214,16 @@ for (const [w, h, mobile] of /** @type {[number, number, boolean][]} */ ([[1440,
console.log(`${ok ? "PASS" : "FAIL"} the shop's part not fetched: Back ${off && off.back}, About ${off && off.about}, Try again ${off && off.retry}; then the shelf ${back}; Escape leaves the shop ${left}`);
b.kill();
}
// the network chip (bottom left, fixed) never over the last row: the shop's gallery (every gnome shown), the cups
// (the community's list at their foot) and the menu, each scrolled to its foot, no control under the chip
// the network chip (bottom left, fixed) is a round's alone: none on the shop's gallery, the cups or the menu
for (const [w, h, mobile] of /** @type {[number, number, boolean][]} */ ([[1440, 900, false], [1024, 768, false], [390, 844, true]]))
for (const [at, ready] of [["/g/", ".gshelf li"], ["/?screen=cups", ".world"], ["/?screen=modes", ".mode"]]) {
const b = await launch({ width: w, height: h, mobile, touch: mobile });
await b.send("Page.navigate", { url: APP + at });
for (let i = 0; i < 90 && !(await b.ev(`!!document.querySelector(${JSON.stringify(ready)})`)); i++) await sleep(500);
await sleep(1500);
for (let k = 0; k < 40 && (await b.ev(`!!document.querySelector(".gshelf__more")`)); k++) await b.js(`document.querySelector(".gshelf__more").click(); true`), await sleep(300);
const under = await b.ev(underChip());
const ok = (await b.ev(`!!document.querySelector(".netbanner")`)) && Array.isArray(under) && under.length === 0;
const ok = (await b.ev(`!document.querySelector(".netbanner")`)) === true;
results.push({ w: `${at} ${w}`, ok });
console.log(`${ok ? "PASS" : "FAIL"} ${at} at ${w}×${h}: scrolled to its foot, nothing under the network chip`, ok ? "" : JSON.stringify(under));
console.log(`${ok ? "PASS" : "FAIL"} ${at} at ${w}×${h}: no network chip on a menu screen`);
b.kill();
}
// the gallery's cards, a row one height (the shop's, and a player's gnomes, found from a gnome that found a player)
Expand Down
6 changes: 6 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"

# the gnomes' pictures, redrawn only with the game: kept a day, then shown while checked again
[[headers]]
for = "/portraits/*"
[headers.values]
Cache-Control = "public, max-age=86400, stale-while-revalidate=604800"

[[headers]]
for = "/*"
[headers.values]
Expand Down
2 changes: 1 addition & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ any folder; the `.ts` and `.mjs` ones run with Node, most through an
| | |
|---|---|
| the checks | `check.sh` (all of them, before a commit), `selfcheck.ts`, `scenelooks.ts`, `gnomelooks.ts`, `wasmparity.ts`, `smoke.ts` |
| the course | `holedata.sh` (the holes' sources into `data/holes.txt`), `paritydata.sh`, `publishdata.sh` (onto a chain) |
| the course | `holedata.sh` (the holes' sources into `data/holes.txt`), `paritydata.sh`, `publishdata.sh` (onto a chain), `coursemaps.ts` (the holes' maps the site serves) |
| a deploy | `stage.sh` (the packages under their owner's name), `importv1.sh` (onyx's v1 records into v2) |
| the wasm | `wasm.sh` and `wasm/`: the realm's own Gno built with TinyGo, into `web/lib/sim/` |
| a local chain | `try-local.sh` (the whole game, to try by hand) and its `playground-server.mjs`, `e2e-builder.sh`, `e2e-gnomes.sh`, `lib/e2e.sh` (what they share) |
Expand Down
17 changes: 10 additions & 7 deletions scripts/builderui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ for (const [w, h] of [[1440, 900], [1280, 800], [1024, 700]] as const) {
c.kill();
}

// the start screen (a player back, hinted): it never scrolls sideways, sits clear of the corner's Back, and its starters stand above the fold;
// its world tabs show the one chosen gold
// the start screen (a player back, hinted): it never scrolls sideways, sits clear of the corner's Back, its one gold Build and its
// templates stand above the fold; its world tabs show the one chosen gold
for (const [w, h] of [[1440, 900], [1280, 720], [1024, 700]] as const) {
const c = await launch({ width: w, height: h });
await c.send("Page.addScriptToEvaluateOnNewDocument", { source: `try { localStorage.setItem("gnogolf.builder.hinted", "1"); } catch {}` });
Expand All @@ -173,16 +173,19 @@ for (const [w, h] of [[1440, 900], [1280, 720], [1024, 700]] as const) {
const at = `start ${w}×${h}`;
assert.equal(await c.js(`document.documentElement.scrollWidth > innerWidth || document.querySelector(".bholes").scrollWidth > innerWidth`), false, `${at}: the window scrolls sideways`);
const cards = await c.js<Box[]>(`[...document.querySelectorAll(".bholes__start")].map((e) => { const r = e.getBoundingClientRect(); return { l: r.left, t: r.top, r: r.right, b: r.bottom }; })`);
assert.equal(cards.length, 4, `${at}: three starters and from scratch`);
assert.equal(cards.length, 3, `${at}: the world's three templates`);
// one call to build: the sign's gold button (a plain green in the world chosen), the only gold one on the screen
assert.deepEqual(await c.js<string[]>(`[...document.querySelectorAll(".bholes .btn--gold")].map((e) => e.textContent.trim())`), ["Build a new hole →"], `${at}: the screen's one gold button`);
for (const b of cards) assert.ok(b.b <= h - 16 && b.l >= 0 && b.r <= w, `${at}: a starter's card below the fold or out of the window (${JSON.stringify(b)})`);
const back = (await box(c, ".screen__back"))!;
for (const sel of [".bholes__sign", ".bholes__bar", ".bholes__starts"]) assert.ok(!overlap(back, (await box(c, sel))!), `${at}: ${sel} under the corner's Back`);
const sign = (await box(c, ".bholes__sign"))!, starts = (await box(c, ".bholes__starts"))!;
assert.ok(Math.abs(sign.l + sign.r - w) <= 2 && Math.abs(starts.l + starts.r - w) <= 2, `${at}: the column is not centred`);
// room: no diagram of the steps (the editor's stepper says them), the world tabs a section's gap under the sign
// room: no diagram of the steps (the editor's stepper says them), the world tabs and Build in the sign, the templates a section's gap under it
const bar = (await box(c, ".bholes__bar"))!;
assert.equal(await c.js(`!!document.querySelector(".bholes__steps")`), false, `${at}: the steps drawn again on the start`);
assert.ok(bar.t - sign.b >= 32, `${at}: the world tabs sit right under the sign (${bar.t - sign.b}px)`);
assert.ok(bar.t >= sign.t && bar.b <= sign.b, `${at}: the world tabs and Build out of the sign`);
assert.ok(starts.t - sign.b >= 24, `${at}: the templates sit right under the sign (${starts.t - sign.b}px)`);
// at 1440 × 900, all of it in the window's frame: the last line ("Open a file, or a published hole") too
if (w === 1440) {
const more = (await box(c, ".bholes__more summary"))!;
Expand All @@ -203,8 +206,8 @@ for (const [w, h] of [[1440, 900], [1280, 720], [1024, 700]] as const) {
assert.deepEqual(await c.js(`[...document.querySelectorAll(".bholes__sign .front__head > *")].map((e) => e.tagName + " " + e.className + " " + e.textContent)`), ["SPAN eyebrow The Builder", "H2 worlds__title Hard hats on!"], `${at}: the head is not a front screen's`);
// one h1, the page's name off screen (build/gate.tsx), as the game's pages
assert.deepEqual(await c.js(`[...document.querySelectorAll("h1")].map((e) => e.className + " " + e.textContent)`), ["sr-only The Builder"], `${at}: the page's h1`);
// the starters as templates, under their label, each card as big as the others
assert.deepEqual(await c.js<string[]>(`[...document.querySelectorAll(".bholes__group")].map((e) => e.textContent)`), ["Start from a template"], `${at}: the start's groups`);
// the starters as templates, under their heading, each card as big as the others
assert.deepEqual(await c.js<string[]>(`[...document.querySelectorAll(".bholes__starts h3")].map((e) => e.textContent)`), ["Or start from a template"], `${at}: the templates' heading`);
assert.ok(cards.every((b) => Math.abs(b.r - b.l - (cards[0].r - cards[0].l)) <= 1 && Math.abs(b.b - b.t - (cards[0].b - cards[0].t)) <= 1), `${at}: the starters' cards not one size`);
console.log(`${at}: ok`);
c.kill();
Expand Down
36 changes: 36 additions & 0 deletions scripts/coursemaps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env -S node --experimental-strip-types
// The course's maps as the site serves them (web/public/maps/course.json),
// made from the repo before `npm run dev` and `npm run build`: every hole of
// data/holes.txt as builder.wasm's HoleState answers it (the realm's own
// code), its map's fields alone, by slot, with its data's sha256 (the realm's
// own hash of a version: Versions), which tells it from any other version. The
// game draws a course hole's map from it once the chain's hash is the same
// (web/lib/maps.ts). Not committed; written only if changed.
//
// (from web/) node --experimental-strip-types --disable-warning=ExperimentalWarning --import ./test/setup.mjs ../scripts/coursemaps.ts

import { createHash } from "node:crypto";
import fs from "node:fs";
import type { HoleState } from "../web/lib/types.ts";

const { makeBuilderHost } = await import("../web/lib/builder/wasm.ts");

const ROOT = new URL("../", import.meta.url), OUT = new URL("web/public/maps/course.json", ROOT);
const host = makeBuilderHost(new WebAssembly.Module(fs.readFileSync(new URL("web/lib/sim/builder.wasm", ROOT))));
const maps: Record<string, unknown> = {};
for (const line of fs.readFileSync(new URL("data/holes.txt", ROOT), "utf8").trim().split("\n")) {
const [slot, , sha8, hex] = line.split(" ");
const sha = createHash("sha256").update(Buffer.from(hex, "hex")).digest("hex");
if (!sha.startsWith(sha8)) throw new Error(`${slot}: its data is not ${sha8}'s`);
host.load(slot, hex);
const out = host.state(slot);
if (out.startsWith("panic: ")) throw new Error(`${slot}: ${out}`);
const { world, start, cup, cupR, walls, posts, zones } = JSON.parse(out) as HoleState;
maps[slot] = { sha, world, start, cup, cupR, walls, posts, zones };
}
const json = JSON.stringify(maps), fresh = !fs.existsSync(OUT) || fs.readFileSync(OUT, "utf8") !== json;
if (fresh) {
fs.mkdirSync(new URL("./", OUT), { recursive: true });
fs.writeFileSync(OUT, json);
}
console.log(`coursemaps: ${Object.keys(maps).length} maps, ${Math.round(json.length / 1024)} KB, ${fresh ? "written" : "unchanged"}`);
2 changes: 2 additions & 0 deletions web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ next-env.d.ts
.env*.local
# the gnomes' thumbnails and catalogue as the site serves them: made by scripts/gnomeassets.mjs
public/gnomes/
# the course's maps as the site serves them: made by scripts/coursemaps.ts
public/maps/
Loading
Loading
0