Fix mobile restart and swipe aiming while firing

This commit is contained in:
enne2
2026-10-11 00:13:06 +02:00
parent dee0b387ba
commit f246ede94f
5 changed files with 107 additions and 7 deletions
+32
View File
@@ -46,7 +46,9 @@ func _drag(index: int, pos: Vector2, relative: Vector2) -> void:
ev.index = index
ev.position = pos
ev.relative = relative
ev.screen_relative = relative
Input.parse_input_event(ev)
Input.flush_buffered_events()
func _steps(count: int) -> void:
for i in count:
@@ -128,6 +130,12 @@ func run_test() -> void:
_touch(0, fire_pos, true)
await _steps(10)
assert(player.ammo < 30)
var fire_yaw: float = player.rotation.y
_drag(0, fire_pos + Vector2(-80, 10), Vector2(-80, 10))
await _frame()
assert(player.rotation.y > fire_yaw + 0.001)
assert(Input.is_action_pressed("shoot"))
print("PASS: trascinare FUOCO mira senza interrompere lo sparo")
var after_fire: int = player.ammo
_touch(0, fire_pos, false)
await _steps(10)
@@ -166,6 +174,30 @@ func run_test() -> void:
# --- rilevamento: su questo contesto (desktop headless) la UI non e' automatica ---
assert(not TouchScript.should_auto_enable())
print("PASS: TouchControls.should_auto_enable() = false su desktop -> la UI compare solo se serve")
assert(TouchScript._look_delta(Vector2(100, 20), 1000).is_equal_approx(TouchScript._look_delta(Vector2(200, 40), 2000)))
print("PASS: sensibilita' invariata per swipe proporzionali su schermi diversi")
_touch(0, start_pos, true)
player.take_damage(1000)
await _frame()
await _frame()
assert(not touch.enabled and touch._touches.is_empty())
assert(not Input.is_action_pressed("shoot"))
assert(is_instance_valid(player.restart_button))
await create_timer(0.7).timeout
assert(not player.restart_button.disabled)
current_scene = world
# Verifica anche il reload effettivo, non solo il pulsante.
var restart_event := InputEventScreenTouch.new()
restart_event.pressed = true
restart_event.position = player.restart_button.get_global_rect().get_center()
player._input(restart_event)
assert(player.restart_button.disabled)
await _frame()
await _frame()
assert(current_scene != world)
assert(current_scene.player.hp > 0)
world = current_scene
print("PASS: morte libera input, RICOMINCIA touch ricarica davvero la partita")
print("PASS: controlli touch completi")
world.queue_free()
await _frame()