Fix touch: use start-to-end distance to distinguish taps from camera drags

Cumulative drag distance (_touch_drag_total) is the wrong metric for tap
detection: natural finger jitter (A→B→A) can exceed 36 px even on a clean
tap, silently suppressing board clicks (unit moves, card plays, etc.).

Switch the board-click gate to start-to-end distance (< 50 px = tap).
_touch_drag_active now only means "camera mode fired during this touch" and
is set by the gesture timer or when an active camera mode consumes a drag.
This means taps always reach _handle_board_click regardless of finger wobble.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-30 19:58:52 -04:00
co-authored by Claude Happy
parent 6e27f57d7a
commit 72fba92af5
@@ -130,8 +130,9 @@ var _pinch_dist : float = 0.0
# Prevents single-finger orbit from triggering during a pinch gesture even
# if a ScreenDrag for finger-0 arrives before finger-1's ScreenTouch is processed.
var _was_multi_touch : bool = false
var _touch_drag_active : bool = false # set when cumulative finger movement > threshold; suppresses tap-click
var _touch_drag_total : float = 0.0 # cumulative drag distance since last touch-down
var _touch_drag_active : bool = false # camera mode fired during this touch; suppresses tap-click
var _touch_drag_total : float = 0.0 # cumulative drag distance since last touch-down (gates camera actions)
var _touch_start_pos : Vector2 = Vector2.ZERO # finger position at touch-down (for start-to-end tap detection)
# Touch camera mode — which camera action is currently active on touch
var _touch_cam_orbit : bool = false # single-finger drag → orbit
@@ -940,6 +941,7 @@ func _unhandled_input(event: InputEvent) -> void:
# Single-touch start: arm tap + hold (touch right-click) behavior.
_touch_drag_active = false
_touch_drag_total = 0.0
_touch_start_pos = st.position
_press_was_on_board = true
_last_mouse = st.position
var touch_coord := _mouse_to_tile_coord(st.position)
@@ -963,13 +965,18 @@ func _unhandled_input(event: InputEvent) -> void:
var released_pos := st.position
var had_single_touch := (_touch_points.size() == 1 and _touch_points.has(st.index))
_touch_points.erase(st.index)
if had_single_touch and not _touch_drag_active and not _was_multi_touch and _press_was_on_board:
_hold_timer.stop()
_handle_board_click(released_pos)
if had_single_touch and not _was_multi_touch and _press_was_on_board:
# Use start-to-end distance, not cumulative, to detect taps.
# Cumulative distance mis-classifies natural finger jitter (A→B→A) as a drag.
var tap_dist := released_pos.distance_to(_touch_start_pos)
if tap_dist < 50.0 and not _touch_drag_active:
_hold_timer.stop()
_handle_board_click(released_pos)
if _touch_points.is_empty():
_was_multi_touch = false
_touch_drag_active = false
_touch_drag_total = 0.0
_touch_start_pos = Vector2.ZERO
_press_was_on_board = false
_held_coord = Vector2i(-1, -1)
_hold_timer.stop()