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:
@@ -603,6 +603,12 @@ func _on_server_push(type: String, payload: Variant) -> void:
|
|||||||
var d := payload as Dictionary
|
var d := payload as Dictionary
|
||||||
var s := d.get("state", {}) as Dictionary
|
var s := d.get("state", {}) as Dictionary
|
||||||
if not s.is_empty():
|
if not s.is_empty():
|
||||||
|
# Drop stale spectator pushes that belong to a session we already left.
|
||||||
|
var update_sid : String = str(s.get("sessionId", ""))
|
||||||
|
if not session_id.is_empty() and update_sid != session_id:
|
||||||
|
if debug_output:
|
||||||
|
print("[Game] PUSH state_update IGNORED (wrong session): ", update_sid)
|
||||||
|
return
|
||||||
_state_version = int(s.get("stateVersion", -1))
|
_state_version = int(s.get("stateVersion", -1))
|
||||||
if debug_output:
|
if debug_output:
|
||||||
print("[Game] PUSH state_update phase=", s.get("phase","?"),
|
print("[Game] PUSH state_update phase=", s.get("phase","?"),
|
||||||
|
|||||||
@@ -119,12 +119,22 @@ func clear_highlight_override(type: String) -> void:
|
|||||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
_ensure_buses()
|
||||||
_load()
|
_load()
|
||||||
_apply_music()
|
_apply_music()
|
||||||
_apply_sfx()
|
_apply_sfx()
|
||||||
|
|
||||||
# ── Internal ──────────────────────────────────────────────────────────────────
|
# ── Internal ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
func _ensure_buses() -> void:
|
||||||
|
for bus_name in [BUS_MUSIC, BUS_SFX]:
|
||||||
|
if AudioServer.get_bus_index(bus_name) < 0:
|
||||||
|
var idx := AudioServer.bus_count
|
||||||
|
AudioServer.add_bus()
|
||||||
|
AudioServer.set_bus_name(idx, bus_name)
|
||||||
|
AudioServer.set_bus_send(idx, "Master")
|
||||||
|
|
||||||
|
|
||||||
func _apply_music() -> void:
|
func _apply_music() -> void:
|
||||||
var idx := AudioServer.get_bus_index(BUS_MUSIC)
|
var idx := AudioServer.get_bus_index(BUS_MUSIC)
|
||||||
if idx < 0:
|
if idx < 0:
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
[sub_resource type="Theme" id="Theme_056su"]
|
[sub_resource type="Theme" id="Theme_056su"]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ld7sk"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ld7sk"]
|
||||||
|
bg_color = Color(0.38039216, 0.38039216, 0.38039216, 0.58431375)
|
||||||
|
|
||||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xjmfi"]
|
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xjmfi"]
|
||||||
|
|
||||||
@@ -574,12 +575,6 @@ layout_mode = 2
|
|||||||
theme_override_font_sizes/font_size = 15
|
theme_override_font_sizes/font_size = 15
|
||||||
text = "Return to Main Menu"
|
text = "Return to Main Menu"
|
||||||
|
|
||||||
[node name="SettingsLayer" type="CanvasLayer" parent="."]
|
|
||||||
layer = 15
|
|
||||||
|
|
||||||
[node name="InGameSettings" parent="SettingsLayer" instance=ExtResource("2_igs")]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
|
|
||||||
[node name="CamCtrlPanel" type="PanelContainer" parent="HUD"]
|
[node name="CamCtrlPanel" type="PanelContainer" parent="HUD"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
visible = false
|
visible = false
|
||||||
@@ -613,6 +608,12 @@ layout_mode = 2
|
|||||||
toggle_mode = true
|
toggle_mode = true
|
||||||
text = "Zoom"
|
text = "Zoom"
|
||||||
|
|
||||||
|
[node name="SettingsLayer" type="CanvasLayer" parent="."]
|
||||||
|
layer = 15
|
||||||
|
|
||||||
|
[node name="InGameSettings" parent="SettingsLayer" instance=ExtResource("2_igs")]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
|
||||||
[node name="HoldTimer" type="Timer" parent="."]
|
[node name="HoldTimer" type="Timer" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
wait_time = 0.5
|
wait_time = 0.5
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ var _last_click_frame : int = -1
|
|||||||
var _last_click_iid : String = ""
|
var _last_click_iid : String = ""
|
||||||
var _is_spectating : bool = false
|
var _is_spectating : bool = false
|
||||||
var _hand_focus_index : int = 0
|
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 _hand_hover_iid : String = ""
|
||||||
var _cached_hand_iids : Array[String] = []
|
var _cached_hand_iids : Array[String] = []
|
||||||
var _pending_popup_cards : Array[Dictionary] = []
|
var _pending_popup_cards : Array[Dictionary] = []
|
||||||
@@ -916,17 +918,47 @@ func _on_cam_gesture_timer_fired() -> void:
|
|||||||
|
|
||||||
# ── Input ─────────────────────────────────────────────────────────────────────
|
# ── 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:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
var mb := event as 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 mb.button_index == MOUSE_BUTTON_WHEEL_UP:
|
||||||
if _hand_area.get_global_rect().has_point(mb.position):
|
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
|
return
|
||||||
_zoom(1.5); return
|
_zoom(1.5); return
|
||||||
elif mb.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
elif mb.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
||||||
if _hand_area.get_global_rect().has_point(mb.position):
|
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
|
return
|
||||||
_zoom(-1.5); return
|
_zoom(-1.5); return
|
||||||
elif mb.button_index == MOUSE_BUTTON_MIDDLE:
|
elif mb.button_index == MOUSE_BUTTON_MIDDLE:
|
||||||
@@ -4455,7 +4487,7 @@ func _rebuild_hand(hand: Array) -> void:
|
|||||||
# Build new IID list.
|
# Build new IID list.
|
||||||
var new_iids : Array[String] = []
|
var new_iids : Array[String] = []
|
||||||
for card: Dictionary in hand:
|
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 "")
|
new_iids.append(str(raw_iid) if raw_iid != null else "")
|
||||||
if new_iids == _cached_hand_iids:
|
if new_iids == _cached_hand_iids:
|
||||||
_refresh_hand_selection()
|
_refresh_hand_selection()
|
||||||
@@ -4690,7 +4722,8 @@ func _refresh_hand_selection() -> void:
|
|||||||
if not widget.has_meta("card_instance_id"): continue
|
if not widget.has_meta("card_instance_id"): continue
|
||||||
var iid : String = str(widget.get_meta("card_instance_id"))
|
var iid : String = str(widget.get_meta("card_instance_id"))
|
||||||
var sel : bool = ((_mode == Mode.CARD_FROM_HAND
|
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)
|
and _sel_card_id == iid)
|
||||||
if widget.has_method("set_selected"):
|
if widget.has_method("set_selected"):
|
||||||
widget.set_selected(sel)
|
widget.set_selected(sel)
|
||||||
@@ -4772,7 +4805,8 @@ func _spin_hand(direction: int) -> void:
|
|||||||
var card_count := _hand_cards.get_child_count()
|
var card_count := _hand_cards.get_child_count()
|
||||||
if card_count <= 1:
|
if card_count <= 1:
|
||||||
return
|
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)
|
_set_mode(Mode.NONE)
|
||||||
_hand_focus_index = posmod(_hand_focus_index + direction, card_count)
|
_hand_focus_index = posmod(_hand_focus_index + direction, card_count)
|
||||||
_layout_hand_cards()
|
_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 is_mine : bool = (not _is_spectating) and Game.is_my_turn()
|
||||||
var my : Dictionary = Game.get_my_player()
|
var my : Dictionary = Game.get_my_player()
|
||||||
var opp : Dictionary = Game.get_opponent()
|
var opp : Dictionary = Game.get_opponent()
|
||||||
print("[MY]", my)
|
#print("[MY]", my)
|
||||||
_phase_lbl.text = "Phase: %s" % phase
|
_phase_lbl.text = "Phase: %s" % phase
|
||||||
if _is_spectating:
|
if _is_spectating:
|
||||||
var active_id : String = str(state.get("activePlayerAccountId", ""))
|
var active_id : String = str(state.get("activePlayerAccountId", ""))
|
||||||
|
|||||||
Reference in New Issue
Block a user