extends Area2D

export var stream: AudioStream
export var caption: String
export var audio_delay: float
export var duration: float
onready var player = $AudioStreamPlayer
onready var label = $"../../UI/Caption"
onready var delay_timer = $AudioDelay
onready var label_timer = $LabelTime

func _ready():
	player.set_stream(stream)
	#
	delay_timer.set_wait_time(audio_delay)
	label_timer.set_wait_time(duration)

func _on_body_entered(_body):
	delay_timer.start()

func _on_label_timeout():
	label.set_visible(false)
	AudioServer.set_bus_volume_db(2, 0.0)

func _on_delay_timeout():
	label_timer.start()
	label.parse_bbcode('[center]' + caption + '[/center]')
	AudioServer.set_bus_volume_db(2, -10.0)
	label.set_visible(true)
	player.play()
