MRPCI/web/build.sh
m3ultra 50ede0febf web: MRPCI runs in a browser, as a player
The macroquad GUI now builds for wasm32 the way MRPGI's does, with two
deliberate differences.

It boots into Play and the F8 editor toggle is compiled out of the web
build. What ships to someone playing a game should be the game, not the tool
that made it.

And it embeds a WorldBundle rather than a game *folder*. MRPGI reaches for
include_dir! because its bundle carries only manifest+rooms; MRPCI's already
carries scripts and sprites too, so one `--export-bundle` document is the
whole game. That is also the format MRP3GI boots from, which means one file
now feeds two engines.

mrpci_alloc/mrpci_world_in let the page hand over another bundle while the
engine is running — the arcade picker and drag-and-drop both arrive there,
and the session restarts on the new world.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 14:17:10 +10:00

46 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# Build the browser version of MRPCI into web/dist/ (self-contained, static).
# Requires the wasm target: rustup target add wasm32-unknown-unknown
#
# ./web/build.sh # bakes games/neon-precinct
# ./web/build.sh /path/to/game # bake any game folder instead
#
# The browser build is a PLAYER: it boots straight into the game and the F8
# editor toggle is compiled out. Authoring stays on the desktop.
#
# Unlike MRPGI's build, which embeds a game *folder* with include_dir!, this
# bakes a single WorldBundle JSON — the same document `--export-bundle`
# writes and the MRP3GI bridge boots from. One format, three engines, and the
# page can hand the engine another one at runtime.
set -e
cd "$(dirname "$0")/.."
GAME="${1:-games/neon-precinct}"
BUNDLE="web/game.bundle.json"
echo "baking game: $GAME"
cargo build --release -p mrpci-core --bin mrpci-headless
./target/release/mrpci-headless --game "$GAME" --export-bundle "$BUNDLE"
# include_str! reads the path at compile time; make sure the crate recompiles
# when only the bundle changed.
touch mrpci/src/main.rs
cargo build -p mrpci --release --target wasm32-unknown-unknown
rm -rf web/dist
mkdir -p web/dist
cp target/wasm32-unknown-unknown/release/mrpci.wasm web/dist/
cp web/index.html web/mq_js_bundle.js web/dist/
# A game's own sfx/ and music/ ride along if it has them; the engine falls
# back to its built-in synth for anything missing, so this is optional.
for kind in sfx music; do
if [ -d "$GAME/$kind" ]; then
mkdir -p "web/dist/game/$kind"
cp "$GAME/$kind"/*.wav "$GAME/$kind"/*.ogg "$GAME/$kind"/*.mp3 \
"web/dist/game/$kind/" 2>/dev/null || true
fi
done
echo "web build ready: $(du -sh web/dist | cut -f1) in web/dist/"