87 lines
2.9 KiB
GDScript
87 lines
2.9 KiB
GDScript
extends SceneTree
|
|
|
|
# Forgejo #182: opening a dialog releases both touch joysticks before the
|
|
# world is paused. A finger-up event during the pause cannot reach their
|
|
# ordinary input path, so waiting for it would resume stale movement/fire.
|
|
|
|
var state: Node
|
|
var main: Node
|
|
var fleet: Node
|
|
var narration: Control
|
|
var movement: Control
|
|
var firing: Control
|
|
var stage: int = 0
|
|
var elapsed: float = 0.0
|
|
|
|
|
|
func _initialize() -> void:
|
|
state = root.get_node("GameState")
|
|
state.reset_new_game()
|
|
state.intro_active = false
|
|
state.reset_quests()
|
|
main = load("res://world/Main.tscn").instantiate()
|
|
root.add_child(main)
|
|
current_scene = main
|
|
fleet = main.get_node("Fleet")
|
|
narration = main.get_node("UI/NarrationBanner")
|
|
movement = main.get_node("UI/Joystick")
|
|
firing = main.get_node("UI/FireStick")
|
|
|
|
|
|
func _hold(stick: Control, index: int, direction: Vector2) -> void:
|
|
var centre: Vector2 = stick.global_position + stick.size * 0.5
|
|
var press := InputEventScreenTouch.new()
|
|
press.index = index
|
|
press.pressed = true
|
|
press.position = centre
|
|
stick.handle_touch(press)
|
|
var drag := InputEventScreenDrag.new()
|
|
drag.index = index
|
|
drag.position = centre + direction.normalized() * stick.max_radius
|
|
stick.handle_drag(drag)
|
|
|
|
|
|
func _process(delta: float) -> bool:
|
|
elapsed += delta
|
|
if stage != 0 or elapsed < 0.3:
|
|
return false
|
|
stage = 1
|
|
main.get_node("EnemySpawner").set_process(false)
|
|
main.get_node("AsteroidField").set_process(false)
|
|
_hold(movement, 21, Vector2.RIGHT)
|
|
_hold(firing, 22, Vector2.UP)
|
|
main._process(0.0)
|
|
main.get_node("FireStickController")._process(0.0)
|
|
if not movement.is_active() or not firing.is_active():
|
|
return _fail("the test could not hold both joysticks")
|
|
if movement.direction == Vector2.ZERO or firing.direction == Vector2.ZERO:
|
|
return _fail("a held joystick reported no direction")
|
|
if fleet.steer_direction == Vector2.ZERO:
|
|
return _fail("the movement joystick had not begun steering")
|
|
|
|
narration.say("Hands clear.", "TEST")
|
|
if not paused:
|
|
return _fail("the dialog did not pause the game")
|
|
for stick in [movement, firing]:
|
|
if stick.is_active() or stick.direction != Vector2.ZERO:
|
|
return _fail("%s remained held behind the dialog" % stick.name)
|
|
if stick.base_pos.distance_to(stick.home_pos()) > 0.01 \
|
|
or stick.knob_pos.distance_to(stick.home_pos()) > 0.01:
|
|
return _fail("%s did not visually recenter" % stick.name)
|
|
if fleet.steer_direction != Vector2.ZERO:
|
|
return _fail("releasing the movement joystick did not stop the fleet")
|
|
|
|
narration.clear()
|
|
main.get_node("FireStickController")._process(0.0)
|
|
if main.get_node("FireStickController").is_firing():
|
|
return _fail("fire resumed from stale joystick input after the dialog")
|
|
print("dialog released and recentered movement and fire joysticks before pausing")
|
|
print("TEST_DIALOG_RELEASES_JOYSTICKS: PASS")
|
|
quit(0)
|
|
return true
|
|
|
|
|
|
func _fail(message: String) -> bool:
|
|
print("TEST_DIALOG_RELEASES_JOYSTICKS: FAIL (%s)" % message)
|
|
quit(1)
|
|
return true
|