- MRPGI_WEB_GAME env (default games/lost-fuse via .cargo/config.toml) selects the game include_dir! embeds; web/build.sh <game-dir> stages just game.json+rooms+sprites (a repo's raw art was ballooning the wasm to 41MB; now 1.9MB) and ships the game's web/index.html and music/. - sound.rs: file overrides load through macroquad's loader (fs on native, HTTP fetch on web), and AudioOut now loads inside a coroutine behind LazyAudio — browsers gate audio decoding behind a user gesture, and blocking boot on it was a black screen. First frame draws immediately; music starts when ready, remembering the requested mood/mute. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
50 lines
2.0 KiB
Bash
Executable File
50 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# Build the browser version of MRPGI into web/dist/ (self-contained, static).
|
|
# Requires the wasm target: rustup target add wasm32-unknown-unknown
|
|
#
|
|
# ./web/build.sh # the default game (games/lost-fuse)
|
|
# ./web/build.sh /path/to/game # bake any game folder into the wasm;
|
|
# # its music/ and web/index.html ride along
|
|
#
|
|
# Deploy (engine live at https://monsterrobot.games/engine/):
|
|
# scp web/dist/* root@100.94.195.115:/opt/dealgod/images/engine/
|
|
# Served by the dealgod-nginx container via a `location /engine/` alias in
|
|
# /opt/dealgod/nginx/dealgod-servers.conf. NOTE: edit that file IN PLACE
|
|
# (python open("w") / tee), never `sed -i` — it's a single-file bind mount
|
|
# and an inode swap desyncs the container until a `docker restart`.
|
|
set -e
|
|
cd "$(dirname "$0")/.."
|
|
|
|
GAME="${1:-}"
|
|
if [ -n "$GAME" ]; then
|
|
SRC="$(cd "$GAME" && pwd)"
|
|
# Stage only what the engine reads — include_dir! embeds the whole tree,
|
|
# and a game repo also carries raw art, tools, .git, etc.
|
|
STAGE="$(mktemp -d)/game"
|
|
mkdir -p "$STAGE"
|
|
cp "$SRC/game.json" "$STAGE/" 2>/dev/null || true
|
|
cp -R "$SRC/rooms" "$SRC/sprites" "$STAGE/"
|
|
MRPGI_WEB_GAME="$STAGE"
|
|
export MRPGI_WEB_GAME
|
|
echo "baking game: $SRC (staged at $STAGE)"
|
|
fi
|
|
# include_dir! reads the env var at compile time; make sure the crate recompiles.
|
|
touch mrpgi/src/main.rs
|
|
|
|
cargo build -p mrpgi --release --target wasm32-unknown-unknown
|
|
rm -rf web/dist
|
|
mkdir -p web/dist
|
|
cp target/wasm32-unknown-unknown/release/mrpgi.wasm web/dist/
|
|
cp web/index.html web/manual.html web/mq_js_bundle.js web/dist/
|
|
|
|
if [ -n "$GAME" ]; then
|
|
# A game can ship its own page shell and music; both are optional.
|
|
[ -f "$SRC/web/index.html" ] && cp "$SRC/web/index.html" web/dist/
|
|
if [ -d "$SRC/music" ]; then
|
|
mkdir -p web/dist/music
|
|
cp "$SRC"/music/*.wav web/dist/music/ 2>/dev/null || true
|
|
cp "$SRC"/music/*.ogg "$SRC"/music/*.mp3 web/dist/music/ 2>/dev/null || true
|
|
fi
|
|
fi
|
|
echo "web build ready: $(du -sh web/dist | cut -f1) in web/dist/"
|