Fix: BFS path type error Array vs Array[Vector2i]
Queue entries store paths as plain Array (nested in an untyped Array). GDScript cannot implicitly upcast Array → Array[Vector2i] on pop_front. Keep path variables untyped while building; use Array.assign() to produce a typed Array[Vector2i] only at the final return point. 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:
@@ -801,7 +801,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 := player.get("archSpirit", {})
|
var arch : Dictionary = player.get("archSpirit", {})
|
||||||
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", ""))
|
||||||
@@ -828,9 +828,9 @@ func _bfs_path(from: Vector2i, to: Vector2i, blocked: Dictionary) -> Array[Vecto
|
|||||||
# Queue entries: [pos: Vector2i, path: Array[Vector2i]]
|
# Queue entries: [pos: Vector2i, path: Array[Vector2i]]
|
||||||
var queue : Array = [[from, []]]
|
var queue : Array = [[from, []]]
|
||||||
while not queue.is_empty():
|
while not queue.is_empty():
|
||||||
var front = queue.pop_front()
|
var front = queue.pop_front()
|
||||||
var cur : Vector2i = front[0]
|
var cur : Vector2i = front[0]
|
||||||
var path : Array[Vector2i] = front[1]
|
var path : Array = front[1] # untyped — stored in a plain Array queue
|
||||||
for d : Vector2i in DIRS:
|
for d : Vector2i in DIRS:
|
||||||
var nxt := cur + d
|
var nxt := cur + d
|
||||||
if nxt.x < 0 or nxt.x >= bw or nxt.y < 0 or nxt.y >= bh:
|
if nxt.x < 0 or nxt.x >= bw or nxt.y < 0 or nxt.y >= bh:
|
||||||
@@ -840,10 +840,12 @@ func _bfs_path(from: Vector2i, to: Vector2i, blocked: Dictionary) -> Array[Vecto
|
|||||||
if blocked.has(nxt) and nxt != to:
|
if blocked.has(nxt) and nxt != to:
|
||||||
continue
|
continue
|
||||||
visited[nxt] = true
|
visited[nxt] = true
|
||||||
var new_path : Array[Vector2i] = path.duplicate()
|
var new_path : Array = path.duplicate()
|
||||||
new_path.append(nxt)
|
new_path.append(nxt)
|
||||||
if nxt == to:
|
if nxt == to:
|
||||||
return new_path
|
var typed : Array[Vector2i] = []
|
||||||
|
typed.assign(new_path)
|
||||||
|
return typed
|
||||||
queue.append([nxt, new_path])
|
queue.append([nxt, new_path])
|
||||||
return [to] # fallback: direct jump
|
return [to] # fallback: direct jump
|
||||||
|
|
||||||
@@ -892,7 +894,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 := player.get("archSpirit", {})
|
var arch : Dictionary = player.get("archSpirit", {})
|
||||||
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", ""))
|
||||||
|
|||||||
Reference in New Issue
Block a user