stick-the-quick/ui/DebugMenu/SoundTest.gd

58 lines
1.5 KiB
GDScript3
Raw Normal View History

class_name SoundTest extends Control
const MUSIC := {
"calm_before_the_storm.ogg": true,
"chill.ogg": true,
"dramatic_level_music.ogg": true,
"dream1.ogg": true,
"dream2.ogg": true,
"dream3.ogg": true,
"little_lost_doll.ogg": true,
"menu.ogg": true,
"pair_of_three.ogg": true,
"title.ogg": true
}
@onready var _drop_down := (
$OuterMargin/Content/VBoxContainer/HBoxContainer/OptionButton
) as OptionButton
@onready var _play_button := (
$OuterMargin/Content/VBoxContainer/HBoxContainer/Play
) as Button
@onready var _stop_button := (
$OuterMargin/Content/VBoxContainer/HBoxContainer/Stop
) as Button
@onready var _back_button := (
$OuterMargin/Content/VBoxContainer/Back
) as Button
@onready var _sound_effect_player := (
$AudioStreamPlayer
) as AudioStreamPlayer
@onready var _tracks := {}
func _ready() -> void:
_play_button.pressed.connect(_on_play)
_stop_button.pressed.connect(_on_stop)
_back_button.pressed.connect(_on_back)
for fname in DirAccess.get_files_at("res://audio/"):
if fname.ends_with(".ogg"):
var file := load("res://audio/" + fname) as AudioStream
if file:
_tracks[fname] = file
_drop_down.add_item(fname)
func _on_play() -> void:
var fname := _drop_down.get_item_text(_drop_down.selected)
if MUSIC.get(fname, false):
FX.play_bgm(_tracks[fname])
else:
_sound_effect_player.stream = _tracks[fname]
_sound_effect_player.play()
func _on_stop() -> void:
FX.stop_bgm()
_sound_effect_player.stop()
func _on_back() -> void:
UI.Return(self, true)