91 lines
2.4 KiB
GDScript
91 lines
2.4 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.front_choice = "Hearthguard"
|
|
game.rear_choice = "Kindhand"
|
|
game.front_hp = 94
|
|
game.enemy_hp = 0
|
|
game.coin = 20
|
|
game.first_reward_committed = true
|
|
game.page = game.AppPage.VICTORY
|
|
game.render()
|
|
await settle(8)
|
|
|
|
await tap("ContinueAdaptationButton")
|
|
expect(game.page == game.AppPage.ADAPTATION, "first result touch opens adaptation")
|
|
await tap("Adaptation_EQ_061")
|
|
expect(game.adaptation_choice == "EQ-061", "touch selects Early Bell")
|
|
await tap("Adaptation_EQ_002")
|
|
expect(game.adaptation_choice == "EQ-002", "touch revises to Frontpin")
|
|
await tap("BeginSecondBattle")
|
|
expect(game.page == game.AppPage.SECOND_BATTLE and game.adaptation_committed, "touch commits and starts second battle")
|
|
|
|
game.queue_free()
|
|
game = null
|
|
await settle(70)
|
|
if failures.is_empty():
|
|
print("ABG_P9_0R4_TOUCH_OK touch=%d fallback=0 direct=0 open=1 revise=1 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(8)
|
|
|
|
|
|
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.0R4 touch: %s" % message)
|