Fix occupantId null handling in game_screen.gd
Server sends occupantId as JSON null for empty tiles, not "".
- dict.get("occupantId", "") returns null (not "") when key is present with null value
- Fixed all four occupantId checks to use truthiness instead of "" comparison
- Hold timer: extract to untyped var first then cast, avoids Nil→String assignment crash
- Valid placement/move/channel tiles now correctly identify empty tiles
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:
@@ -525,7 +525,7 @@ func _valid_play_tiles(card: Dictionary) -> Array:
|
||||
for ty in range(bh):
|
||||
var dist : int = abs(tx - ax) + abs(ty - ay)
|
||||
if dist < min_r or dist > max_r: continue
|
||||
if Game.get_tile(tx, ty).get("occupantId", "") != "": continue
|
||||
if Game.get_tile(tx, ty).get("occupantId"): continue
|
||||
results.append(Vector2i(tx, ty))
|
||||
|
||||
"Terramorpha":
|
||||
@@ -561,7 +561,7 @@ func _valid_move_tiles(unit: Dictionary) -> Array:
|
||||
for ty in range(bh):
|
||||
var dist : int = abs(tx - ux) + abs(ty - uy)
|
||||
if dist == 0 or dist > mp: continue
|
||||
if Game.get_tile(tx, ty).get("occupantId", "") != "": continue
|
||||
if Game.get_tile(tx, ty).get("occupantId"): continue
|
||||
results.append(Vector2i(tx, ty))
|
||||
return results
|
||||
|
||||
@@ -624,7 +624,7 @@ func _valid_placement_tiles() -> Array:
|
||||
var bh : int = Game.board_height()
|
||||
var row : int = 0 if my_id == p1_id else bh - 1
|
||||
for tx in range(bw):
|
||||
if Game.get_tile(tx, row).get("occupantId", "") == "":
|
||||
if not Game.get_tile(tx, row).get("occupantId"):
|
||||
results.append(Vector2i(tx, row))
|
||||
return results
|
||||
|
||||
@@ -1217,7 +1217,8 @@ func _on_hold_timer_fired() -> void:
|
||||
if tile.is_empty(): return
|
||||
var aff : String = tile.get("resolvedAffinity", "Void")
|
||||
_ctx_tile_lbl.text = "Tile (%d,%d) — %s" % [_held_coord.x, _held_coord.y, aff]
|
||||
var occupant_id : String = tile.get("occupantId", "")
|
||||
var _raw_occ = tile.get("occupantId")
|
||||
var occupant_id : String = _raw_occ if _raw_occ is String else ""
|
||||
if occupant_id.is_empty():
|
||||
_ctx_unit_lbl.text = ""
|
||||
_ctx_abil_lbl.text = ""
|
||||
|
||||
Reference in New Issue
Block a user