Files
aetherbound-guild/runtime/tests/p9_0r4_preview_capture_test.gd
T

109 lines
3.5 KiB
GDScript

extends SceneTree
const MainScene = preload("res://main.tscn")
const STATES := ["first_result", "adaptation_unselected", "adaptation_frontpin", "second_battle_frontpin", "second_result_frontpin"]
const VIEWPORT_SIZE := Vector2i(844, 390)
var output_root := ""
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
output_root = OS.get_environment("ABG_P9_0R4_CAPTURE_ROOT")
if output_root.is_empty():
output_root = "/tmp/abg-p9-0r4-preview"
DirAccess.make_dir_recursive_absolute(output_root)
var viewport := SubViewport.new()
viewport.size = VIEWPORT_SIZE
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
root.add_child(viewport)
var game := MainScene.instantiate()
game.auto_boot = false
game.audio_enabled = false
viewport.add_child(game)
await settle(12)
game.locale = "zh_CN"
game.text_scale = 1.0
game.reduced_motion = false
game.muted = true
for index in range(STATES.size()):
apply_state(game, STATES[index])
game.render()
await settle(6)
verify_interactive_bounds(game, Rect2(Vector2.ZERO, Vector2(VIEWPORT_SIZE)), STATES[index])
await RenderingServer.frame_post_draw
var image := viewport.get_texture().get_image()
var path := output_root.path_join("%02d-%s.png" % [index + 1, STATES[index]])
var error := image.save_png(path)
if error != OK:
failures.append("capture %s failed with %s" % [STATES[index], error])
game.queue_free()
viewport.queue_free()
await settle(120)
if failures.is_empty():
print("ABG_P9_0R4_PREVIEW_CAPTURE_OK frames=5 viewport=844x390 locale=zh_CN text_scale=1.0 renderer=normal input_claim=none min_touch=44 root=%s" % output_root)
call_deferred("finish", 0)
else:
for failure in failures:
push_error(failure)
call_deferred("finish", 1)
func apply_state(game: Control, state_name: String) -> void:
game.clear_experience()
game.front_choice = "Hearthguard"
game.rear_choice = "Kindhand"
game.coin = 20
game.first_reward_committed = true
game.front_hp = 94
game.enemy_hp = 0
match state_name:
"first_result":
game.page = game.AppPage.VICTORY
"adaptation_unselected":
game.page = game.AppPage.ADAPTATION
"adaptation_frontpin":
game.page = game.AppPage.ADAPTATION
game.adaptation_choice = "EQ-002"
"second_battle_frontpin":
game.page = game.AppPage.SECOND_BATTLE
game.adaptation_choice = "EQ-002"
game.adaptation_committed = true
game.battle_playing = false
game.battle_phase = 2
game.front_hp = 90
game.enemy_hp = 100
game.emit_battle_feedback(2, "front", -10, "抗推", "push resisted", "medium")
game.battle_feedback_clock = 0.16
"second_result_frontpin":
game.page = game.AppPage.SECOND_RESULT
game.adaptation_choice = "EQ-002"
game.adaptation_committed = true
game.front_hp = 100
game.enemy_hp = 0
game.second_result_time = 7.05
func verify_interactive_bounds(node: Node, bounds: Rect2, label: String) -> void:
if node is BaseButton and node.is_visible_in_tree():
var rect: Rect2 = node.get_global_rect()
if rect.position.x < -0.5 or rect.position.y < -0.5 or rect.end.x > bounds.end.x + 0.5 or rect.end.y > bounds.end.y + 0.5:
failures.append("%s button %s outside viewport: %s" % [label, node.name, rect])
if rect.size.x < 44.0 or rect.size.y < 44.0:
failures.append("%s button %s below 44px: %s" % [label, node.name, rect.size])
for child in node.get_children():
verify_interactive_bounds(child, bounds, label)
func finish(exit_code: int) -> void:
quit(exit_code)
func settle(frames: int) -> void:
for frame in range(frames):
await process_frame