Merge branch '25-add-a-configuration-file-to-save-user-preferences' into aleajactaest
This commit is contained in:
commit
5c084efca6
5 changed files with 38 additions and 3 deletions
|
@ -17,6 +17,7 @@ config/features=PackedStringArray("4.0", "Vulkan Clustered")
|
||||||
|
|
||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
|
user_settings="*res://scripts/user_settings.gd"
|
||||||
Themes="*res://scripts/themes.gd"
|
Themes="*res://scripts/themes.gd"
|
||||||
Common="*res://scripts/common.gd"
|
Common="*res://scripts/common.gd"
|
||||||
Screenshot="*res://scripts/screenshot.gd"
|
Screenshot="*res://scripts/screenshot.gd"
|
||||||
|
|
|
@ -42,8 +42,10 @@ func _ready():
|
||||||
# var t = linear2db(0.0)
|
# var t = linear2db(0.0)
|
||||||
# var u = db2linear($Music.get_volume_db())
|
# var u = db2linear($Music.get_volume_db())
|
||||||
# Common.msg_debug("volume :" + str(u))
|
# Common.msg_debug("volume :" + str(u))
|
||||||
$Window/VBox/Tab/Mixer/MusicLevel/music.set_value( int(db2linear($Music.get_volume_db()) * 100.0))
|
var music_volume = float(user_settings.configuration["sound"]["music_volume"])
|
||||||
$Window/VBox/Tab/Mixer/MusicLevel/Value.set_text(str(int(db2linear($Music.get_volume_db()) * 100.0)))
|
$Music.set_volume_db(linear2db(music_volume/100.0))
|
||||||
|
$Window/VBox/Tab/Mixer/MusicLevel/music.set_value( int(db2linear($Music.get_volume_db()) * 100))
|
||||||
|
$Window/VBox/Tab/Mixer/MusicLevel/Value.set_text(str(int(db2linear($Music.get_volume_db()) * 100)))
|
||||||
var bus_name = $Music.get_bus()
|
var bus_name = $Music.get_bus()
|
||||||
Common.msg_debug("bus_name: " + str(bus_name))
|
Common.msg_debug("bus_name: " + str(bus_name))
|
||||||
var bus_id = AudioServer.get_bus_index(bus_name)
|
var bus_id = AudioServer.get_bus_index(bus_name)
|
||||||
|
@ -221,7 +223,8 @@ func _on_effect_value_changed(value):
|
||||||
func _on_music_value_changed(value):
|
func _on_music_value_changed(value):
|
||||||
$Music.set_volume_db(linear2db(value/100.0))
|
$Music.set_volume_db(linear2db(value/100.0))
|
||||||
$Window/VBox/Tab/Mixer/MusicLevel/Value.set_text(str(value))
|
$Window/VBox/Tab/Mixer/MusicLevel/Value.set_text(str(value))
|
||||||
|
user_settings.configuration["sound"]["music_volume"] = value
|
||||||
|
user_settings.save()
|
||||||
|
|
||||||
func _on_global_value_changed(value):
|
func _on_global_value_changed(value):
|
||||||
AudioServer.set_bus_volume_db(AudioServer.get_bus_index($Music.get_bus()), linear2db(value/100.0))
|
AudioServer.set_bus_volume_db(AudioServer.get_bus_index($Music.get_bus()), linear2db(value/100.0))
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
script = ExtResource( "1_dltpv" )
|
script = ExtResource( "1_dltpv" )
|
||||||
|
|
||||||
[node name="Music" type="AudioStreamPlayer" parent="."]
|
[node name="Music" type="AudioStreamPlayer" parent="."]
|
||||||
|
volume_db = 23.803
|
||||||
|
|
||||||
[node name="EndMusic" type="Timer" parent="."]
|
[node name="EndMusic" type="Timer" parent="."]
|
||||||
|
|
||||||
|
|
5
scripts/README.md
Normal file
5
scripts/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Folder for configuration file
|
||||||
|
|
||||||
|
By default, Godot places the "user://" folder there :
|
||||||
|
|
||||||
|
- on Linux : `~\.local/share/godot/app_userdata/Third Person basic scene/`
|
25
scripts/user_settings.gd
Normal file
25
scripts/user_settings.gd
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
var cfg_path = "user://settings.cfg"
|
||||||
|
@onready var configuration = get_settings()
|
||||||
|
|
||||||
|
func save():
|
||||||
|
Common.msg_debug("Save to config file : %s/%s" % [OS.get_user_data_dir(), cfg_path.replace("user://", "")])
|
||||||
|
var file = ConfigFile.new()
|
||||||
|
for section in configuration.keys():
|
||||||
|
for key in configuration[section].keys():
|
||||||
|
file.set_value(section, key, configuration[section][key])
|
||||||
|
file.save(cfg_path)
|
||||||
|
|
||||||
|
func get_settings():
|
||||||
|
var cfg = {}
|
||||||
|
var config = ConfigFile.new()
|
||||||
|
var cfg_file_content = config.load(cfg_path)
|
||||||
|
if cfg_file_content != OK:
|
||||||
|
return cfg
|
||||||
|
for section in config.get_sections():
|
||||||
|
print ("Config section : %s" % section)
|
||||||
|
for parameter in config.get_section_keys(section):
|
||||||
|
print("Config parameter : %s" % parameter)
|
||||||
|
cfg[section] = {parameter:config.get_value(section, parameter)}
|
||||||
|
return cfg
|
Loading…
Reference in a new issue