Files
mtgodot-poc/script/python_game_render_test.sh
T
2026-09-27 19:44:41 -07:00

64 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# 2V2-e: the ported client (system.py in Godot) logs in, enters the game and draws RenderGame's
# commands; project/python_game_render_test.gd takes the screenshot and writes report.json.
#
# script/python_game_render_test.sh offline: port_fake_login_server on loopback
# MT_FAKE_MOB_COUNT=24 MT_PROFILE_FRAME=1 MT_PROFILE_COMBAT=1 script/python_game_render_test.sh
# offline crowd sample (1..64 dogs; default 1)
# script/python_game_render_test.sh --live live: MT_LIVE_HOST / MT_LIVE_LOGIN / MT_LIVE_PASSWORD
# (+ MT_LIVE_AUTH_PORT / MT_LIVE_GAME_PORT / MT_LIVE_SLOT)
#
# Credentials are only ever read from the caller's environment; nothing here prints them. Do not add
# `set -x`. Needs a windowed Godot (a headless run draws nothing and skips the screenshot checks).
# exit: 0 PASS, 1 FAIL, 2 precondition missing.
set -euo pipefail
set +x
cd "$(dirname "$0")/.."
repo="$PWD"
godot_bin="${GODOT:-godot}"
output="${MT_RENDER_OUTPUT:-$repo/build/rendering/python-game-$(date +%Y%m%d-%H%M%S)-$$}"
mkdir -p "$output"
export MT_RENDER_OUTPUT="$output"
server_pid=""
cleanup() {
if [ -n "$server_pid" ]; then
kill -TERM "$server_pid" 2>/dev/null || true
wait "$server_pid" 2>/dev/null || true
fi
}
trap cleanup EXIT
if [ "${1:-}" = "--live" ]; then
if [ -z "${MT_LIVE_HOST:-}" ] || [ -z "${MT_LIVE_LOGIN:-}" ] || [ -z "${MT_LIVE_PASSWORD:-}" ]; then
echo "python_game_render_test: --live needs MT_LIVE_HOST, MT_LIVE_LOGIN, MT_LIVE_PASSWORD" >&2
exit 2
fi
else
server="$repo/build/extension/src/port/port_fake_login_server"
if [ ! -x "$server" ]; then
echo "python_game_render_test: build port_fake_login_server first ($server)" >&2
exit 2
fi
fifo="$output/server.ports"
"$server" > "$fifo" 2> "$output/server.log" &
server_pid=$!
for _ in $(seq 50); do
[ -s "$fifo" ] && break
sleep 0.1
done
read -r word auth_port game_port < "$fifo" || true
if [ "${word:-}" != "ports" ]; then
echo "python_game_render_test: the fake server did not start (see $output/server.log)" >&2
exit 2
fi
export MT_LIVE_HOST=127.0.0.1 MT_LIVE_LOGIN=fakeuser MT_LIVE_PASSWORD=fakepass
export MT_LIVE_AUTH_PORT="$auth_port" MT_LIVE_GAME_PORT="$game_port" MT_LIVE_SLOT=0
fi
status=0
"$godot_bin" --path "$repo/project" --script res://python_game_render_test.gd > "$output/godot.log" 2>&1 || status=$?
grep -E "^(ok|FAIL):|python_game_render_test:" "$output/godot.log" || true
exit "$status"