extends Level
var _Cutscenes = {
	"old_man_intro": "res://src/CutScenes/ChallengeCutscene.tscn"
}
var _played_old_man_cutscene = !GameState.is_first_run

func _ready() -> void:
	print("preGameReady")
	_player.set_ability("dash", true)
	_player.set_ability("wall_jump", true)
	_player.set_ability("attack", true)

func _enter_tree():
	if AudioManager.current_music() != AudioManager.Music.PreGame:
		AudioManager.play_music(AudioManager.Music.PreGame)

func _on_OldDudeIntroArea_body_entered(body: Node) -> void:
	if _played_old_man_cutscene: return
	if body.name == 'Player':
		GameState.set_state(GameState.States.CUTSCENE)
		AudioManager.play_music(AudioManager.Music.Abandon)
		var old_man_animation_palyer = $WiseOldDude/AnimationPlayer
		old_man_animation_palyer.play("fade")
		yield(old_man_animation_palyer, "animation_finished")
		old_man_animation_palyer.play("idle")
		
		_played_old_man_cutscene = true
		var scene:CutScene = (load(_Cutscenes.old_man_intro)).instance()
		add_child(scene)
		scene.allow_skip = !GameState.is_first_run
		scene.start_scene(body.get_node("Camera"))
		yield(scene, "cutscene_finished")
		
		old_man_animation_palyer.play_backwards("fade")
		yield(old_man_animation_palyer, "animation_finished")
		
		GameState.set_state(GameState.States.NEW_GAME)
	pass # Replace with function body.

func _process(delta: float) -> void:
	if is_active_level:
		if _player.position.x > 330:
			AmbiantLighting.change_light("NIGHT")
		else:
			AmbiantLighting.change_light("DAY")
