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 = get_node("PauseOverlay")
onready var pause_title: Label = get_node("PauseOverlay/Title")

var paused := false setget set_paused

func _ready():
	PlayerData.connect("player_died", self, "_on_PlayerData_player_died")


func _on_PlayerData_player_died() -> void:
	self.paused = true
	pause_title.text = "You lost"


func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("pause") and pause_title.text != "You lost":
		#not oder ! schaltet einen boolean um
		#Ist self hier notwendig?
		self.paused = not paused
		get_tree().set_input_as_handled()


func set_paused(value: bool) -> void:
	paused = value
	get_tree().paused = value
	pause_overlay.visible = value
