Public: anyone can read this; the crew can change it.

Migrated from github.com/amirmushichge/pixel-plays

fantastic og metadata. the fact that these games are static means we could re… #48

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

quill/pixel-plays:quill/45-fantastic-og-metadata-the-fact-that-thes → main 3 commits fork 5 threads · 5 unresolved

  • Merged. quill/45-fantastic-og-metadata-the-fact-that-thes was merged into main as ecaabdf.

Review

Sign in to review this change.
43 files changed +516 −1
README.md +4 −1
@@ -43,8 +43,11 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is
4343 ## Plays
4444 `/stats/` ranks the games by how much they are played, and `/api/stats` returns the same rows as JSON. Each game page reports three anonymous events to `POST /api/play` (an Origin check against browser cross-site posts, which a script can still forge, so the endpoint is also limited as below): the page opened, the first tap or key press (a play), and the seconds the page stayed visible after that. Only totals per game are kept, with no ids or cookies, in `plays.json` under `FORGE_APP_DATA` (in memory when it is unset). `stats.mjs` holds the counting; it needs no dependency, so the file is plain JSON rather than SQLite, which would tie the server to Bun. Limits: 60 events a minute per client address (the socket address, never a header) and 600 a minute per game, answered with 429; a play is refused unless an open is ahead of it and time unless plays can account for it (at most 3600 s each), so forged events cannot show a ratio real ones never could. They cannot stop someone slowly inflating a game within those bounds, so treat the numbers as a guide. Counts are flushed to disk on SIGTERM. Not recorded yet: a finished round, since each game ends in its own way.
4545
46 ## Share cards
47 Every page carries Open Graph and Twitter tags (between `og:begin` and `og:end`), and `og/<id>.png` is a 1200x630 card: the game's own opening frame, scaled 2x on white; `og/home.png` is a grid of all of them. Because the games are static, `bun scripts/og.mjs` makes them without a browser: it runs each page's scripts in a `vm` against a stub DOM, captures the canvas pixels and writes the PNG (zlib only, no dependency) and the tags. Run it after adding a game or changing a scene; `serve.test.mjs` fails when a card or its tags are missing or stale. Scenes are rendered with a seeded `Math.random`, so the cards are byte-for-byte reproducible. Absolute URLs use `ORIGIN` at the top of the script (the forge production site), so change it there if the site moves.
outdated

The og step was inserted mid-phrase, so the sentence now reads "run bun scripts/og.mjs for its share card with a one-line blurb". Make it a separate sentence.

48
4649 ## Add a game
47 Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too). The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run, Pottery Wheel, Row Home, Orchard, Lighthouse, Market Scale, Window Washer and Domino Run play on their own sound effects). Rules that need testing go in a plain script with a `.test.mjs` beside it, as in `kite-hill/model.js`.
50 Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too). Then run `bun scripts/og.mjs` to make its share card and tags. The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run, Pottery Wheel, Row Home, Orchard, Lighthouse, Market Scale, Window Washer and Domino Run play on their own sound effects). Rules that need testing go in a plain script with a `.test.mjs` beside it, as in `kite-hill/model.js`.
4851
4952 - `shell.js` provides the game menu, the Rules popup, the credits and the background music.
5053 - `engine.js` provides the camera, depth buffer, colour ramps, shadows, edges, figures, trees and wind as globals.
balote/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Balote</title>
7 <!-- og:begin -->
8 <meta name="description" content="Bocce against a bot, first to 5">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/balote/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Balote">
13 <meta property="og:description" content="Bocce against a bot, first to 5">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/balote/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/balote.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Balote: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --a: #b5392b; --b: #27496d; }
924 * { box-sizing: border-box; }
domino-run/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Domino Run</title>
7 <!-- og:begin -->
8 <meta name="description" content="Set out a line of 20 dominoes along a chalk path and tip the first: a gap too wide stops the chain, too close topples one early, ring the bell for 10 plus 1 per domino left">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/domino-run/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Domino Run">
13 <meta property="og:description" content="Set out a line of 20 dominoes along a chalk path and tip the first: a gap too wide stops the chain, too close topples one early, ring the bell for 10 plus 1 per domino left">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/domino-run/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/domino-run.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Domino Run: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; }
924 * { box-sizing: border-box; }
free-throw/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Free Throw</title>
7 <!-- og:begin -->
8 <meta name="description" content="Ten shots on a rooftop court: hold to crouch and build power, release to jump, then shoot at the top of the jump">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/free-throw/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Free Throw">
13 <meta property="og:description" content="Ten shots on a rooftop court: hold to crouch and build power, release to jump, then shoot at the top of the jump">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/free-throw/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/free-throw.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Free Throw: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #b4452f; }
924 * { box-sizing: border-box; }
harbour-crane/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Harbour Crane</title>
7 <!-- og:begin -->
8 <meta name="description" content="Stack ten crates onto a bobbing fishing boat from a swinging crane hook">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/harbour-crane/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Harbour Crane">
13 <meta property="og:description" content="Stack ten crates onto a bobbing fishing boat from a swinging crane hook">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/harbour-crane/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/harbour-crane.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Harbour Crane: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #b0642e; }
924 * { box-sizing: border-box; }
index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width, initial-scale=1">
66 <title>Pixel Plays</title>
7 <!-- og:begin -->
8 <meta name="description" content="Small browser games shown as isometric pixel dioramas. Pick one.">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Pixel Plays">
13 <meta property="og:description" content="Small browser games shown as isometric pixel dioramas. Pick one.">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/home.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="The opening scene of every Pixel Plays game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 body { margin: 0; background: #fff; color: #1c1b19; font: 16px/1.5 system-ui, sans-serif; }
924 main { max-width: 36rem; margin: 0 auto; padding: 8vh 20px 48px; }
kite-hill/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Kite Hill</title>
7 <!-- og:begin -->
8 <meta name="description" content="Keep a kite in the air through 60 seconds of gusts: pull to climb, let out line when the grass bends">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/kite-hill/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Kite Hill">
13 <meta property="og:description" content="Keep a kite in the air through 60 seconds of gusts: pull to climb, let out line when the grass bends">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/kite-hill/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/kite-hill.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Kite Hill: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; }
924 * { box-sizing: border-box; }
laundry/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Rooftop Laundry</title>
7 <!-- og:begin -->
8 <meta name="description" content="Get the washing into the basket before the storm">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/laundry/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Rooftop Laundry">
13 <meta property="og:description" content="Get the washing into the basket before the storm">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/laundry/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/laundry.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Rooftop Laundry: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; }
924 * { box-sizing: border-box; }
lighthouse/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Lighthouse</title>
7 <!-- og:begin -->
8 <meta name="description" content="Sweep the lighthouse beam to turn boats away from the rocks: hold one in the light for a second, three wrecks end the night">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/lighthouse/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Lighthouse">
13 <meta property="og:description" content="Sweep the lighthouse beam to turn boats away from the rocks: hold one in the light for a second, three wrecks end the night">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/lighthouse/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/lighthouse.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Lighthouse: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #c4503c; }
924 * { box-sizing: border-box; }
market-scale/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Market Scale</title>
7 <!-- og:begin -->
8 <meta name="description" content="Weigh fruit onto a hanging pan scale to match each order: exact scores 3, within 50 g scores 1">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/market-scale/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Market Scale">
13 <meta property="og:description" content="Weigh fruit onto a hanging pan scale to match each order: exact scores 3, within 50 g scores 1">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/market-scale/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/market-scale.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Market Scale: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; }
924 * { box-sizing: border-box; }
mini-ramp/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Mini Ramp</title>
7 <!-- og:begin -->
8 <meta name="description" content="60 seconds on a skateboard ramp, pump for height and grab in the air">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/mini-ramp/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Mini Ramp">
13 <meta property="og:description" content="60 seconds on a skateboard ramp, pump for height and grab in the air">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/mini-ramp/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/mini-ramp.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Mini Ramp: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; }
924 * { box-sizing: border-box; }
og/balote.png added
Binary file not shown.
og/domino-run.png added
Binary file not shown.
og/free-throw.png added
Binary file not shown.
og/harbour-crane.png added
Binary file not shown.
og/home.png added
Binary file not shown.
og/kite-hill.png added
Binary file not shown.
og/laundry.png added
Binary file not shown.
og/lighthouse.png added
Binary file not shown.
og/market-scale.png added
Binary file not shown.
og/mini-ramp.png added
Binary file not shown.
og/orchard.png added
Binary file not shown.
og/paper-route.png added
Binary file not shown.
og/pizza-toss.png added
Binary file not shown.
og/pottery-wheel.png added
Binary file not shown.
og/row-home.png added
Binary file not shown.
og/sled-run.png added
Binary file not shown.
og/stari-most.png added
Binary file not shown.
og/stone-skip.png added
Binary file not shown.
og/tie-break.png added
Binary file not shown.
og/window-washer.png added
Binary file not shown.
orchard/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Orchard</title>
7 <!-- og:begin -->
8 <meta name="description" content="Catch falling apples in a basket: ripe 1, golden 3, a wasp-bitten brown one costs a life">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/orchard/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Orchard">
13 <meta property="og:description" content="Catch falling apples in a basket: ripe 1, golden 3, a wasp-bitten brown one costs a life">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/orchard/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/orchard.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Orchard: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #c4503c; }
924 * { box-sizing: border-box; }
paper-route/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Paper Route</title>
7 <!-- og:begin -->
8 <meta name="description" content="Ten newspapers thrown from a passing bike: porch 3, lawn 1, a window costs 2">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/paper-route/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Paper Route">
13 <meta property="og:description" content="Ten newspapers thrown from a passing bike: porch 3, lawn 1, a window costs 2">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/paper-route/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/paper-route.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Paper Route: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #c4503c; }
924 * { box-sizing: border-box; }
pizza-toss/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Pizza Toss</title>
7 <!-- og:begin -->
8 <meta name="description" content="Five tosses of pizza dough: hold to spin, catch it before it drops, too much spin tears it">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/pizza-toss/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Pizza Toss">
13 <meta property="og:description" content="Five tosses of pizza dough: hold to spin, catch it before it drops, too much spin tears it">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/pizza-toss/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/pizza-toss.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Pizza Toss: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #b4452f; }
924 * { box-sizing: border-box; }
pottery-wheel/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Pottery Wheel</title>
7 <!-- og:begin -->
8 <meta name="description" content="Shape a pot on a kick wheel: hold to centre the clay without collapsing it, then pull the wall as tall as you can before it tears">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/pottery-wheel/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Pottery Wheel">
13 <meta property="og:description" content="Shape a pot on a kick wheel: hold to centre the clay without collapsing it, then pull the wall as tall as you can before it tears">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/pottery-wheel/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/pottery-wheel.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Pottery Wheel: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #b4452f; }
924 * { box-sizing: border-box; }
row-home/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Row Home</title>
7 <!-- og:begin -->
8 <meta name="description" content="Race a rowing boat across the river against a bot: stroke in rhythm with the glide, too early catches a crab">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/row-home/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Row Home">
13 <meta property="og:description" content="Race a rowing boat across the river against a bot: stroke in rhythm with the glide, too early catches a crab">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/row-home/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/row-home.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Row Home: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; }
924 * { box-sizing: border-box; }
scripts/og.mjs added +165
@@ -0,0 +1,165 @@
1 // Renders each game's opening frame to og/<id>.png and keeps the share-card tags in <id>/index.html current.
2 // Usage: bun scripts/og.mjs (no browser: the game scripts run in a vm against a stub DOM and the canvas pixels are captured)
3 import { readFileSync, writeFileSync } from 'node:fs';
4 import { deflateSync, crc32 } from 'node:zlib';
5 import { createContext, runInContext } from 'node:vm';
6 import { fileURLToPath } from 'node:url';
7 import { join } from 'node:path';
8
9 export const ORIGIN = 'https://pixel-plays--forge-trevato-apps.open-platform.sh';
outdated

With this origin, canonical and og:url on every forge page point at Vercel. Use the forge production origin, which fits the direction to steer towards being forged, or drop canonical.

10 export const CARD = { w: 1200, h: 630, scale: 2 };
11 const root = fileURLToPath(new URL('..', import.meta.url));
12 const FRAMES = 12;
13
14 // scenes scatter trees and bunting with Math.random and seed rounds from Date.now; a seeded random and a fixed clock make every capture, and so every card, the same
15 function mulberry32(a) {
16 return () => {
17 a = a + 0x6D2B79F5 | 0;
18 let t = Math.imul(a ^ a >>> 15, 1 | a);
19 t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
20 return ((t ^ t >>> 14) >>> 0) / 4294967296;
21 };
22 }
23
24 // a stand-in for any DOM object a game touches: every property is another stand-in, calling it does nothing
25 function stub() {
26 const f = function () {};
27 const p = new Proxy(f, {
28 get: (_, k) => (k === Symbol.toPrimitive ? () => 0 : k === 'length' ? 0 : k === 'then' ? undefined : p),
29 set: () => true,
30 apply: () => p,
31 construct: () => p,
32 });
33 return p;
34 }
35
36 export function scriptsOf(html) {
37 return [...html.matchAll(/<script(?:\s+src="([^"]+)")?\s*>([\s\S]*?)<\/script>/g)].map(m => (m[1] ? { src: m[1] } : { code: m[2] }));
38 }
39
40 // run the page's scripts and return the last 360x280 RGBA frame the canvas received
41 export function capture(id) {
42 const dir = join(root, id);
43 const html = readFileSync(join(dir, 'index.html'), 'utf8');
44 let frame = null;
45 const callbacks = [];
46 const canvas = stub();
47 const ctx = stub();
48 const make = (w, h) => ({ data: new Uint8ClampedArray(w * h * 4), width: w, height: h });
49 const sink = new Proxy(ctx, {
50 get: (t, k) => k === 'createImageData' ? make : k === 'putImageData' ? img => { frame = Uint8ClampedArray.from(img.data); } : t[k],
outdated

The real Math goes into the vm, so the five scenes that call Math.random render differently on every run (I confirmed this on balote and free-throw). Pass a seeded random here so the cards come out the same each time.

51 });
52 const el = new Proxy(canvas, { get: (t, k) => (k === 'getContext' ? () => sink : t[k]) });
53 const doc = new Proxy(stub(), { get: (t, k) => (k === 'getElementById' ? n => (n === 'c' ? el : t) : t[k]) });
54 const win = {
55 document: doc, innerWidth: 1200, innerHeight: 700, devicePixelRatio: 1,
56 requestAnimationFrame: cb => { callbacks.push(cb); return callbacks.length; },
57 matchMedia: () => ({ matches: false, addEventListener() {}, addListener() {} }),
58 addEventListener() {}, localStorage: { getItem: () => null, setItem() {} },
59 AudioContext: undefined, webkitAudioContext: undefined, Audio: stub(), PixelPlays: { mount() {} },
60 performance: { now: () => 0 }, Math: Object.assign(Object.create(Math), { random: mulberry32(1) }), Date: class extends Date { static now() { return 1e12; } constructor(...a) { super(...(a.length ? a : [1e12])); } }, console,
61 };
62 win.window = win; win.self = win; win.globalThis = win;
63 const ctxVm = createContext(win);
64 for (const s of scriptsOf(html)) {
65 const code = s.src ? (s.src.endsWith('shell.js') ? '' : readFileSync(join(dir, s.src), 'utf8')) : s.code;
66 if (code) runInContext(code, ctxVm, { filename: s.src || id + '/inline' });
67 }
68 for (let i = 0; i < FRAMES; i++) {
69 const batch = callbacks.splice(0);
70 for (const cb of batch) cb(i * 16.7);
71 }
72 if (!frame) throw new Error(id + ': no frame was drawn');
73 return frame;
74 }
75
76 const png = (w, h, rgb) => {
77 const raw = Buffer.alloc((w * 3 + 1) * h);
78 for (let y = 0; y < h; y++) rgb.copy(raw, y * (w * 3 + 1) + 1, y * w * 3, (y + 1) * w * 3);
79 const chunk = (type, data) => {
80 const head = Buffer.alloc(4); head.writeUInt32BE(data.length);
81 const body = Buffer.concat([Buffer.from(type), data]);
82 const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(body));
83 return Buffer.concat([head, body, crc]);
84 };
85 const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 4); ihdr[8] = 8; ihdr[9] = 2;
86 return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk('IHDR', ihdr), chunk('IDAT', deflateSync(raw, { level: 9 })), chunk('IEND', Buffer.alloc(0))]);
87 };
88
89 // the scene, integer-scaled with nearest neighbour, centred on white
90 export function card(rgba, W = 360, H = 280) {
91 const { w, h, scale } = CARD;
92 const out = Buffer.alloc(w * h * 3, 255);
93 const left = (w - W * scale) >> 1, top = (h - H * scale) >> 1;
94 for (let y = 0; y < H * scale; y++) for (let x = 0; x < W * scale; x++) {
95 const s = ((y / scale | 0) * W + (x / scale | 0)) * 4, a = rgba[s + 3] / 255, d = ((top + y) * w + left + x) * 3;
96 for (let c = 0; c < 3; c++) out[d + c] = Math.round(rgba[s + c] * a + 255 * (1 - a));
97 }
98 return png(w, h, out);
99 }
100
101 const esc = s => s.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;');
102 export function tags(game) {
103 const url = game.id === 'home' ? `${ORIGIN}/` : `${ORIGIN}/${game.id}/`, image = `${ORIGIN}/og/${game.id}.png`;
104 return [
105 `<meta name="description" content="${esc(game.blurb)}">`,
106 `<link rel="canonical" href="${url}">`,
107 `<meta property="og:type" content="website">`,
108 `<meta property="og:site_name" content="Pixel Plays">`,
109 `<meta property="og:title" content="${esc(game.title)}">`,
110 `<meta property="og:description" content="${esc(game.blurb)}">`,
111 `<meta property="og:url" content="${url}">`,
112 `<meta property="og:image" content="${image}">`,
113 `<meta property="og:image:type" content="image/png">`,
114 `<meta property="og:image:width" content="${CARD.w}">`,
115 `<meta property="og:image:height" content="${CARD.h}">`,
116 `<meta property="og:image:alt" content="${game.id === 'home' ? 'The opening scene of every Pixel Plays game' : esc(game.title) + ': the opening scene of the game'}">`,
117 `<meta name="twitter:card" content="summary_large_image">`,
118 ].join('\n');
119 }
120 const BEGIN = '<!-- og:begin -->', END = '<!-- og:end -->';
121 export function withTags(html, game) {
122 const block = `${BEGIN}\n${tags(game)}\n${END}`;
outdated

Nit: filter already returns a new array, so the spread does nothing.

123 if (html.includes(BEGIN)) return html.replace(new RegExp(BEGIN + '[\\s\\S]*?' + END), () => block);
124 return html.replace(/(<\/title>)/, (_, t) => t + '\n' + block);
125 }
126
127 export const HOME = { id: 'home', title: 'Pixel Plays', blurb: 'Small browser games shown as isometric pixel dioramas. Pick one.' };
128
129 export function games() {
130 const sandbox = { window: {}, document: {} };
131 sandbox.window = sandbox;
132 const ctx = createContext(sandbox);
133 runInContext(readFileSync(join(root, 'shell.js'), 'utf8'), ctx);
134 return sandbox.PixelPlays.GAMES.filter(g => !g.soon).map(g => ({ id: g.id, title: g.title, blurb: g.blurb }));
135 }
136
137 // the home card: every opening scene in a grid, sampled nearest-neighbour
138 export function collage(frames, W = 360, H = 280) {
139 const { w, h } = CARD, cols = 5, rows = Math.ceil(frames.length / cols);
140 const cw = w / cols | 0, ch = h / rows | 0, k = Math.min(cw / W, ch / H);
141 const sw = W * k | 0, sh = H * k | 0, out = Buffer.alloc(w * h * 3, 255);
142 frames.forEach((rgba, n) => {
143 const left = (n % cols) * cw + (cw - sw >> 1), top = (n / cols | 0) * ch + (ch - sh >> 1);
144 for (let y = 0; y < sh; y++) for (let x = 0; x < sw; x++) {
145 const s = ((y / k | 0) * W + (x / k | 0)) * 4, a = rgba[s + 3] / 255, d = ((top + y) * w + left + x) * 3;
146 for (let c = 0; c < 3; c++) out[d + c] = Math.round(rgba[s + c] * a + 255 * (1 - a));
147 }
148 });
149 return png(w, h, out);
150 }
151
152 if (import.meta.main) {
153 const frames = [];
154 for (const g of games()) {
155 const frame = capture(g.id);
156 frames.push(frame);
157 writeFileSync(join(root, 'og', g.id + '.png'), card(frame));
158 const file = join(root, g.id, 'index.html');
159 writeFileSync(file, withTags(readFileSync(file, 'utf8'), g));
160 console.log('rendered', g.id);
161 }
162 writeFileSync(join(root, 'og', 'home.png'), collage(frames));
163 const file = join(root, 'index.html');
164 writeFileSync(file, withTags(readFileSync(file, 'utf8'), HOME));
165 }
serve.test.mjs +47
@@ -156,6 +156,53 @@ test('Domino Run and its rules script are served without a track', async () => {
156156 expect((await fetch(base + '/domino-run/chain.js')).status).toBe(200);
157157 });
158158
159 test('every game and the home page carry share-card tags and a served PNG card', async () => {
160 const { games, withTags, ORIGIN, CARD, HOME } = await import('./scripts/og.mjs');
161 const { readFileSync } = await import('node:fs');
162 const list = games();
163 expect(list.length).toBeGreaterThan(0);
164 for (const g of list) {
165 const html = await (await fetch(`${base}/${g.id}/`)).text();
166 expect(html).toContain(`<meta property="og:image" content="${ORIGIN}/og/${g.id}.png">`);
167 expect(html).toContain('<meta name="twitter:card" content="summary_large_image">');
168 // the tags are what the generator would write now (title and blurb are current)
169 expect(withTags(html, g)).toBe(html);
170 const card = await fetch(`${base}/og/${g.id}.png`);
171 expect(card.status).toBe(200);
172 expect(card.headers.get('content-type')).toBe('image/png');
173 const bytes = Buffer.from(await card.arrayBuffer());
174 expect([...bytes.subarray(1, 4)]).toEqual([80, 78, 71]);
175 expect([bytes.readUInt32BE(16), bytes.readUInt32BE(20)]).toEqual([CARD.w, CARD.h]);

This checks the PNG's size only, so a stale card passes. Once rendering is deterministic, also assert that card(capture(g.id)) equals the committed file.

176 }
177 const home = await (await fetch(base + '/')).text();
178 expect(home).toContain(`content="${ORIGIN}/og/home.png"`);
179 expect(withTags(home, HOME)).toBe(home);
180 expect((await fetch(base + '/og/home.png')).status).toBe(200);
181 expect(readFileSync(new URL('./og/balote.png', import.meta.url)).length).toBeGreaterThan(1000);
182 });
183
184 test('every committed card is what the games render now, and capture is deterministic', async () => {
185 const { games, capture, card, collage } = await import('./scripts/og.mjs');
186 const { readFileSync } = await import('node:fs');
187 const frames = [];
188 for (const g of games()) {
189 const frame = capture(g.id);
190 expect(Buffer.from(capture(g.id)).equals(Buffer.from(frame))).toBe(true);
191 frames.push(frame);
192 expect(card(frame).equals(readFileSync(new URL(`./og/${g.id}.png`, import.meta.url)))).toBe(true);
193 }
194 expect(collage(frames).equals(readFileSync(new URL('./og/home.png', import.meta.url)))).toBe(true);
195 }, 60000);
196
197 test('a card is not blank: the scene is captured from the game, not a placeholder', async () => {
198 const { capture } = await import('./scripts/og.mjs');
199 const frame = capture('lighthouse');
200 expect(frame.length).toBe(360 * 280 * 4);
201 let dark = 0;
202 for (let i = 0; i < frame.length; i += 4) if (frame[i + 3] && frame[i] + frame[i + 1] + frame[i + 2] < 300) dark++;
203 expect(dark).toBeGreaterThan(5000);
204 });
205
159206 const post = (body, headers = { origin: base }) => fetch(base + '/api/play', { method: 'POST', body: typeof body === 'string' ? body : JSON.stringify(body), headers });
160207
161208 test('plays are counted from the same origin and show on the stats page and JSON', async () => {
sled-run/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Sled Run</title>
7 <!-- og:begin -->
8 <meta name="description" content="Ride a sledge down a snowy hill: tuck for speed, release on a kicker to jump, land flat">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/sled-run/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Sled Run">
13 <meta property="og:description" content="Ride a sledge down a snowy hill: tuck for speed, release on a kicker to jump, land flat">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/sled-run/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/sled-run.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Sled Run: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #c4503a; }
924 * { box-sizing: border-box; }
stari-most/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Stari Most</title>
7 <!-- og:begin -->
8 <meta name="description" content="Five dives off the old bridge, flip and enter the water vertically">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/stari-most/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Stari Most">
13 <meta property="og:description" content="Five dives off the old bridge, flip and enter the water vertically">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/stari-most/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/stari-most.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Stari Most: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; }
924 * { box-sizing: border-box; }
stone-skip/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Stone Skip</title>
7 <!-- og:begin -->
8 <meta name="description" content="Skim a flat stone across a lake, five throws, count the bounces">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/stone-skip/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Stone Skip">
13 <meta property="og:description" content="Skim a flat stone across a lake, five throws, count the bounces">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/stone-skip/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/stone-skip.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Stone Skip: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #3f7f9c; }
924 * { box-sizing: border-box; }
tie-break/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Tie-Break</title>
7 <!-- og:begin -->
8 <meta name="description" content="Clay-court tie-break against a bot, the moment you hit decides where the ball lands">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/tie-break/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Tie-Break">
13 <meta property="og:description" content="Clay-court tie-break against a bot, the moment you hit decides where the ball lands">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/tie-break/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/tie-break.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Tie-Break: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --a: #b5392b; --b: #27496d; }
924 * { box-sizing: border-box; }
window-washer/index.html +15
@@ -4,6 +4,21 @@
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
66 <title>Window Washer</title>
7 <!-- og:begin -->
8 <meta name="description" content="Squeegee a grimy window clean before the cradle drops a floor: drag across it, bird droppings need two passes">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/window-washer/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Window Washer">
13 <meta property="og:description" content="Squeegee a grimy window clean before the cradle drops a floor: drag across it, bird droppings need two passes">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/window-washer/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/window-washer.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Window Washer: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
722 <style>
823 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #3f7fa8; }
924 * { box-sizing: border-box; }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs