Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Market Scale: weigh fruit onto a pan scale to hit each customer's order #37
Check · Review · Land · Live done — Landed and live in production.
Market Scale is added at /market-scale/ and pushed. bun test passes for market-scale, serve.test.mjs and shell.test.mjs (30 tests), and tsc --noEmit is clean. I haven't run it in a browser or touched the pointer and keyboard paths on a real page.
shipped production is serving it deploy ab54f53
1 earlier comment · 1 event
Market Scale is added at /market-scale/ and pushed. bun test passes for market-scale, serve.test.mjs and shell.test.mjs (30 tests), and tsc --noEmit is clean. I haven't run it in a browser or touched the pointer and keyboard paths on a real page. I checked the look with a stubbed canvas that rendered two frames to PNG.
What changed
- Rules:
market-scale/scale.jsholds the fruit weights, the pan total, the needle spring, the scoring and the clock. The crate has 8 fruit: apple 150 g, pear 200 g, lemon 100 g, melon 500 g. - Scoring: exact scores 3, within 50 g scores 1, anything else scores 0. A sale after the 15-second clock has run out scores 0, and the clock expiring sells the pan automatically. A round is five customers.
- Targets: 17 fixed targets, each reachable exactly from the crate. A round draws five distinct ones.
- Tests:
market-scale/scale.test.mjsshows exact 3, 40 g off 1, over the clock 0, that every target is reachable, and the needle overshooting then settling. It also covers the five-customer round, best tracking, and keyboard selection wrapping. - Page: the stall is a striped awning with a swaying fringe, a crate of fruit, a hanging brass pan, a dial with a 2px needle, a chalk slate showing the target, and a bell on a stool. The pan sinks and the needle moves in whole pixels. It uses the 360×280 canvas and fixed camera, and the fringe stops under
prefers-reduced-motion. - Input: drag fruit onto the pan, or tap it to put it in. Tap a fruit in the pan to take it out. Tap the bell to sell. Arrows pick a fruit, enter moves it, space sells.
- Wiring:
shell.jsGAMES, the rootindex.htmllist, the README Games table, and aserve.test.mjscase for/market-scale/andscale.js. The page has#mute, and no.mp3is committed.
What I chose not to do
- No unit on the slate: the 3×5 chalk font can't draw a legible "g", so the slate shows digits only. The "g" and the fruit weights are in the HUD text, which also shows the pan total.
- No customer figure: the stall has no customer figure standing at it.
- No design lint:
scripts/design-lint.tsandscripts/fast.tsdon't exist in this clone, so I ran neither. - No dependencies: none added.
To try it: bun serve.mjs, then open /market-scale/. Tap the bell to open the stall and match each slate target. bun test market-scale runs the rules tests.
🤖 Generated with Claude Code
Good work overall. The rules module is clean plain data in and out. scale.test.mjs covers what the issue asked for: exact scores 3, 40 g off scores 1, over the clock scores 0, every target is reachable, and the needle settles. bun test market-scale serve.test.mjs shell.test.mjs is green (30/30). Credits are marked forged in shell.js, index.html and the README, and the preview at this head serves /market-scale/ and scale.js byte for byte. There is no identity, write path or terminal in this static app, so the security and both-doors items don't apply.
I ran the page itself in a stubbed canvas against this head. Tapping the bell opens the stall. Tapping a crate fruit puts it in the pan, tapping a fruit in the pan takes it out, and arrows + enter and space all drive the state correctly.
The main gesture is visibly broken, though. A fruit dragged over the pan disappears. In draw() the dragged fruit is drawn at world z = lift = 2.5. The dish sits at PAN.rest = 3 (minus the sink), so the depth buffer puts the fruit under the brass. I rendered a frame with an apple held over panScreen(): the apple is gone from the crate and appears nowhere on screen. It only reappears once it is dropped into the pan. Over plain ground it does show, but centred exactly on the pointer, because unproject(sx, sy + lift*COS*S) at z = lift projects back to sy. A finger covers it, and the comment saying it is "lifted so it shows above it" is not true.
Fix first: draw the dragged fruit above everything it can pass over, at least above the pan's top (e.g. z > PAN.rest + 1, or draw it after the pan without depth testing), and offset it upward on screen by a fixed number of pixels so it rides above the finger. Make the comment match what the code does. The builder notes say the pointer paths were never tried in a browser, so please also drag each of the four fruit kinds onto the pan on the preview and confirm it stays visible the whole way.
I fixed the dragged fruit disappearing over the pan, and pushed the change to this branch. I checked it only in a stubbed canvas, not in a browser or on the preview, so I did not drag each fruit on the preview as you asked.
- Cause: you were right. The held fruit was drawn at z = 2.5, below the dish at
PAN.rest= 3, so the depth buffer hid it. Because it was un-projected and drawn at the same height, it also sat exactly under the pointer. - Fix in
market-scale/index.html:
- The held fruit is now drawn at z = 9, above the pan and a full load of fruit.
- It is shown a fixed 26 px above the pointer, and the comment now says that.
- It is drawn after the slate and dial. At first the 2D dial covered a held melon, so I moved the draw to the end of draw().
- It casts no shadow while held, so no stale shadow carries into the next frame.
- Check: I rendered each of the four fruit kinds held directly over the pan and compared the frame with and without the drag. In the 13×13 px window where the fruit should appear, 164–169 of 169 pixels changed for all four. The earlier version had the apple missing entirely.
- Not verified: real pointer events, so how the drag feels with a finger is untested.
- Tests:
bun test market-scale serve.test.mjs shell.test.mjsstill passes (30/30). There is no new test, because this logic lives inline in the page and no suite loads it.
My earlier ask is met: the dragged fruit now disappeared over the pan, and it no longer does.
- Height: the held fruit is drawn at z = 9 (
market-scale/index.html:360). That is above the dish atPAN.rest= 3, the chain tops at 7.2 and a full load of fruit. It is also drawn afterdrawSlate()/drawDial(), so the 2D dial can't cover it either. - Offset: I checked the offset against
project/unprojectinengine.js. Unprojecting atsy - 26 + lift·COS·Sand drawing at z = lift lands exactly 26 px above the pointer, so the finger no longer covers the fruit. The comment now says what the code does. - Shadow: dropping the shadow while the fruit is held means no stale shadow is left behind.
On the preview at this head:
/,/market-scale/andscale.jsall answer 200, and the home list includes Market Scale.scale.test.mjsrun against the files the preview serves passes 10/10.
Nothing else changed since 1a6230b, so the rest stays passed as before.
Non-blocking: no test covers the drag-draw math because it lives inline in the page. If a later pull touches it, a small dragPoint(sx, sy) helper in scale.js with a test that it projects 26 px above the pointer would keep this from regressing.
Market Scale is added at
/market-scale/and pushed.bun testpasses formarket-scale,serve.test.mjsandshell.test.mjs(30 tests), andtsc --noEmitis clean. I haven't run it in a browser or touched the pointer and keyboard paths on a real page. I checked the look with a stubbed canvas that rendered two frames to PNG.What changed
market-scale/scale.jsholds the fruit weights, the pan total, the needle spring, the scoring and the clock. The crate has 8 fruit: apple 150 g, pear 200 g, lemon 100 g, melon 500 g.market-scale/scale.test.mjsshows exact 3, 40 g off 1, over the clock 0, that every target is reachable, and the needle overshooting then settling. It also covers the five-customer round, best tracking, and keyboard selection wrapping.prefers-reduced-motion.shell.jsGAMES, the rootindex.htmllist, the README Games table, and aserve.test.mjscase for/market-scale/andscale.js. The page has#mute, and no.mp3is committed.What I chose not to do
scripts/design-lint.tsandscripts/fast.tsdon't exist in this clone, so I ran neither.To try it:
bun serve.mjs, then open/market-scale/. Tap the bell to open the stall and match each slate target.bun test market-scaleruns the rules tests.🤖 Generated with Claude Code
Closes #26