extends Button
class_name AudibleButton

export(String, FILE) var focus_sound = "res://assets/sounds/Simple Switch Off.ogg"
export(String, FILE) var press_sound = "res://assets/sounds/Simple Switch On.ogg"
var focus_player
var press_player

func _ready() -> void:
    focus_player = AudioStreamPlayer.new()
    focus_player.bus = "UI"
    var asrp = AudioStreamRandomPitch.new()
    asrp.audio_stream = GlobalState.sound_library[focus_sound]
    focus_player.stream = asrp
    #focus_player.volume_db = 5
    add_child(focus_player)
    connect("focus_exited", self, "focus_play")

    press_player = AudioStreamPlayer.new()
    press_player.bus = "UI"
    var asrp2 = AudioStreamRandomPitch.new()
    asrp2.audio_stream = GlobalState.sound_library[press_sound]
    press_player.stream = asrp2
    #press_player.volume_db = 5
    add_child(press_player)
    connect("button_down", self, "press_play")

func focus_play():
    if visible:
        focus_player.play()

func press_play():
    if visible:
        press_player.play()
