magicciv/scripts/p1-56-civics-proof.sh
Natalie bf9295a5d9 feat(@projects/@magic-civilization): add weston-based civics proof script
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-05-14 19:44:00 -07:00

83 lines
2.6 KiB
Bash
Executable file

#!/usr/bin/env bash
# p1-56 Civics Interactive proof renderer.
#
# Runs ON apricot. Drives flatpak Godot under a weston-headless Wayland host
# pointed at `res://engine/scenes/tests/proof_civics_interactive.tscn`. The
# scene renders the 4-panel godot-ui surface (drag-to-employ, harvest dropdown,
# GP spawn modal, throne-room layer slots) and self-captures to
# `user://screenshots/proof_civics_interactive_<ts>.png`.
#
# Env:
# SCRATCH_DIR worktree path containing src/game (required)
# LOG_FILE log destination (default /tmp/p1-56-civics-proof.log)
# TIMEOUT_SEC Godot timeout in seconds (default 90)
set -uo pipefail
SCRATCH_DIR="${SCRATCH_DIR:?SCRATCH_DIR is required}"
LOG_FILE="${LOG_FILE:-/tmp/p1-56-civics-proof.log}"
TIMEOUT_SEC="${TIMEOUT_SEC:-90}"
GODOT_USERDATA="$HOME/.var/app/org.godotengine.Godot/data/godot/app_userdata/Magic Civilization"
SHOT_DIR="$GODOT_USERDATA/screenshots"
echo "=== p1-56 Civics Interactive proof ==="
echo "SCRATCH_DIR: $SCRATCH_DIR"
echo "LOG: $LOG_FILE"
echo "Sandbox screenshot dir: $SHOT_DIR"
mkdir -p "$SHOT_DIR"
rm -f "$SHOT_DIR"/proof_civics_interactive_*.png 2>/dev/null || true
if ! command -v weston >/dev/null 2>&1; then
echo "ERROR: weston not installed" >&2
exit 2
fi
WESTON_SOCKET="p1-56-civics-$$"
WESTON_LOG="/tmp/p1-56-civics-weston.log"
echo "Starting weston (headless, socket=$WESTON_SOCKET)..."
weston --backend=headless --no-config --socket="$WESTON_SOCKET" \
--width=1280 --height=800 \
>"$WESTON_LOG" 2>&1 &
WESTON_PID=$!
sleep 1.5
if ! kill -0 "$WESTON_PID" 2>/dev/null; then
echo "ERROR: weston failed to launch — see $WESTON_LOG" >&2
tail -20 "$WESTON_LOG" >&2
exit 3
fi
trap 'kill $WESTON_PID 2>/dev/null; wait $WESTON_PID 2>/dev/null' EXIT
XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" \
timeout "$TIMEOUT_SEC" flatpak run --user \
--filesystem=home \
--socket=wayland \
--unset-env=DISPLAY \
--env=WAYLAND_DISPLAY="$WESTON_SOCKET" \
--filesystem=xdg-run/${WESTON_SOCKET} \
org.godotengine.Godot \
--path "$SCRATCH_DIR/src/game" \
--display-driver wayland \
--rendering-driver opengl3 \
--rendering-method gl_compatibility \
res://engine/scenes/tests/proof_civics_interactive.tscn \
>"$LOG_FILE" 2>&1
RC=$?
echo "--- Godot exit rc=$RC ---"
echo "--- Tail of log ---"
tail -40 "$LOG_FILE"
echo "-------------------"
SHOTS=( "$SHOT_DIR"/proof_civics_interactive_*.png )
if [ ! -f "${SHOTS[0]}" ]; then
echo "ERROR: no proof_civics_interactive_*.png produced under $SHOT_DIR" >&2
exit 1
fi
echo "Captured ${#SHOTS[@]} shot(s):"
ls -la "$SHOT_DIR"/proof_civics_interactive_*.png
echo "=== Done ==="
exit 0