98 lines
2.9 KiB
GDScript
98 lines
2.9 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(10)
|
|
game.locale = "zh_CN"
|
|
game.muted = true
|
|
game.page = game.AppPage.FIRST_MISSION
|
|
game.render()
|
|
await settle(6)
|
|
|
|
await tap("OpenFrontSelectionButton")
|
|
await tap("Front_Hearthguard")
|
|
await tap("Front_Wayrunner")
|
|
expect(game.front_choice == "Wayrunner", "touch replaces the front")
|
|
await tap("ContinueRearSelectionButton")
|
|
await tap("Rear_Farstring")
|
|
await tap("Rear_Kindhand")
|
|
expect(game.rear_choice == "Kindhand", "touch replaces the rear")
|
|
await tap("ReviewFormationButton")
|
|
await tap("ReviseFrontButton")
|
|
expect(game.page == game.AppPage.FRONT_SELECTION and game.rear_choice == "Kindhand", "front revision preserves rear")
|
|
await tap("Front_Hearthguard")
|
|
await tap("ContinueRearSelectionButton")
|
|
await tap("ReviewFormationButton")
|
|
await tap("ReviseRearButton")
|
|
await tap("Rear_Farstring")
|
|
await tap("ReviewFormationButton")
|
|
await tap("CommitFormationButton")
|
|
expect(game.page == game.AppPage.BATTLE and game.battle_playing, "touch commit reaches battle")
|
|
expect(game.front_choice == "Hearthguard" and game.rear_choice == "Farstring", "touch commits the revised formation")
|
|
expect(game.formation_commit_count == 1, "touch commits exactly once")
|
|
|
|
game.queue_free()
|
|
game = null
|
|
await settle(90)
|
|
if failures.is_empty():
|
|
print("ABG_P9_0R9_FIRST_COMPANY_TOUCH_OK touch=%d fallback=0 direct=0 revise=front,rear commit=1" % 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(7)
|
|
|
|
|
|
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(frames: int) -> void:
|
|
for frame in range(frames):
|
|
await process_frame
|
|
|
|
|
|
func expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append("P9.0R9 first Company touch: %s" % message)
|