sort pieces T->B, L->R

This commit is contained in:
mehbark 2025-05-04 19:11:33 -04:00
parent 193888cd2b
commit 1c9fc2de85

View file

@ -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] = []