120 lines
3.5 KiB
GDScript
120 lines
3.5 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
|
|
prepare_real_session_result()
|
|
await settle(6)
|
|
|
|
await tap("OpenRouteBoardButton")
|
|
expect(game.page == game.AppPage.ROUTE_BOARD, "session result touch opens route board")
|
|
await tap("Route_R6_01")
|
|
await tap("Route_R6_03")
|
|
expect(game.route_choice == "R6-03", "touch revises route selection")
|
|
await tap("ReviewRouteButton")
|
|
expect(game.page == game.AppPage.ROUTE_REVIEW, "touch opens route review")
|
|
await tap("CancelRouteReviewButton")
|
|
expect(game.page == game.AppPage.ROUTE_BOARD and game.route_choice == "R6-03", "touch cancel preserves selection")
|
|
await tap("Route_R6_02")
|
|
await tap("ReviewRouteButton")
|
|
await tap("CommitRouteButton")
|
|
expect(game.page == game.AppPage.FOURTH_BATTLE and game.route_committed, "touch commits route and starts battle")
|
|
await wait_for_page(game.AppPage.SECOND_CYCLE_RESULT, 720)
|
|
expect(game.route_choice == "R6-02" and game.coin == 15, "route reward reaches exact Coin")
|
|
expect(find_control(game, "SecondCycleFacts") != null, "touch route renders causal result")
|
|
|
|
game.queue_free()
|
|
game = null
|
|
await settle(90)
|
|
if failures.is_empty():
|
|
print("ABG_P9_0R6_ROUTE_TOUCH_OK touch=%d fallback=0 direct=0 revise=1 review=1 cancel=1 commit=1 battle=1 result=1" % touch_count)
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func prepare_real_session_result() -> void:
|
|
game.front_choice = "Hearthguard"
|
|
game.rear_choice = "Kindhand"
|
|
game.adaptation_choice = "EQ-061"
|
|
game.adaptation_committed = true
|
|
game.guild_choice = "retain_item"
|
|
game.guild_committed = true
|
|
game.retained_item = "EQ-061"
|
|
game.coin = 8
|
|
game.front_hp = 82
|
|
game.enemy_hp = 0
|
|
game.third_result_time = 6.60
|
|
game.page = game.AppPage.SESSION_RESULT
|
|
game.render()
|
|
|
|
|
|
func wait_for_page(target_page: int, max_frames: int) -> void:
|
|
var previous_scale := Engine.time_scale
|
|
Engine.time_scale = 12.0
|
|
for frame in range(max_frames):
|
|
if game.page == target_page:
|
|
break
|
|
await process_frame
|
|
Engine.time_scale = previous_scale
|
|
expect(game.page == target_page, "automatic fourth battle reaches result")
|
|
await settle(6)
|
|
|
|
|
|
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.0R6 route touch: %s" % message)
|