extends MarginContainer

@export var key : Key = KEY_SPACE
@export var time : float = 3
@export var advance_type : AdvanceType
@export var scene : String
@export var label : String
@onready var progress_bar : ProgressBar = $ProgressBar

enum AdvanceType{
	SCENE,
	DIALOGUE
}
var progress : float = 0
var button_held : bool
var key_held : bool

func _process(delta: float) -> void:
	key_held = Input.is_key_pressed(key)
	if key_held or button_held:
		progress = min(time, progress + delta)
		if progress == time:
			advance()
			return
	else:
		progress = max(0, progress - 2 * delta)
	progress_bar.value = 100 * progress / time

func advance():
	match(advance_type):
		AdvanceType.SCENE:
			Game.switch_scenes(scene)
		AdvanceType.DIALOGUE:
			Game.switch_dialogue(scene, label)

func _on_button_button_down() -> void:
	button_held = true


func _on_button_button_up() -> void:
	button_held = false
