feat: complete stairs exit interaction and verification

This commit is contained in:
goose
2026-10-01 16:15:30 -04:00
parent b0ce464a38
commit c16f648ce8
7 changed files with 206 additions and 32 deletions
+6
View File
@@ -18,6 +18,12 @@ const TARGET_OFFSETS: Array[Vector2i] = [
static func resolve(state: GameState) -> Array[TurnResult]:
var results: Array[TurnResult] = []
if state.map.get_cell(state.player.cell) == GridMapState.CellKind.STAIRS and not state.exit_reached:
state.exit_reached = true
results.append(TurnResultType.new(state.player.id, &"stairs_used", state.player.cell, state.player.cell, &"", 0, "You descend the stairs."))
TurnResolverType.append_enemy_response(state, results)
return results
var door_cell := _find_closed_door(state)
if door_cell.x >= 0:
state.map.set_cell(door_cell, GridMapState.CellKind.FLOOR)
+23 -5
View File
@@ -25,19 +25,37 @@ func _ready() -> void:
_sync_enemy_views()
hud.refresh(game_state)
audio_library.set_ambience_context("exploration")
if "--capture" in OS.get_cmdline_user_args():
_capture_visual_check()
var capture_mode := _get_capture_mode()
if not capture_mode.is_empty():
_capture_visual_check(capture_mode)
func _capture_visual_check() -> void:
func _get_capture_mode() -> String:
var arguments := OS.get_cmdline_user_args()
if "--capture-exit" in arguments:
return "exit"
if "--capture" in arguments:
return "initial"
return ""
func _capture_visual_check(capture_mode: String) -> void:
if capture_mode == "exit":
_prepare_exit_capture_state()
await get_tree().process_frame
await get_tree().process_frame
await RenderingServer.frame_post_draw
var capture_path := ProjectSettings.globalize_path("res://artifacts/visual-check.png")
var filename := "visual-check-exit.png" if capture_mode == "exit" else "visual-check.png"
var capture_path := ProjectSettings.globalize_path("res://artifacts/" + filename)
DirAccess.make_dir_recursive_absolute(capture_path.get_base_dir())
var image := get_viewport().get_texture().get_image()
var result := image.save_png(capture_path)
get_tree().quit(0 if result == OK else 1)
func _prepare_exit_capture_state() -> void:
game_state.map.set_cell(Vector2i(2, 1), GridMapStateType.CellKind.FLOOR)
game_state.player.cell = Vector2i(9, 7)
_process_interact()
_sync_camera_to_player()
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed(&"interact"):
submit_test_interact()
@@ -75,7 +93,7 @@ func get_actor_cell_rect(actor_id: StringName) -> Rect2:
return Rect2()
func _process_interact() -> Array[TurnResult]:
if game_state.get_context_target() in [&"stairs", &"exit_reached"]:
if game_state.get_context_target() == &"exit_reached":
return _refresh_hud_for_context()
var results := game_state.try_interact()
_sync_map_renderer_visibility()
+36 -21
View File
@@ -14,8 +14,10 @@ fi
mkdir -p artifacts
log_path="artifacts/visual-check.log"
capture_path="artifacts/visual-check.png"
rm -f "$capture_path"
initial_capture_path="artifacts/visual-check.png"
exit_capture_path="artifacts/visual-check-exit.png"
rm -f "$initial_capture_path" "$exit_capture_path"
: > "$log_path"
runner=()
if [[ -z "${DISPLAY:-}" ]]; then
@@ -27,23 +29,26 @@ if [[ -z "${DISPLAY:-}" ]]; then
fi
fi
set +e
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --capture >"$log_path" 2>&1
status=$?
set -e
if (( status != 0 )); then
echo "visual check failed: Godot exited with status $status; see $log_path" >&2
exit "$status"
fi
if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then
echo "visual check failed: Godot reported errors; see $log_path" >&2
exit 1
fi
if [[ ! -s "$capture_path" ]]; then
echo "visual check failed: missing capture $capture_path" >&2
exit 1
fi
if ! python3 - "$capture_path" <<'PY'
run_capture() {
local label="$1"
local capture_argument="$2"
set +e
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --"$capture_argument" >>"$log_path" 2>&1
local status=$?
set -e
if (( status != 0 )); then
echo "visual check failed: $label capture Godot exited with status $status; see $log_path" >&2
exit "$status"
fi
}
validate_capture() {
local capture_path="$1"
if [[ ! -s "$capture_path" ]]; then
echo "visual check failed: missing capture $capture_path" >&2
exit 1
fi
if ! python3 - "$capture_path" <<'PY'
import struct
import sys
@@ -60,7 +65,17 @@ if (width, height) != (1280, 720):
raise SystemExit(f"expected 1280x720 PNG, got {width}x{height}")
print(f"visual capture: {path} ({width}x{height})")
PY
then
echo "visual check failed: capture is not a nonempty valid PNG" >&2
then
echo "visual check failed: capture is not a nonempty valid PNG" >&2
exit 1
fi
}
run_capture "initial" "capture"
run_capture "exit" "capture-exit"
if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then
echo "visual check failed: Godot reported errors; see $log_path" >&2
exit 1
fi
validate_capture "$initial_capture_path"
validate_capture "$exit_capture_path"