Files
gamedev-the-steward/tools/validate_pantry_crisis_demo.gd
2026-07-16 00:37:59 +02:00

59 lines
1.6 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends SceneTree
const MINIMUM_DURATION_SECONDS := 20.0
const MAXIMUM_DURATION_SECONDS := 30.0
const HARD_TIMEOUT_SECONDS := 36.0
var completed := false
var failed_reason := ""
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
var main_scene: Node = load("res://main.tscn").instantiate()
root.add_child(main_scene)
await process_frame
for _frame in 10:
await physics_frame
var demo := main_scene.get_node("DemoController")
demo.pantry_crisis_completed.connect(_on_demo_completed)
demo.pantry_crisis_failed.connect(_on_demo_failed)
var started_at := Time.get_ticks_msec()
demo.start_pantry_crisis_demo()
while not completed and failed_reason.is_empty():
var elapsed := (Time.get_ticks_msec() - started_at) / 1000.0
if elapsed > HARD_TIMEOUT_SECONDS:
failed_reason = "Timed out after %.1f seconds" % elapsed
break
await process_frame
var duration := (Time.get_ticks_msec() - started_at) / 1000.0
if not failed_reason.is_empty():
push_error("[TOOL] Pantry crisis demo failed: %s" % failed_reason)
quit(1)
return
if duration < MINIMUM_DURATION_SECONDS or duration > MAXIMUM_DURATION_SECONDS:
push_error(
(
"[TOOL] Pantry crisis demo took %.1f seconds; expected %.0f%.0f"
% [duration, MINIMUM_DURATION_SECONDS, MAXIMUM_DURATION_SECONDS]
)
)
quit(1)
return
print("[TOOL] Pantry crisis demo completed in %.1f seconds" % duration)
quit(0)
func _on_demo_completed(_helper_id: int, _resolution_event_id: int) -> void:
completed = true
func _on_demo_failed(reason: String) -> void:
failed_reason = reason