extends CanvasLayer

var _enabled := false

func _ready():
	visible = false
	EventBus.game_started.connect(_on_game_started)

func _on_game_started():
	_enabled = true

func _unhandled_input(event):
	if not _enabled:
		return
	if event is InputEventKey and event.pressed and not event.echo and event.keycode == KEY_ESCAPE:
		_toggle()
		get_viewport().set_input_as_handled()

func _toggle():
	var paused := not get_tree().paused
	get_tree().paused = paused
	visible = paused
