129 lines
4.1 KiB
GDScript
129 lines
4.1 KiB
GDScript
extends SceneTree
|
|
|
|
const MainScene = preload("res://main.tscn")
|
|
const RunState = preload("res://domain/run_state.gd")
|
|
|
|
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()
|
|
root.add_child(game)
|
|
await wait_for_title()
|
|
await tap("StartNewGame")
|
|
var settings_snapshot: Dictionary = game.run.snapshot()
|
|
await tap("LocaleButton")
|
|
await tap("TextScaleButton")
|
|
await tap("MotionButton")
|
|
await tap("MuteButton")
|
|
expect(game.locale == "en", "language toggle uses real touch")
|
|
expect(is_equal_approx(game.text_scale, 1.3), "130 percent text toggle uses real touch")
|
|
expect(game.reduced_motion, "reduced-motion toggle uses real touch")
|
|
expect(game.muted, "mute toggle uses real touch")
|
|
expect(game.run.snapshot() == settings_snapshot, "accessibility controls do not mutate gameplay state")
|
|
|
|
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 tap("PrimaryAction")
|
|
await tap("ReviseOpening")
|
|
expect(game.run.selected == ["OFF-03", "OFF-04"], "revision retains selected pair")
|
|
await tap("PrimaryAction")
|
|
await tap("PrimaryAction")
|
|
await tap("PrimaryAction")
|
|
await tap("PrimaryAction")
|
|
await tap("PrimaryAction")
|
|
await tap("PrimaryAction")
|
|
await tap("EquipTarget_OFF-03")
|
|
await tap("OrderUnit_OFF-03")
|
|
await tap("OrderUnit_MKT-R1-01")
|
|
await tap("PrimaryAction")
|
|
|
|
var snapshot: Dictionary = game.run.snapshot()
|
|
expect(snapshot.step == RunState.Step.READY, "touch path reaches readiness receipt")
|
|
expect(snapshot.coin == 12, "touch path final Coin")
|
|
expect(snapshot.company.size() == 4, "touch path final Company")
|
|
expect(snapshot.equipment_wearer == "OFF-03", "touch path equips Tomas")
|
|
expect(snapshot.operation_counts.opening == 1, "touch path opening one-shot")
|
|
expect(snapshot.operation_counts["MKT-R1-01"] == 1 and snapshot.operation_counts["MKT-R1-02"] == 1, "touch path hires one-shot")
|
|
expect(snapshot.operation_counts.purchase == 1 and snapshot.operation_counts.equip == 1 and snapshot.operation_counts.order == 1, "touch path remaining commits one-shot")
|
|
|
|
game.queue_free()
|
|
game = null
|
|
await drain_cleanup()
|
|
if failures.is_empty():
|
|
print("ABG_P9_1_TOUCH_OK touch=%d fallback=0 direct=0 locale=en text_130=true reduced_motion=true mute=true final_coin=12 company=4" % 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:
|
|
failures.append("missing touch target %s" % node_name)
|
|
return
|
|
if not control.is_visible_in_tree() or (control is BaseButton and control.disabled):
|
|
failures.append("unavailable 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 regression did not reach Title")
|
|
|
|
|
|
func drain_cleanup() -> void:
|
|
for frame in range(60):
|
|
await process_frame
|
|
|
|
|
|
func expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append("P9.1 touch: %s" % message)
|