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:
@@ -4458,6 +4458,13 @@ func _rebuild_hand(hand: Array) -> void:
|
|||||||
_refresh_hand_selection()
|
_refresh_hand_selection()
|
||||||
return
|
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).
|
# Detect brand-new cards (not in previous server hand, not already queued).
|
||||||
var pending_iids : Array[String] = []
|
var pending_iids : Array[String] = []
|
||||||
for c: Dictionary in _pending_popup_cards:
|
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:
|
if iid not in _cached_hand_iids and iid not in pending_iids:
|
||||||
brand_new.append(card)
|
brand_new.append(card)
|
||||||
|
|
||||||
_cached_hand_iids = new_iids
|
# Drop pending popups for cards that left the hand (avoid typed-array filter).
|
||||||
|
var kept : Array[Dictionary] = []
|
||||||
# Drop pending popups for cards that left the hand.
|
for c: Dictionary in _pending_popup_cards:
|
||||||
_pending_popup_cards = _pending_popup_cards.filter(
|
if c.get("instanceId", "") in new_iids:
|
||||||
func(c: Dictionary) -> bool: return 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.
|
# Queue brand-new cards for popup; exclude them from the live hand display.
|
||||||
for card: Dictionary in brand_new:
|
for card: Dictionary in brand_new:
|
||||||
@@ -4485,9 +4493,10 @@ func _rebuild_hand(hand: Array) -> void:
|
|||||||
popup_iids.append(c.get("instanceId", "") as String)
|
popup_iids.append(c.get("instanceId", "") as String)
|
||||||
|
|
||||||
# Build the display hand (everything except cards waiting in popup queue).
|
# Build the display hand (everything except cards waiting in popup queue).
|
||||||
var display_hand : Array = hand.filter(
|
var display_hand : Array[Dictionary] = []
|
||||||
func(c: Variant) -> bool:
|
for card: Dictionary in hand:
|
||||||
return (c as Dictionary).get("instanceId", "") not in popup_iids)
|
if card.get("instanceId", "") not in popup_iids:
|
||||||
|
display_hand.append(card)
|
||||||
|
|
||||||
_apply_display_hand(display_hand)
|
_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(),
|
" my_player_found=", not Game.get_my_player().is_empty(),
|
||||||
" hand_size=", hand.size(),
|
" hand_size=", hand.size(),
|
||||||
" my_id=", Auth.user_id.substr(0,8))
|
" my_id=", Auth.user_id.substr(0,8))
|
||||||
if not _is_spectating:
|
_rebuild_hand(hand)
|
||||||
_rebuild_hand(hand)
|
|
||||||
_update_hud(state)
|
_update_hud(state)
|
||||||
|
|
||||||
# ── Update position/HP tracking now so the next state update is correct ───
|
# ── Update position/HP tracking now so the next state update is correct ───
|
||||||
|
|||||||
Reference in New Issue
Block a user