diff options
author | George L. Albany <Megacake1234@gmail.com> | 2023-06-04 02:17:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-04 02:17:28 +0200 |
commit | 3236f51d700674aee6ee6572109ffb3d5fa5fed2 (patch) | |
tree | b898150a8a45e7c0d814459e7f12f39429acefeb /game/src/Game/Menu/OptionMenu/SettingNodes/SettingHSlider.gd | |
parent | 73e29d02e48739aba5ca5db1b9575c67e795400f (diff) | |
parent | b98166b28c47cccff731d30959b8250fb27ff408 (diff) |
Merge pull request #130 from Spartan322/organize/godot-project
Diffstat (limited to 'game/src/Game/Menu/OptionMenu/SettingNodes/SettingHSlider.gd')
-rw-r--r-- | game/src/Game/Menu/OptionMenu/SettingNodes/SettingHSlider.gd | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/game/src/Game/Menu/OptionMenu/SettingNodes/SettingHSlider.gd b/game/src/Game/Menu/OptionMenu/SettingNodes/SettingHSlider.gd new file mode 100644 index 0000000..6fa30ed --- /dev/null +++ b/game/src/Game/Menu/OptionMenu/SettingNodes/SettingHSlider.gd @@ -0,0 +1,41 @@ +extends HSlider +class_name SettingHSlider + +@export +var section_name : String = "setting" + +@export +var setting_name : String = "setting_hslider" + +@export +var default_value : float = 0 + +func _ready(): + Events.Options.load_settings.connect(load_setting) + Events.Options.save_settings.connect(save_setting) + Events.Options.reset_settings.connect(reset_setting) + +func load_setting(file : ConfigFile): + if file == null: return + var load_value = file.get_value(section_name, setting_name, default_value) + match typeof(load_value): + TYPE_FLOAT, TYPE_INT: + if value == load_value: value_changed.emit(value) + value = load_value + return + TYPE_STRING, TYPE_STRING_NAME: + var load_string := load_value as String + if load_string.is_valid_float(): + load_value = load_string.to_float() + if value == load_value: value_changed.emit(value) + value = load_value + return + push_error("Setting value '%s' invalid for setting [%s] \"%s\"" % [load_value, section_name, setting_name]) + value = default_value + +func save_setting(file : ConfigFile): + if file == null: return + file.set_value(section_name, setting_name, value) + +func reset_setting(): + value = default_value |