diff --git a/board.gd b/board.gd index 6163d54..34df7c2 100644 --- a/board.gd +++ b/board.gd @@ -15,10 +15,16 @@ func top_left_aabb() -> AABB: func bottom_right_aabb() -> AABB: return AABB(position + Vector3(dims.x, 0, dims.y) + Vector3(1,0,2), Vector3.ONE*0.1) -# todo: Array[Piece] -func pieces() -> Array: - # todo: sort for consistency - return get_children() +func pieces() -> Array[Piece]: + var sorted: Array[Piece] = [] + for child in get_children(): + if child is Piece: + sorted.push_back(child) + # important for consistency. + # everything involving pieces is done top to bottom, then left to right + # expensive? yes. wasteful? definitely. worth it? i think so. + sorted.sort_custom(func(a, b): return a.lpos.y < b.lpos.y or a.lpos.x < b.lpos.x) + return sorted func pieces_at(pos: Vector2i) -> Array[Piece]: var out: Array[Piece] = []