class_name GuildQueue extends Node2D

var length : int :
	get:
		return len(members)
@export var direction : Vector2 = Vector2.ZERO
var members : Array[AdventurerSprite] = []

var front : AdventurerSprite :
	get: return null if len(members) == 0 else members[0]

signal advanced()

func add_member(member : AdventurerSprite) -> void:
	members.append(member)

func remove_member(member : AdventurerSprite) -> void:
	members.erase(member)


func try_advance() -> AdventurerSprite:
	if length > 0:
		return advance()
	else:
		return null

func advance() -> AdventurerSprite:
	advanced.emit()
	return front

func get_last_position() -> Vector2:
	return get_index_position(length - 1)

func get_index_position(idx : int) -> Vector2:
	return global_position + idx * 100 * direction

func get_member_position(member) -> Vector2:
	var idx = members.find(member)
	if idx == -1:
		return Vector2.ZERO
	else:
		return get_index_position(idx)
