From 425e4428c7e867658cfb6c125d52f21e958bee47 Mon Sep 17 00:00:00 2001 From: hpham474 Date: Sun, 7 Nov 2021 23:11:19 -0600 Subject: [PATCH] Refactoring: parametrize set volume function --- godot_ship/script/options/Options.gd | 11 ++----- .../script/options/OptionsController.gd | 31 +++++++++++++------ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/godot_ship/script/options/Options.gd b/godot_ship/script/options/Options.gd index 65171c0..09e1bf9 100644 --- a/godot_ship/script/options/Options.gd +++ b/godot_ship/script/options/Options.gd @@ -21,25 +21,20 @@ func _on_Button_pressed(): func _on_Master_Slider_value_changed(value): AudioBus.emit_signal("button_clicked") - OptionsController.set_mas_vol(value) - OptionsController.save_options() + OptionsController.set_vol(value, "mas_vol") func _on_Music_Slider_value_changed(value): AudioBus.emit_signal("button_clicked") - OptionsController.set_mus_vol(value) - OptionsController.save_options() + OptionsController.set_vol(value, "mus_vol") func _on_SFX_Slider_value_changed(value): AudioBus.emit_signal("button_clicked") - OptionsController.set_sfx_vol(value) - OptionsController.save_options() + OptionsController.set_vol(value, "sfx_vol") func _on_Light_pressed(): AudioBus.emit_signal("button_clicked") OptionsController.set_theme("light") - OptionsController.save_options() func _on_Dark_pressed(): AudioBus.emit_signal("button_clicked") OptionsController.set_theme("dark") - OptionsController.save_options() diff --git a/godot_ship/script/options/OptionsController.gd b/godot_ship/script/options/OptionsController.gd index 70082af..ebc92b2 100644 --- a/godot_ship/script/options/OptionsController.gd +++ b/godot_ship/script/options/OptionsController.gd @@ -22,15 +22,28 @@ func set_theme(theme_name): theme = String(theme_name) save_options() emit_signal("change_theme", theme) -func set_mas_vol(volume): - mas_vol = volume - AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mas_vol) -func set_mus_vol(volume): - mus_vol = volume - AudioServer.set_bus_volume_db(AudioServer.get_bus_index("BGM"), mus_vol) -func set_sfx_vol(volume): - sfx_vol = volume - AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), sfx_vol) + save_options() +func set_vol(volume, type): + if type == "mas_vol": + mas_vol = volume + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mas_vol) + elif type == "mus_vol": + mus_vol = volume + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("BGM"), mus_vol) + elif type == "sfx_vol": + sfx_vol = volume + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), sfx_vol) + save_options() + +#func set_mas_vol(volume): +# mas_vol = volume +# AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mas_vol) +#func set_mus_vol(volume): +# mus_vol = volume +# AudioServer.set_bus_volume_db(AudioServer.get_bus_index("BGM"), mus_vol) +#func set_sfx_vol(volume): +# sfx_vol = volume +# AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), sfx_vol) #Option Save File func save_options():