TableTower/tests/test_mobile.gd
2026-11-10 19:53:22 -06:00

60 lines
2.2 KiB
GDScript

extends TestBase
## The phone layout (List fills the screen, Spread/List swap, slim bar and
## tray, View/Help/Play-Build in ☰) and touch gestures (pinch zoom, a long
## press timing out into a right-click).
## Run: godot --headless --path . -s res://tests/test_mobile.gd -- --sample
func _init() -> void:
if not await start_main():
return
await _test_layout()
await _test_touch()
finish()
func _test_layout() -> void:
main.mobile = MobileLayout.new(main)
main.mobile.apply()
await _frames()
_check(main.list_view.visible and not main.board.visible, "the list fills the screen")
_check(not main.top_bar.view_menu.visible and not main.top_bar.help_menu.visible and not main.tray.side_panel.visible, "the bar and tray slim down")
main.mobile.swap.pressed.emit()
_check(main.board.visible and not main.list_view.visible and main.mobile.swap.text == "List", "Spread/List swaps to the spread")
main.mobile.swap.pressed.emit()
var texts: Array = Actions.background(main, Vector2.ZERO).map(func(a: Dictionary) -> String: return str(a.get("text", "")))
_check(texts.has("Switch to Build") and texts.has("Help…"), "☰ carries Play/Build and Help: %s" % str(texts))
main.mobile.show_list(false)
func _test_touch() -> void:
var touch: TouchInput = null
for c in main.get_children():
if c is TouchInput:
touch = c
_check(touch != null, "touch gestures are on")
var z := main.board.zoom
touch._input(_tap(0, Vector2(100, 300), true))
touch._input(_tap(1, Vector2(200, 300), true))
var d := InputEventScreenDrag.new()
d.index = 1
d.position = Vector2(300, 300)
touch._input(d)
_check(main.board.zoom > z * 1.5, "two fingers spreading apart zoom in (%.2f → %.2f)" % [z, main.board.zoom])
touch._input(_tap(1, Vector2(300, 300), false))
touch._input(_tap(0, Vector2(100, 300), false))
touch._input(_tap(0, Vector2(120, 320), true))
touch._process(0.3)
_check(touch._hold_t > 0.0, "a held finger counts toward a long press")
touch._process(0.3)
_check(touch._hold_t < 0.0, "after half a second it fires (as a right-click)")
touch._input(_tap(0, Vector2(120, 320), false))
func _tap(i: int, at: Vector2, down: bool) -> InputEventScreenTouch:
var t := InputEventScreenTouch.new()
t.index = i
t.position = at
t.pressed = down
return t