fix(spectate): restore _rebuild_hand for spectators, fix typed Array filter

- Removed the outer _is_spectating guard on _rebuild_hand; blocking it
  entirely left _cached_hand_iids stale and skipped other bookkeeping
- Spectator early-exit now inside _rebuild_hand after updating the cache,
  clearing the display hand cleanly
- Replaced Array[Dictionary].filter() (returns untyped Array, silent type
  mismatch on reassignment) with explicit loops into typed Array[Dictionary]
- Same fix for the display_hand build: explicit typed loop instead of
  hand.filter() with Variant cast

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-14 23:30:37 -04:00
co-authored by Claude Happy
parent cdbcf5e2d1
commit 8649384997
+18 -10
View File
@@ -4458,6 +4458,13 @@ func _rebuild_hand(hand: Array) -> void:
_refresh_hand_selection()
return
_cached_hand_iids = new_iids
# Spectators have no playable hand — just clear any stale widgets and stop.
if _is_spectating:
_apply_display_hand([])
return
# Detect brand-new cards (not in previous server hand, not already queued).
var pending_iids : Array[String] = []
for c: Dictionary in _pending_popup_cards:
@@ -4470,11 +4477,12 @@ func _rebuild_hand(hand: Array) -> void:
if iid not in _cached_hand_iids and iid not in pending_iids:
brand_new.append(card)
_cached_hand_iids = new_iids
# Drop pending popups for cards that left the hand.
_pending_popup_cards = _pending_popup_cards.filter(
func(c: Dictionary) -> bool: return c.get("instanceId", "") in new_iids)
# Drop pending popups for cards that left the hand (avoid typed-array filter).
var kept : Array[Dictionary] = []
for c: Dictionary in _pending_popup_cards:
if c.get("instanceId", "") in new_iids:
kept.append(c)
_pending_popup_cards = kept
# Queue brand-new cards for popup; exclude them from the live hand display.
for card: Dictionary in brand_new:
@@ -4485,9 +4493,10 @@ func _rebuild_hand(hand: Array) -> void:
popup_iids.append(c.get("instanceId", "") as String)
# Build the display hand (everything except cards waiting in popup queue).
var display_hand : Array = hand.filter(
func(c: Variant) -> bool:
return (c as Dictionary).get("instanceId", "") not in popup_iids)
var display_hand : Array[Dictionary] = []
for card: Dictionary in hand:
if card.get("instanceId", "") not in popup_iids:
display_hand.append(card)
_apply_display_hand(display_hand)
@@ -5300,8 +5309,7 @@ func _on_state_updated(state: Dictionary) -> void:
" my_player_found=", not Game.get_my_player().is_empty(),
" hand_size=", hand.size(),
" my_id=", Auth.user_id.substr(0,8))
if not _is_spectating:
_rebuild_hand(hand)
_rebuild_hand(hand)
_update_hud(state)
# ── Update position/HP tracking now so the next state update is correct ───