Handle nullable spectator arrays in Game getters
This commit is contained in:
@@ -150,24 +150,28 @@ func get_board() -> Dictionary:
|
||||
return state.get("board", {})
|
||||
|
||||
|
||||
func _as_array(v: Variant) -> Array:
|
||||
return v as Array if v is Array else []
|
||||
|
||||
|
||||
## Returns Array of TileDto dicts.
|
||||
func get_tiles() -> Array:
|
||||
return get_board().get("tiles", [])
|
||||
return _as_array(get_board().get("tiles", []))
|
||||
|
||||
|
||||
## Returns the local player's hand (Array of CardInstanceDto dicts).
|
||||
func get_hand() -> Array:
|
||||
return get_my_player().get("hand", [])
|
||||
return _as_array(get_my_player().get("hand", []))
|
||||
|
||||
|
||||
## Returns the local player's field (Array of CardInstanceDto dicts).
|
||||
func get_field() -> Array:
|
||||
return get_my_player().get("field", [])
|
||||
return _as_array(get_my_player().get("field", []))
|
||||
|
||||
|
||||
## Returns the opponent's field (Array of CardInstanceDto dicts).
|
||||
func get_opponent_field() -> Array:
|
||||
return get_opponent().get("field", [])
|
||||
return _as_array(get_opponent().get("field", []))
|
||||
|
||||
|
||||
## Returns all enemy PlayerStateDto dicts (players not on the same team as the local player).
|
||||
@@ -186,9 +190,10 @@ func get_enemy_players() -> Array:
|
||||
func get_all_enemy_units() -> Array:
|
||||
var units : Array = []
|
||||
for p: Dictionary in get_enemy_players():
|
||||
units.append_array(p.get("field", []))
|
||||
var arch : Dictionary = p.get("archSpirit", {})
|
||||
if not arch.is_empty(): units.append(arch)
|
||||
units.append_array(_as_array(p.get("field", [])))
|
||||
var arch = p.get("archSpirit")
|
||||
if arch is Dictionary and not (arch as Dictionary).is_empty():
|
||||
units.append(arch)
|
||||
return units
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user