extends CanvasLayer

func _ready():
	if EventBus.debug_starting_floor > 0:
		call_deferred("_start")
		return
	get_tree().paused = true

func _unhandled_input(event):
	if event is InputEventKey and event.pressed and not event.echo:
		if event.keycode == KEY_SPACE or event.keycode == KEY_ENTER:
			get_viewport().set_input_as_handled()
			_start()
		elif event.keycode >= KEY_1 and event.keycode <= KEY_9:
			EventBus.debug_starting_floor = event.keycode - KEY_0
			get_viewport().set_input_as_handled()
			_start()
		elif event.keycode == KEY_0:
			EventBus.debug_starting_floor = EventBus.STARTING_FLOOR
			get_viewport().set_input_as_handled()
			_start()

func _start():
	get_tree().paused = false
	EventBus.game_started.emit()
	queue_free()
