108 lines
3.3 KiB
GDScript
108 lines
3.3 KiB
GDScript
extends SceneTree
|
|
|
|
const MainScene = preload("res://main.tscn")
|
|
|
|
var game: Control
|
|
var touch_count := 0
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_test")
|
|
|
|
|
|
func run_test() -> void:
|
|
game = MainScene.instantiate()
|
|
game.auto_boot = false
|
|
root.add_child(game)
|
|
await settle()
|
|
game.boot_verified = true
|
|
game.page = game.AppPage.TITLE
|
|
game.render()
|
|
await settle()
|
|
|
|
await tap("EnterGameButton")
|
|
await tap("StartNewGameButton")
|
|
await tap("OpenRecruitSelectionButton")
|
|
expect(game.page == game.AppPage.RECRUIT_SELECTION, "Title and Main Menu touches reach unified Recruit selection")
|
|
await tap("Recruit_Wayrunner")
|
|
await tap("Recruit_Kindhand")
|
|
await tap("ReviewFormationButton")
|
|
expect(game.front_choice == "Wayrunner" and game.rear_choice == "Kindhand", "system assigns the chosen people")
|
|
await tap("CommitFormationButton")
|
|
expect(game.page == game.AppPage.BATTLE, "touch starts battle")
|
|
await tap("RestartButton")
|
|
expect(game.restart_confirmation, "restart touch opens confirmation")
|
|
await tap("RestartCancelButton")
|
|
expect(game.page == game.AppPage.BATTLE and not game.restart_confirmation, "cancel touch preserves battle")
|
|
await tap("HomeButton")
|
|
expect(game.page == game.AppPage.MAIN_MENU, "Home touch reaches Main Menu")
|
|
expect(game.front_choice.is_empty() and game.rear_choice.is_empty(), "Home touch clears team")
|
|
await tap("StartNewGameButton")
|
|
await tap("OpenRecruitSelectionButton")
|
|
await tap("Recruit_Hearthguard")
|
|
await tap("Recruit_Farstring")
|
|
await tap("ReviewFormationButton")
|
|
await tap("CommitFormationButton")
|
|
await tap("RestartButton")
|
|
await tap("RestartConfirmButton")
|
|
expect(game.page == game.AppPage.MAIN_MENU, "confirmed restart touch reaches Main Menu")
|
|
expect(game.front_hp == 100 and game.enemy_hp == 100, "confirmed restart clears HP")
|
|
|
|
game.queue_free()
|
|
game = null
|
|
await drain_cleanup()
|
|
if failures.is_empty():
|
|
print("ABG_P9_0R1_TOUCH_OK touch=%d fallback=0 direct=0 replace=2 battle=1 home=1 restart=confirmed" % touch_count)
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
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 touch target %s" % node_name)
|
|
return
|
|
var position := root.get_final_transform() * control.get_global_rect().get_center()
|
|
var down := InputEventScreenTouch.new()
|
|
down.index = 0
|
|
down.position = position
|
|
down.pressed = true
|
|
Input.parse_input_event(down)
|
|
await process_frame
|
|
var up := InputEventScreenTouch.new()
|
|
up.index = 0
|
|
up.position = position
|
|
up.pressed = false
|
|
Input.parse_input_event(up)
|
|
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 drain_cleanup() -> void:
|
|
for frame in range(50):
|
|
await process_frame
|
|
|
|
|
|
func expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append("P9.0R1 touch: %s" % message)
|