extends Control

# Smart ist es die notwendigen Resourcen vor dem Skriptstart zu laden
onready var current_scene := get_tree().get_current_scene()
onready var pause_overlay: ColorRect = $HUDOverlay
onready var timer: Label = $HUDOverlay/GetBackTimer
onready var score: Label = $HUDOverlay/Score


func _ready():
	#TODO Connect what HOW?
	PlayerData.connect("score_updated", self, "update_interface")
	update_interface()

func _process(delta):
	if timer.visible:
		timer.text = String(round($HUDOverlay/GetBackTimer/Timer.time_left))

func start_timer():
	timer.visible = true
	$HUDOverlay/GetBackTimer/Timer.start()
	$HUDOverlay/GetBackTimer/AnimationPlayer.play("Redlight")
	_zoom_timer()


func _zoom_timer() -> void:
	var tween := create_tween()
	tween.tween_property(timer, "rect_scale", Vector2(1,1), 1.0)


func update_interface() -> void:
	score.text = "Score: %s" % PlayerData.score


func _on_UserInterface_terminal_activated() -> void:
	start_timer()
