ChocolateBird/test/audio_system.gd

52 lines
1.6 KiB
GDScript3
Raw Normal View History

2023-07-27 19:58:29 +09:30
extends Node2D
var inst_buttons = []
var sfx_buttons = []
func _create_sfx_buttons():
var disable_btn := !SoundLoader.has_loaded_audio_samples
for i in SoundLoader.INST_NUM:
var btn = Button.new()
2023-08-23 19:38:59 +09:30
btn.text = 'Inst #%02X' % i
2023-07-27 19:58:29 +09:30
btn.align = Button.ALIGN_CENTER
2023-08-23 19:38:59 +09:30
btn.set_position(Vector2((i%7)*50, (i/7)*24))
btn.rect_min_size.x = 48
2023-07-27 19:58:29 +09:30
add_child(btn)
btn.connect('pressed', SoundLoader, 'play_sample', [i])
inst_buttons.append(btn)
btn.disabled = disable_btn
for i in SoundLoader.SFX_NUM:
var btn = Button.new()
btn.text = 'SFX #%02X' % i
btn.align = Button.ALIGN_CENTER
2023-08-23 19:38:59 +09:30
btn.set_position(Vector2((i%4)*50, 156 + (i/4)*24))
btn.rect_min_size.x = 48
2023-07-27 19:58:29 +09:30
add_child(btn)
btn.connect('pressed', SoundLoader, 'play_sfx', [i])
sfx_buttons.append(btn)
btn.disabled = disable_btn
if disable_btn:
SoundLoader.connect('audio_samples_loaded', self, '_enable_sfx_buttons')
SoundLoader.connect('audio_inst_sample_loaded', self, '_enable_inst_button')
SoundLoader.connect('audio_sfx_sample_loaded', self, '_enable_sfx_button')
func _enable_sfx_buttons():
for btn in sfx_buttons:
btn.disabled = false
for btn in inst_buttons:
btn.disabled = false
func _enable_sfx_button(id: int):
# NB: This assumes sequential loading (may change, probably won't)
for i in id+1:
sfx_buttons[i].disabled = false
func _enable_inst_button(id: int):
# NB: This assumes sequential loading (may change, probably won't)
for i in id+1:
inst_buttons[i].disabled = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
_create_sfx_buttons()