80 lines
2.7 KiB
GDScript3
80 lines
2.7 KiB
GDScript3
|
|
extends SceneTree
|
||
|
|
## 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
|
||
|
|
|
||
|
|
var _failures := 0
|
||
|
|
var main: Main
|
||
|
|
|
||
|
|
|
||
|
|
func _init() -> void:
|
||
|
|
if not OS.get_cmdline_user_args().has("--sample"):
|
||
|
|
print("Run with -- --sample so the test can't touch saved data.")
|
||
|
|
quit(2)
|
||
|
|
return
|
||
|
|
main = load("res://ui/main.tscn").instantiate()
|
||
|
|
root.add_child(main)
|
||
|
|
await _frames(5)
|
||
|
|
await _test_layout()
|
||
|
|
await _test_touch()
|
||
|
|
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
|
||
|
|
quit(1 if _failures else 0)
|
||
|
|
|
||
|
|
|
||
|
|
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
|
||
|
|
|
||
|
|
|
||
|
|
func _frames(n: int = 2) -> void:
|
||
|
|
for i in n:
|
||
|
|
await process_frame
|
||
|
|
|
||
|
|
|
||
|
|
func _check(ok: bool, what: String) -> void:
|
||
|
|
if not ok:
|
||
|
|
_failures += 1
|
||
|
|
print("FAIL ", what)
|