class_name GravePuzzle

extends Puzzle

@onready var timer: Timer = $Timer

@export var graves: Array[Grave] = []

var _last_grave: Grave

func _process(delta):
	var is_finished = true
	for grave in graves:
		if !grave.is_finished:
			is_finished = false
			break;
			
	if !is_complete and is_finished:
		# In case we forget or don't need to add a timer for some rooms
		if timer and timer.is_stopped():
			timer.start()
		elif !timer:
			complete()

func activate_grave(grave: Grave):
	if _last_grave == grave.pair:
		grave.complete()
		grave.pair.complete()
		return
	
	grave.sing()
	_last_grave = grave


func _on_timer_timeout():
	complete()
