fix(spectate): move Game signal connections to top of _ready, null-safe IIDs

- Game.state_updated (and other game signals) now connected before any UI
  setup that could error. Previously they were at line ~340, after hand spin
  button setup — if anything between _configure_hand_spin_buttons and those
  connects threw, spectators would never receive live state pushes (no player
  actions to trigger ACK-based updates as fallback)
- _rebuild_hand now uses str(raw) if raw != null else "" for IID extraction;
  card.get("instanceId", "") returns null (not the default) when the key
  exists with a null value, which would error on append to Array[String]

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:42:28 -04:00
co-authored by Claude Happy
parent 8649384997
commit 573d8cf727
@@ -302,6 +302,16 @@ const ANIM_ALIASES : Dictionary = {
# ── Lifecycle ─────────────────────────────────────────────────────────────────
func _ready() -> void:
# Connect critical game signals first — before anything that could error —
# so state pushes are never missed even if later setup fails.
Game.state_updated.connect(_on_state_updated)
Game.game_over.connect(_on_game_over)
Game.session_abandoned.connect(_on_session_abandoned)
Game.opponent_inactive.connect(_on_opponent_inactive)
Game.inactive_warning.connect(_on_inactive_warning)
Game.both_idle_warning.connect(_on_both_idle_warning)
Game.player_eliminated.connect(_on_player_eliminated)
_setup_environment()
_apply_camera()
_init_cursor_nodes()
@@ -337,14 +347,6 @@ func _ready() -> void:
Chat.set_bubble_visible(true)
Chat.set_bubble_host(_chat_bubble_host)
Game.state_updated.connect(_on_state_updated)
Game.game_over.connect(_on_game_over)
Game.session_abandoned.connect(_on_session_abandoned)
Game.opponent_inactive.connect(_on_opponent_inactive)
Game.inactive_warning.connect(_on_inactive_warning)
Game.both_idle_warning.connect(_on_both_idle_warning)
Game.player_eliminated.connect(_on_player_eliminated)
if Game.is_spectating:
_is_spectating = true
_setup_spectator_ui()
@@ -4453,7 +4455,8 @@ func _rebuild_hand(hand: Array) -> void:
# Build new IID list.
var new_iids : Array[String] = []
for card: Dictionary in hand:
new_iids.append(card.get("instanceId", "") as String)
var raw_iid := card.get("instanceId")
new_iids.append(str(raw_iid) if raw_iid != null else "")
if new_iids == _cached_hand_iids:
_refresh_hand_selection()
return