Guard archSpirit nil in game ownership/render loops

This commit is contained in:
Shard
2026-03-27 14:17:24 +00:00
parent 8736217241
commit e5a9bde653
@@ -903,6 +903,11 @@ func _is_friendly_unit(instance_id: String) -> bool:
return _friendly_unit_ids.has(instance_id) return _friendly_unit_ids.has(instance_id)
func _safe_arch(player: Dictionary) -> Dictionary:
var arch = player.get("archSpirit")
return arch as Dictionary if arch is Dictionary else {}
func _rebuild_ownership(state: Dictionary) -> void: func _rebuild_ownership(state: Dictionary) -> void:
_enemy_unit_ids.clear() _enemy_unit_ids.clear()
_friendly_unit_ids.clear() _friendly_unit_ids.clear()
@@ -913,7 +918,7 @@ func _rebuild_ownership(state: Dictionary) -> void:
for u: Dictionary in p.get("field", []): for u: Dictionary in p.get("field", []):
var iid : String = u.get("instanceId", "") var iid : String = u.get("instanceId", "")
if not iid.is_empty(): target[iid] = true if not iid.is_empty(): target[iid] = true
var arch : Dictionary = p.get("archSpirit", {}) var arch : Dictionary = _safe_arch(p)
var aid : String = arch.get("instanceId", "") var aid : String = arch.get("instanceId", "")
if not aid.is_empty(): target[aid] = true if not aid.is_empty(): target[aid] = true
@@ -1177,7 +1182,7 @@ func _rebuild_units(state: Dictionary) -> void:
for player: Dictionary in state.get("players", []): for player: Dictionary in state.get("players", []):
var is_mine : bool = str(player.get("accountId", "")).to_lower() == my_id.to_lower() var is_mine : bool = str(player.get("accountId", "")).to_lower() == my_id.to_lower()
var color : Color = Color(0.3, 0.5, 1.0) if is_mine else Color(1.0, 0.35, 0.35) var color : Color = Color(0.3, 0.5, 1.0) if is_mine else Color(1.0, 0.35, 0.35)
var arch : Dictionary = player.get("archSpirit", {}) var arch : Dictionary = _safe_arch(player)
for unit: Dictionary in ([arch] + player.get("field", [])): for unit: Dictionary in ([arch] + player.get("field", [])):
if unit.is_empty() or unit.get("position") == null: continue if unit.is_empty() or unit.get("position") == null: continue
var iid : String = str(unit.get("instanceId", "")) var iid : String = str(unit.get("instanceId", ""))
@@ -1812,7 +1817,7 @@ func _update_prev_state(state: Dictionary) -> void:
_prev_unit_hp.clear() _prev_unit_hp.clear()
_prev_unit_pos.clear() _prev_unit_pos.clear()
for player: Dictionary in state.get("players", []): for player: Dictionary in state.get("players", []):
var arch : Dictionary = player.get("archSpirit", {}) var arch : Dictionary = _safe_arch(player)
for unit: Dictionary in ([arch] + player.get("field", [])): for unit: Dictionary in ([arch] + player.get("field", [])):
if unit.is_empty(): continue if unit.is_empty(): continue
var iid := str(unit.get("instanceId", "")) var iid := str(unit.get("instanceId", ""))
@@ -1934,7 +1939,7 @@ func _play_move_animations(state: Dictionary) -> float:
blocked[_prev_unit_pos[prev_iid]] = true blocked[_prev_unit_pos[prev_iid]] = true
var max_dur := 0.0 var max_dur := 0.0
for player: Dictionary in state.get("players", []): for player: Dictionary in state.get("players", []):
var arch : Dictionary = player.get("archSpirit", {}) var arch : Dictionary = _safe_arch(player)
for unit: Dictionary in ([arch] + player.get("field", [])): for unit: Dictionary in ([arch] + player.get("field", [])):
if unit.is_empty(): continue if unit.is_empty(): continue
var iid := str(unit.get("instanceId", "")) var iid := str(unit.get("instanceId", ""))
@@ -2615,7 +2620,7 @@ func _confirm_transition(card: Dictionary) -> void:
func _get_my_arch_tier() -> int: func _get_my_arch_tier() -> int:
var arch : Dictionary = Game.get_my_player().get("archSpirit", {}) var arch : Dictionary = _safe_arch(Game.get_my_player())
return int(arch.get("tier", 1)) return int(arch.get("tier", 1))