extends Control

@onready var progress_bar: ProgressBar = $ProgressBar
@onready var button: Button = $Button

var score_timer = 0
@export var score_timer_max = 1
@export var score_subtract = 10

@export var gameover_scene : PackedScene
@export var gamewin_scene : PackedScene

func _ready() -> void:
	SignalBus.add_score.connect(add_score)
	score_timer = score_timer_max
	
func add_score(score_to_add : int):
	progress_bar.value += score_to_add
	
	if progress_bar.value <= 0:
		get_tree().change_scene_to_file(gameover_scene.resource_path)
		
	if progress_bar.value >= progress_bar.max_value:
		get_tree().change_scene_to_file(gamewin_scene.resource_path)


func _process(delta: float) -> void:
	pass
	#score_timer -= delta
	#if score_timer <= 0:
		#progress_bar.value -= score_subtract
		#score_timer = score_timer_max

func _on_button_pressed() -> void:
	SignalBus.worldmap.emit()
