mirror of
https://github.com/JohnBreaux/Boat-Battle.git
synced 2024-11-15 05:25:57 +00:00
Added options remember settings after closing and reopening game
Options file is saved to "(user)/AppData/Godot/app_userdata/godot_ship/options.save"
This commit is contained in:
parent
678ebdb95e
commit
c83e10668c
@ -7,27 +7,27 @@ onready var theme_buttons = find_node("Buttons", true, true).get_children()
|
|||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
OptionsController.load_options()
|
||||||
find_next_valid_focus().grab_focus()
|
find_next_valid_focus().grab_focus()
|
||||||
sound_slider.value = OptionsController.get_sfx_volume()
|
sound_slider.value = OptionsController.get_sfx_volume()
|
||||||
music_slider.value = OptionsController.get_mus_volume()
|
music_slider.value = OptionsController.get_mus_volume()
|
||||||
|
|
||||||
|
|
||||||
func _on_Button_pressed():
|
func _on_Button_pressed():
|
||||||
queue_free()
|
queue_free()
|
||||||
# MessageBus.emit_signal("change_scene", "Title")
|
# MessageBus.emit_signal("change_scene", "Title")
|
||||||
|
|
||||||
|
|
||||||
func _on_SFX_Slider_value_changed(value):
|
func _on_SFX_Slider_value_changed(value):
|
||||||
OptionsController.set_sfx_vol(value)
|
OptionsController.set_sfx_vol(value)
|
||||||
|
OptionsController.save_options()
|
||||||
|
|
||||||
func _on_Volume_Slider_value_changed(value):
|
func _on_Volume_Slider_value_changed(value):
|
||||||
OptionsController.set_mus_vol(value)
|
OptionsController.set_mus_vol(value)
|
||||||
|
OptionsController.save_options()
|
||||||
|
|
||||||
func _on_Light_pressed():
|
func _on_Light_pressed():
|
||||||
OptionsController.set_theme("light")
|
OptionsController.set_theme("light")
|
||||||
|
OptionsController.save_options()
|
||||||
|
|
||||||
func _on_Dark_pressed():
|
func _on_Dark_pressed():
|
||||||
OptionsController.set_theme("dark")
|
OptionsController.set_theme("dark")
|
||||||
|
OptionsController.save_options()
|
||||||
|
@ -7,6 +7,8 @@ signal change_mus_volume (volume)
|
|||||||
signal change_sfx_volume (volume)
|
signal change_sfx_volume (volume)
|
||||||
|
|
||||||
# Option variables
|
# Option variables
|
||||||
|
var f = File.new()
|
||||||
|
var options_file = "user://options.save"
|
||||||
var theme = "dark"
|
var theme = "dark"
|
||||||
var mus_vol = 100
|
var mus_vol = 100
|
||||||
var sfx_vol = 100
|
var sfx_vol = 100
|
||||||
@ -27,6 +29,21 @@ func set_sfx_vol(volume):
|
|||||||
sfx_vol = volume
|
sfx_vol = volume
|
||||||
emit_signal("change_sfx_volume", sfx_vol)
|
emit_signal("change_sfx_volume", sfx_vol)
|
||||||
|
|
||||||
|
#Option Save File
|
||||||
|
func save_options():
|
||||||
|
f.open(options_file, File.WRITE)
|
||||||
|
f.store_var(theme)
|
||||||
|
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()
|
||||||
|
mus_vol = f.get_var()
|
||||||
|
sfx_vol = f.get_var()
|
||||||
|
f.close()
|
||||||
|
|
||||||
# Getters
|
# Getters
|
||||||
func get_theme():
|
func get_theme():
|
||||||
return theme
|
return theme
|
||||||
|
Loading…
Reference in New Issue
Block a user