123 lines
3.5 KiB
GDScript
123 lines
3.5 KiB
GDScript
extends SceneTree
|
|
|
|
const MainScene = preload("res://main.tscn")
|
|
|
|
var game: Control
|
|
var output_root := ""
|
|
var touch_count := 0
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_test")
|
|
|
|
|
|
func run_test() -> void:
|
|
output_root = OS.get_environment("ABG_P9_1_CAPTURE_ROOT")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-p9-1-captures"
|
|
DirAccess.make_dir_recursive_absolute(output_root)
|
|
game = MainScene.instantiate()
|
|
root.add_child(game)
|
|
await wait_for_title()
|
|
await tap("StartNewGame")
|
|
game.locale = OS.get_environment("ABG_P9_1_LOCALE") if not OS.get_environment("ABG_P9_1_LOCALE").is_empty() else "zh_CN"
|
|
game.text_scale = float(OS.get_environment("ABG_P9_1_TEXT_SCALE")) if not OS.get_environment("ABG_P9_1_TEXT_SCALE").is_empty() else 1.0
|
|
game.reduced_motion = OS.get_environment("ABG_P9_1_REDUCED_MOTION") == "1"
|
|
game.muted = OS.get_environment("ABG_P9_1_MUTED") == "1"
|
|
game.render()
|
|
await settle()
|
|
await capture("01-contract")
|
|
await tap("ContractSelect")
|
|
await tap("Difficulty_standard")
|
|
await tap("PrimaryAction")
|
|
for id in ["OFF-01", "OFF-02", "OFF-03", "OFF-04"]:
|
|
await tap("Inspect_%s" % id)
|
|
await tap("Select_OFF-03")
|
|
await tap("Select_OFF-04")
|
|
await capture("02-offers")
|
|
await tap("PrimaryAction")
|
|
await tap("PrimaryAction")
|
|
await tap("PrimaryAction")
|
|
await capture("03-market")
|
|
await tap("PrimaryAction")
|
|
await tap("PrimaryAction")
|
|
await capture("04-equipment")
|
|
await tap("PrimaryAction")
|
|
await tap("EquipTarget_OFF-03")
|
|
await capture("05-order")
|
|
await tap("OrderUnit_OFF-03")
|
|
await tap("OrderUnit_MKT-R1-01")
|
|
await tap("PrimaryAction")
|
|
await capture("06-readiness")
|
|
|
|
game.queue_free()
|
|
game = null
|
|
await drain_cleanup()
|
|
if failures.is_empty():
|
|
print("ABG_P9_1_RUNTIME_CAPTURE_OK frames=6 touch=%d fallback=0 direct=0 root=%s" % [touch_count, output_root])
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func capture(label: String) -> void:
|
|
await RenderingServer.frame_post_draw
|
|
var image := root.get_texture().get_image()
|
|
var path := output_root.path_join("%s.png" % label)
|
|
var error := image.save_png(path)
|
|
if error != OK:
|
|
failures.append("capture %s failed with %s" % [label, error])
|
|
|
|
|
|
func tap(node_name: String) -> void:
|
|
var control := find_control(game, node_name)
|
|
if control == null or not control.is_visible_in_tree() or (control is BaseButton and control.disabled):
|
|
failures.append("unavailable capture touch target %s" % node_name)
|
|
return
|
|
var logical_position := control.get_global_rect().get_center()
|
|
var position := root.get_final_transform() * logical_position
|
|
var press := InputEventScreenTouch.new()
|
|
press.index = 0
|
|
press.position = position
|
|
press.pressed = true
|
|
Input.parse_input_event(press)
|
|
await process_frame
|
|
var release := InputEventScreenTouch.new()
|
|
release.index = 0
|
|
release.position = position
|
|
release.pressed = false
|
|
Input.parse_input_event(release)
|
|
touch_count += 1
|
|
await settle()
|
|
|
|
|
|
func find_control(node: Node, node_name: String) -> Control:
|
|
if node.name == node_name and node is Control and not node.is_queued_for_deletion():
|
|
return node
|
|
for child in node.get_children():
|
|
var found := find_control(child, node_name)
|
|
if found != null:
|
|
return found
|
|
return null
|
|
|
|
|
|
func settle() -> void:
|
|
for frame in range(8):
|
|
await process_frame
|
|
|
|
|
|
func wait_for_title() -> void:
|
|
for frame in range(90):
|
|
if game.page == game.AppPage.TITLE:
|
|
return
|
|
await process_frame
|
|
failures.append("P9.1 capture did not reach Title")
|
|
|
|
|
|
func drain_cleanup() -> void:
|
|
for frame in range(60):
|
|
await process_frame
|