extends CanvasLayer

var level_manager
var new_scene_path
@onready var animation_player = $AnimationPlayer

func change_scene_to(new_scene : Utils.GAME_SCENES):
	new_scene_path = Utils.GAME_SCENE_PATHS[new_scene]
	
	Globals.current_scene = new_scene
	
	if animation_player.is_playing():
		animation_player.stop()
	animation_player.play("change_scene")

func _new_scene():
	get_tree().call_deferred("change_scene_to_file", new_scene_path)
	match Globals.current_scene:
		Utils.GAME_SCENES.GAME:
			SignalBus.enter_game()
		_:
			SignalBus.exit_game()

func change_level():
	if level_manager == null:
		printerr("no level_manager registered!")
		return
	
	if animation_player.is_playing():
		animation_player.stop()
	animation_player.play("change_level")

func _new_level():
	level_manager.call_deferred("change")
