seedhammer-v1-companion/web/emulator/build.sh
mineracks ded32c8f07 #4 v1 emulator scaffolding — boots in browser
Phase 2 kickoff. The cmd/emulator binary now builds to WebAssembly,
loads a 240×240 LCD-equivalent canvas in the browser, and accepts
8-button input from either on-screen buttons or mapped keyboard
keys. The actual v1 gui/ package isn't lifted yet — this is the
scaffolding that proves the platform/v1.Platform interface contract
and the build/serve pipeline so the GUI lift can land cleanly later.

  platform/v1/platform.go (interface)
    Button enum: Up Down Left Right Center Button1 Button2 Button3
    Event{Button, Pressed}
    Platform interface: Events() <-chan Event, Display(image.Image)

    The interface is intentionally minimal — engrave/font/QR access
    happens via direct package imports, not through Platform.
    Future additions (camera, persistent storage) widen the
    interface, not the data model.

  cmd/emulator/main.go (//go:build js && wasm)
    browserPlatform implements Platform against the browser:
      - Display() copies the RGBA buffer into a JS Uint8ClampedArray
        and calls back into emulatorPaint(pixels, w, h)
      - Events() returns a 32-slot buffered channel that
        exportPushEvent feeds from JS
    Boot screen draws a stub frame (orange border, centre cross-hair
    tick) so the canvas isn't blank during the GUI-less stage.
    Future: replace drawBootScreen with gui.Loop() once gui/ is
    lifted.

  cmd/emulator/emulator_host.go (//go:build !js || !wasm)
    Host placeholder so `go build ./...` succeeds on non-WASM
    targets. Emits a helpful "build with GOOS=js GOARCH=wasm".

  web/emulator/{index.html, app.css, app.js, build.sh}
    Static PWA shell. Lays out an LCD frame (canvas, 320×320
    rendered with image-rendering:pixelated for crisp 240×240
    upscale), an on-screen joystick grid, three side-key buttons,
    and a keyboard-shortcut reference table. Keyboard mapping
    matches docs/architecture/v1-buttons-and-ui.md proposal.
    Reuses ../composer/{wasm_exec.js, app.css} — DRY base styling,
    no duplication.

The static server now needs to run one directory level higher
(`-d ./web` instead of `-d ./web/composer`) so both /composer/
and /emulator/ are reachable.

Build with: ./web/emulator/build.sh
Serve with: python3 -m http.server -d ./web 38080
Open:       http://localhost:38080/emulator/

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 20:38:43 +10:00

18 lines
604 B
Bash
Executable File

#!/usr/bin/env bash
# Build the SeedHammer v1 emulator WASM bundle.
# wasm_exec.js is shared with the composer at ../composer/wasm_exec.js.
set -euo pipefail
cd "$(dirname "$0")"
REPO_ROOT=$(cd ../.. && pwd)
cd "$REPO_ROOT"
GOOS=js GOARCH=wasm go build -trimpath -ldflags="-s -w" \
-o ./web/emulator/emulator.wasm \
./cmd/emulator
size=$(stat -f%z ./web/emulator/emulator.wasm 2>/dev/null || stat -c%s ./web/emulator/emulator.wasm)
echo "built: ./web/emulator/emulator.wasm (${size} bytes)"
echo "serve: python3 -m http.server -d ./web 38080"
echo " → open http://localhost:38080/emulator/"