2021-10-21 10:22:42 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
# signals
|
|
|
|
# Subscribe to these if you want to be notified about changes to the volume
|
|
|
|
signal change_theme (theme)
|
|
|
|
|
|
|
|
# Option variables
|
2021-10-31 10:46:49 +00:00
|
|
|
var f = File.new()
|
|
|
|
var options_file = "user://options.save"
|
2021-10-21 10:22:42 +00:00
|
|
|
var theme = "dark"
|
2021-11-08 04:43:00 +00:00
|
|
|
var mas_vol = 0
|
2021-11-08 03:38:56 +00:00
|
|
|
var mus_vol = 0
|
|
|
|
var sfx_vol = 0
|
2021-10-21 10:22:42 +00:00
|
|
|
|
|
|
|
func _ready():
|
2021-11-01 00:21:23 +00:00
|
|
|
load_options()
|
2021-10-21 10:22:42 +00:00
|
|
|
|
|
|
|
# Setters
|
|
|
|
func set_theme(theme_name):
|
|
|
|
match theme_name:
|
|
|
|
"dark","light":
|
|
|
|
theme = String(theme_name)
|
2021-11-08 04:43:00 +00:00
|
|
|
save_options()
|
2021-10-21 10:22:42 +00:00
|
|
|
emit_signal("change_theme", theme)
|
2021-11-08 04:43:00 +00:00
|
|
|
func set_mas_vol(volume):
|
|
|
|
mas_vol = volume
|
|
|
|
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mas_vol)
|
2021-10-21 10:22:42 +00:00
|
|
|
func set_mus_vol(volume):
|
|
|
|
mus_vol = volume
|
2021-11-08 01:15:13 +00:00
|
|
|
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("BGM"), mus_vol)
|
2021-10-21 10:22:42 +00:00
|
|
|
func set_sfx_vol(volume):
|
|
|
|
sfx_vol = volume
|
2021-11-08 02:33:07 +00:00
|
|
|
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), sfx_vol)
|
2021-10-21 10:22:42 +00:00
|
|
|
|
2021-10-31 10:46:49 +00:00
|
|
|
#Option Save File
|
|
|
|
func save_options():
|
|
|
|
f.open(options_file, File.WRITE)
|
|
|
|
f.store_var(theme)
|
2021-11-08 04:43:00 +00:00
|
|
|
f.store_var(mas_vol)
|
2021-10-31 10:46:49 +00:00
|
|
|
f.store_var(mus_vol)
|
|
|
|
f.store_var(sfx_vol)
|
|
|
|
f.close()
|
|
|
|
func load_options():
|
|
|
|
if f.file_exists(options_file):
|
|
|
|
f.open(options_file, File.READ)
|
|
|
|
theme = f.get_var()
|
2021-11-08 04:43:00 +00:00
|
|
|
mas_vol = f.get_var()
|
2021-10-31 10:46:49 +00:00
|
|
|
mus_vol = f.get_var()
|
|
|
|
sfx_vol = f.get_var()
|
|
|
|
f.close()
|
2021-11-08 04:43:00 +00:00
|
|
|
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mus_vol)
|
2021-11-08 01:15:13 +00:00
|
|
|
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("BGM"), mus_vol)
|
2021-11-08 02:33:07 +00:00
|
|
|
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), sfx_vol)
|
2021-10-31 10:46:49 +00:00
|
|
|
|
2021-10-21 10:22:42 +00:00
|
|
|
# Getters
|
|
|
|
func get_theme():
|
|
|
|
return theme
|
2021-11-08 04:43:00 +00:00
|
|
|
func get_mas_volume():
|
|
|
|
return mas_vol
|
2021-10-21 10:22:42 +00:00
|
|
|
func get_mus_volume():
|
|
|
|
return mus_vol
|
|
|
|
func get_sfx_volume():
|
|
|
|
return sfx_vol
|