fix(hand): scroll throttle, deselect on spin/click-outside for all card modes

- Throttle hand scroll to one step per 150 ms so each wheel tick advances exactly one card
- Deselect selected card when clicking outside the hand area (deferred flag pattern so board clicks still play the card)
- Extend spin and click-outside deselect to cover TERRAMORPHA_SELECT and card-triggered ABILITY_TARGET (Repentance/Instinct), not just CARD_FROM_HAND
- Show Repentance/Instinct cards as visually selected in hand when in ABILITY_TARGET mode
- Drop stale spectator state_update pushes from wrong sessions
- Auto-create missing audio buses on Settings._ready to avoid bus-not-found errors

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-04-15 09:31:30 -04:00
co-authored by Claude Happy
parent 573d8cf727
commit afa9e73489
4 changed files with 63 additions and 12 deletions
@@ -81,6 +81,8 @@ var _last_click_frame : int = -1
var _last_click_iid : String = ""
var _is_spectating : bool = false
var _hand_focus_index : int = 0
var _hand_scroll_time : float = 0.0 # monotonic time of last hand scroll
var _deselect_pending : bool = false # set in _input, cleared by board unhandled click
var _hand_hover_iid : String = ""
var _cached_hand_iids : Array[String] = []
var _pending_popup_cards : Array[Dictionary] = []
@@ -916,17 +918,47 @@ func _on_cam_gesture_timer_fired() -> void:
# ── Input ─────────────────────────────────────────────────────────────────────
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton:
var mb := event as InputEventMouseButton
if mb.button_index == MOUSE_BUTTON_LEFT and mb.pressed and not mb.double_click:
var _card_mode_active := _mode in [Mode.CARD_FROM_HAND, Mode.TERRAMORPHA_SELECT] or \
(_mode == Mode.ABILITY_TARGET and not _ability_card_id.is_empty())
if _card_mode_active:
if not _hand_area.get_global_rect().has_point(mb.position):
_deselect_pending = true
_do_deselect_if_pending.call_deferred()
func _do_deselect_if_pending() -> void:
if _deselect_pending:
_deselect_pending = false
if _mode in [Mode.CARD_FROM_HAND, Mode.TERRAMORPHA_SELECT] or \
(_mode == Mode.ABILITY_TARGET and not _ability_card_id.is_empty()):
_set_mode(Mode.NONE)
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
var mb := event as InputEventMouseButton
# Left-click reaching here is a board click — cancel any pending deselect
# so _do_deselect_if_pending won't wipe selection before the card is played.
if mb.button_index == MOUSE_BUTTON_LEFT and mb.pressed:
_deselect_pending = false
if mb.button_index == MOUSE_BUTTON_WHEEL_UP:
if _hand_area.get_global_rect().has_point(mb.position):
_spin_hand(-1)
var now := Time.get_ticks_msec() / 1000.0
if now - _hand_scroll_time >= 0.15:
_hand_scroll_time = now
_spin_hand(-1)
return
_zoom(1.5); return
elif mb.button_index == MOUSE_BUTTON_WHEEL_DOWN:
if _hand_area.get_global_rect().has_point(mb.position):
_spin_hand(1)
var now := Time.get_ticks_msec() / 1000.0
if now - _hand_scroll_time >= 0.15:
_hand_scroll_time = now
_spin_hand(1)
return
_zoom(-1.5); return
elif mb.button_index == MOUSE_BUTTON_MIDDLE:
@@ -4455,7 +4487,7 @@ func _rebuild_hand(hand: Array) -> void:
# Build new IID list.
var new_iids : Array[String] = []
for card: Dictionary in hand:
var raw_iid := card.get("instanceId")
var raw_iid : Variant = card.get("instanceId")
new_iids.append(str(raw_iid) if raw_iid != null else "")
if new_iids == _cached_hand_iids:
_refresh_hand_selection()
@@ -4690,7 +4722,8 @@ func _refresh_hand_selection() -> void:
if not widget.has_meta("card_instance_id"): continue
var iid : String = str(widget.get_meta("card_instance_id"))
var sel : bool = ((_mode == Mode.CARD_FROM_HAND
or _mode == Mode.TERRAMORPHA_SELECT)
or _mode == Mode.TERRAMORPHA_SELECT
or (_mode == Mode.ABILITY_TARGET and not _ability_card_id.is_empty()))
and _sel_card_id == iid)
if widget.has_method("set_selected"):
widget.set_selected(sel)
@@ -4772,7 +4805,8 @@ func _spin_hand(direction: int) -> void:
var card_count := _hand_cards.get_child_count()
if card_count <= 1:
return
if _mode == Mode.CARD_FROM_HAND:
if _mode in [Mode.CARD_FROM_HAND, Mode.TERRAMORPHA_SELECT] or \
(_mode == Mode.ABILITY_TARGET and not _ability_card_id.is_empty()):
_set_mode(Mode.NONE)
_hand_focus_index = posmod(_hand_focus_index + direction, card_count)
_layout_hand_cards()
@@ -4928,7 +4962,7 @@ func _update_hud(state: Dictionary) -> void:
var is_mine : bool = (not _is_spectating) and Game.is_my_turn()
var my : Dictionary = Game.get_my_player()
var opp : Dictionary = Game.get_opponent()
print("[MY]", my)
#print("[MY]", my)
_phase_lbl.text = "Phase: %s" % phase
if _is_spectating:
var active_id : String = str(state.get("activePlayerAccountId", ""))