extends VBoxContainer

@onready
var score_label : Label = $ScoreLabel
@onready
var length_label : Label = $LengthLabel
@onready
var pending_length_label : Label = $PendingLengthLabel
@onready
var ouroboros_label : Label = $OuroborosPossibleLabel

var ouroboros_possible : bool = false

func _process(_delta: float) -> void:
	score_label.text = "Score\n{score}".format(GameManager)
	length_label.text = "Length\n{0}".format([get_snake_length()])
	var head : Node = get_tree().get_first_node_in_group("Head")
	if head is SnakePart:
		pending_length_label.text = "Eventual\nLength\n{0}".format([get_snake_length() + head.queued_growth])
	if ouroboros_possible:
		ouroboros_label.text = "Ouroboros\nPossible?\nYes"
	else:
		ouroboros_label.text = "Ouroboros\nPossible?\nNo"

func get_snake_length() -> int:
	var length : int = 0
	var obstacles : Array = get_tree().get_nodes_in_group("BlocksSpawn")
	for obstacle in obstacles:
		if obstacle is SnakePart:
			if obstacle.state == obstacle.States.ALIVE:
				length += 1
	
	ouroboros_possible = !length % 2
	return length
