extends Node3D

const DIALOG_PATH = "res://dialogs/timelines/1_waking_up/3_demeter_ship_presentation.dtl"

var jingle_played := false

# Cheat Code
# func _input(_e):
#     if (
#         Input.is_action_pressed("drop")
#         and Input.is_action_pressed("move_right")
#         and Input.is_action_pressed("move_left")
#         and Input.is_action_just_pressed("action")
#     ):
#         GameInfo.game_data.dialogs_done.append(DIALOG_PATH)
#         finish_scene()

# Called when the node enters the scene tree for the first time.
func _ready():
    Input.mouse_mode = Input.MOUSE_MODE_CAPTURED


    %Phone.play_audio()
    await %Phone.clicked
    %Phone.stop_audio()
    Dialogic.start(DIALOG_PATH)
    await Dialogic.timeline_ended
    AudioManager.stop_all_ambiances()
    %Player3D.controlling_player = false
    %VideoAnimationPlayer.play("Appear")
    (%Video as VideoStreamPlayer).play()
    await (%Video as VideoStreamPlayer).finished
    finish_scene()

func finish_scene():
    GameInfo.game_data.finish_story_step()
    GameInfo.game_data.start_run()
    SceneManager.change_to_scene(CockpitScene.new())

func _on_jingle_area_body_entered(body: Node3D):
    if body is Player3D and not jingle_played:
        AudioManager.play_sfx("Ship_reveal")
        jingle_played = true
