From 43f9b54a1394e7e2978eb755cd5c7639573c1655 Mon Sep 17 00:00:00 2001 From: Cake <65981767+CakeVR@users.noreply.github.com> Date: Sun, 26 May 2024 09:39:41 +0200 Subject: [PATCH] Improve documentation of Settings Subsystem. Fixes description for Documentation Generation and adds some useful information to public methods. --- .../Modules/Settings/subsystem_settings.gd | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/addons/dialogic/Modules/Settings/subsystem_settings.gd b/addons/dialogic/Modules/Settings/subsystem_settings.gd index 2d489f2ef..ce61eadff 100644 --- a/addons/dialogic/Modules/Settings/subsystem_settings.gd +++ b/addons/dialogic/Modules/Settings/subsystem_settings.gd @@ -1,13 +1,16 @@ extends DialogicSubsystem - ## Subsystem that allows setting and getting settings that are automatically saved slot independent. +## ## All settings that are stored in the project settings dialogic/settings section are supported. ## For example the text_speed setting is stored there. -## Thus it can be acessed like this: -## Dialogic.Settings.text_speed = 0.05 +## How to access this subsystem via code: +## ```gd +## Dialogic.Settings.text_speed = 0.05 +## ``` ## ## Settings stored there can also be changed with the Settings event. + var settings := {} var _connections := {} @@ -59,11 +62,12 @@ func _setting_changed(property:StringName, value:Variant) -> void: #region HANDY METHODS #################################################################################################### -func get_setting(property:StringName, default:Variant) -> Variant: +## Get a setting named `property`, if it does not exist, falls back to `default`. +func get_setting(property: StringName, default: Variant) -> Variant: return _get(property) if _get(property) != null else default - -func has_setting(property:StringName) -> bool: +## Whether a setting has been set/stored before. +func has_setting(property: StringName) -> bool: return property in settings @@ -72,7 +76,7 @@ func reset_all() -> void: reset_setting(setting) -func reset_setting(property:StringName) -> void: +func reset_setting(property: StringName) -> void: if ProjectSettings.has_setting('dialogic/settings/'+property): settings[property] = ProjectSettings.get_setting('dialogic/settings/'+property) _setting_changed(property, settings[property]) @@ -80,10 +84,10 @@ func reset_setting(property:StringName) -> void: settings.erase(property) _setting_changed(property, null) - -func connect_to_change(setting:StringName, callable:Callable) -> void: - if !setting in _connections: - _connections[setting] = [] - _connections[setting].append(callable) +## If a setting named `property` changes its value, this will emit `Callable`. +func connect_to_change(property: StringName, callable: Callable) -> void: + if not property in _connections: + _connections[property] = [] + _connections[property].append(callable) #endregion