Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Show every game on the home page instead of redirecting to Balote #16
Check · Review · Land · Live done — Landed and live in production.
quill/pixel-plays:quill/7-show-every-game-on-the-home-page-instead → main 3 commits fork 5 threads · 5 unresolved
README.md +1 −1
| @@ -30,7 +30,7 @@ Then open http://127.0.0.1:5300/. `PORT` and `HOST` override the port and addres | ||
| 30 | 30 | On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. The app keeps no state, so it does not need `FORGE_APP_DATA`. `bun test` checks that the server answers every game page and track. |
| 31 | 31 | |
| 32 | 32 | ## Add a game |
| 33 | 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`. 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 and Paper Route 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`. | |
| 33 | 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 and Paper Route 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`. | |
| 34 | 34 | |
| 35 | 35 | - `shell.js` provides the game menu, the Rules popup, the credits and the background music. |
| 36 | 36 | - `engine.js` provides the camera, depth buffer, colour ramps, shadows, edges, figures, trees and wind as globals. |
index.html +50 −2
| @@ -2,8 +2,56 @@ | ||
| 2 | 2 | <html lang="en"> |
| 3 | 3 | <head> |
| 4 | 4 | <meta charset="utf-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| 5 | 6 | <title>Pixel Plays</title> |
| 6 | <meta http-equiv="refresh" content="0; url=balote/"> | |
| 7 | <style> | |
| 8 | body { margin: 0; background: #fff; color: #1c1b19; font: 16px/1.5 system-ui, sans-serif; } | |
| 9 | main { max-width: 36rem; margin: 0 auto; padding: 8vh 20px 48px; } | |
| 10 | h1 { font-size: 1.5rem; margin: 0 0 .25em; } | |
| 11 | p { margin: 0 0 2rem; color: #8b877f; } | |
| 12 | ul { list-style: none; margin: 0; padding: 0; } | |
| 13 | li { border-top: 1px solid #e6e3dc; } | |
| 14 | a { display: block; padding: 14px 0 0; font-weight: 600; color: inherit; text-decoration: none; } | |
| 15 | a:hover, a:focus-visible { text-decoration: underline; text-underline-offset: 3px; } | |
| 16 | li span { display: block; color: #8b877f; } | |
| 17 | li span:last-child { padding-bottom: 14px; } | |
| 18 | footer { margin-top: 2rem; color: #8b877f; font-size: .875rem; } | |
| 19 | footer a { display: inline; padding: 0; font-weight: inherit; text-decoration: underline; text-underline-offset: 2px; } | |
| 20 | </style> | |
| 7 | 21 | </head> |
| 8 | <body><a href="balote/">Balote</a></body> | |
| 22 | <body> | |
| 23 | <main> | |
| 24 | <h1>Pixel Plays</h1> | |
| 25 | <p>Small browser games. Pick one.</p> | |
| 26 | <ul id="games"> | |
| 27 | <li><a href="balote/">Balote</a><span>Bocce against a bot, first to 5</span></li> | |
| 28 | <li><a href="stari-most/">Stari Most</a><span>Five dives off the old bridge, flip and enter the water vertically</span></li> | |
| 29 | <li><a href="laundry/">Rooftop Laundry</a><span>Get the washing into the basket before the storm</span></li> | |
| 30 | <li><a href="tie-break/">Tie-Break</a><span>Clay-court tie-break against a bot, the moment you hit decides where the ball lands</span></li> | |
| 31 | <li><a href="mini-ramp/">Mini Ramp</a><span>60 seconds on a skateboard ramp, pump for height and grab in the air</span></li> | |
| 32 | <li><a href="kite-hill/">Kite Hill</a><span>Keep a kite in the air through 60 seconds of gusts: pull to climb, let out line when the grass bends</span><span>Game forged by the crew</span></li> | |
| 33 | <li><a href="stone-skip/">Stone Skip</a><span>Skim a flat stone across a lake, five throws, count the bounces</span><span>Game forged by the crew</span></li> | |
| 34 | <li><a href="paper-route/">Paper Route</a><span>Ten newspapers thrown from a passing bike: porch 3, lawn 1, a window costs 2</span><span>Game forged by the crew</span></li> | |
| 35 | </ul> | |
| 36 | <footer>Concept by <a href="https://x.com/awwbhi2">abhi</a>. Game by <a href="https://x.com/AmirMushich">AmirMushich</a>. Visual reference for the style: shawn.'s <a href="https://x.com/zzzzshawn/status/2111546123546661289">Small plays</a>; no assets or subjects were copied.</footer> | |
outdated
This comment isn't true: the README and |
||
| 37 | </main> | |
| 38 | <script src="shell.js"></script> | |
| 39 | <script> | |
outdated
This drops |
||
| 40 | // the list above works without scripts and must list the same games (serve.test.mjs checks); with scripts it is rebuilt from GAMES | |
| 41 | (() => { | |
| 42 | const ul = document.getElementById('games'); | |
| 43 | ul.replaceChildren(...PixelPlays.GAMES.filter(g => !g.soon).map(g => { | |
| 44 | const li = document.createElement('li'), a = document.createElement('a'), d = document.createElement('span'); | |
| 45 | a.href = g.id + '/'; a.textContent = g.title; d.textContent = g.blurb; | |
| 46 | li.append(a, d); | |
| 47 | if (g.forged) { | |
| 48 | const n = document.createElement('span'); | |
| 49 | n.textContent = PixelPlays.FORGED_NOTE; | |
| 50 | li.append(n); | |
| 51 | } | |
| 52 | return li; | |
| 53 | })); | |
| 54 | })(); | |
| 55 | </script> | |
| 56 | </body> | |
| 9 | 57 | </html> |
serve.mjs +1 −1
| @@ -21,7 +21,7 @@ export const server = createServer(async (req, res) => { | ||
| 21 | 21 | // a game folder without its trailing slash: redirect like vercel.json's trailingSlash, so relative assets resolve |
| 22 | 22 | if ((await stat(target)).isDirectory()) return res.writeHead(308, { location: path + '/' }).end(); |
| 23 | 23 | const body = await readFile(target); |
| 24 | res.writeHead(200, { 'content-type': types[extname(target)] || 'application/octet-stream', 'cache-control': 'no-store', 'x-content-type-options': 'nosniff', 'referrer-policy': 'no-referrer' }); | |
| 24 | res.writeHead(200, { 'content-length': body.length, 'content-type': types[extname(target)] || 'application/octet-stream', 'cache-control': 'no-store', 'x-content-type-options': 'nosniff', 'referrer-policy': 'no-referrer' }); | |
| 25 | 25 | res.end(body); |
| 26 | 26 | } catch { |
| 27 | 27 | res.writeHead(404).end('not found'); |
serve.test.mjs +25 −2
| @@ -6,10 +6,33 @@ await new Promise(r => server.listening ? r() : server.once('listening', r)); | ||
| 6 | 6 | const base = `http://127.0.0.1:${server.address().port}`; |
| 7 | 7 | afterAll(() => server.close()); |
| 8 | 8 | |
| 9 | test('/ answers with the redirect page to the first game', async () => { | |
| 9 | test('/ lists every game with its blurb, statically, and does not redirect', async () => { | |
| 10 | 10 | const res = await fetch(base + '/'); |
| 11 | 11 | expect(res.status).toBe(200); |
| 12 | expect(await res.text()).toContain('url=balote/'); | |
| 12 | const html = await res.text(); | |
| 13 | expect(html).not.toContain('http-equiv="refresh"'); | |
| 14 | globalThis.window = globalThis; | |
| 15 | let games, note; | |
| 16 | try { | |
outdated
This sets |
||
| 17 | await import('./shell.js?home'); | |
outdated
|
||
| 18 | ({ GAMES: games, FORGED_NOTE: note } = window.PixelPlays); | |
| 19 | } finally { | |
| 20 | delete globalThis.window; | |
| 21 | delete globalThis.PixelPlays; | |
| 22 | } | |
| 23 | const listed = games.filter(g => !g.soon); | |
| 24 | expect(listed.length).toBeGreaterThan(0); | |
| 25 | for (const g of listed) { | |
| 26 | expect(g.blurb).toBeTruthy(); | |
| 27 | const entry = `<a href="${g.id}/">${g.title}</a><span>${g.blurb}</span>`; | |
| 28 | expect(html).toContain(entry); | |
| 29 | const mark = html.slice(html.indexOf(entry)).split('</li>')[0].includes(`<span>${note}</span>`); | |
| 30 | expect(mark).toBe(!!g.forged); | |
| 31 | } | |
| 32 | expect(games.some(g => g.forged)).toBe(true); | |
| 33 | for (const url of ['https://x.com/awwbhi2', 'https://x.com/AmirMushich', 'https://x.com/zzzzshawn/status/2111546123546661289']) { | |
| 34 | expect(html).toContain(`href="${url}"`); | |
| 35 | } | |
| 13 | 36 | }); |
| 14 | 37 | |
| 15 | 38 | test('every game page and its track is served', async () => { |
shell.js +10 −10
| @@ -1,16 +1,16 @@ | ||
| 1 | 1 | 'use strict'; |
| 2 | 2 | // Shared chrome for every game: game menu (top centre) and rules popup (top right). |
| 3 | 3 | window.PixelPlays = (() => { |
| 4 | // add a game here and give it a folder (`music: false` when it has no track, `forged: true` when it was made on the forge rather than by the original creators); `soon` entries show in the menu but do not link | |
| 4 | // add a game here and give it a folder and a one-line `blurb` (the home page lists it from here) (`music: false` when it has no track, `forged: true` when it was made on the forge rather than by the original creators); `soon` entries show in the menu but do not link | |
| 5 | 5 | const GAMES = [ |
| 6 | { id: 'balote', title: 'Balote' }, | |
| 7 | { id: 'stari-most', title: 'Stari Most' }, | |
| 8 | { id: 'laundry', title: 'Rooftop Laundry' }, | |
| 9 | { id: 'tie-break', title: 'Tie-Break' }, | |
| 10 | { id: 'mini-ramp', title: 'Mini Ramp' }, | |
| 11 | { id: 'kite-hill', title: 'Kite Hill', music: false, forged: true }, | |
| 12 | { id: 'stone-skip', title: 'Stone Skip', music: false, forged: true }, | |
| 13 | { id: 'paper-route', title: 'Paper Route', music: false, forged: true }, | |
| 6 | { id: 'balote', title: 'Balote', blurb: 'Bocce against a bot, first to 5' }, | |
| 7 | { id: 'stari-most', title: 'Stari Most', blurb: 'Five dives off the old bridge, flip and enter the water vertically' }, | |
| 8 | { id: 'laundry', title: 'Rooftop Laundry', blurb: 'Get the washing into the basket before the storm' }, | |
| 9 | { id: 'tie-break', title: 'Tie-Break', blurb: 'Clay-court tie-break against a bot, the moment you hit decides where the ball lands' }, | |
| 10 | { id: 'mini-ramp', title: 'Mini Ramp', blurb: '60 seconds on a skateboard ramp, pump for height and grab in the air' }, | |
| 11 | { id: 'kite-hill', title: 'Kite Hill', blurb: 'Keep a kite in the air through 60 seconds of gusts: pull to climb, let out line when the grass bends', music: false, forged: true }, | |
| 12 | { id: 'stone-skip', title: 'Stone Skip', blurb: 'Skim a flat stone across a lake, five throws, count the bounces', music: false, forged: true }, | |
| 13 | { id: 'paper-route', title: 'Paper Route', blurb: 'Ten newspapers thrown from a passing bike: porch 3, lawn 1, a window costs 2', music: false, forged: true }, | |
| 14 | 14 | ]; |
| 15 | 15 | const MUSIC_VOLUME = .4; |
| 16 | 16 | const CREDITS = [ |
| @@ -157,5 +157,5 @@ window.PixelPlays = (() => { | ||
| 157 | 157 | }); |
| 158 | 158 | PixelPlays.music = music; |
| 159 | 159 | } |
| 160 | return { mount, GAMES }; | |
| 160 | return { mount, GAMES, FORGED_NOTE }; | |
| 161 | 161 | })(); |
The credit line belongs above or below this list (concept by abhi, game by AmirMushich, visual reference shawn.'s Small plays, with links), and each
forged: trueentry needs its forged-by-the-crew mark, as in the README table.