Skip to content

Commit

Permalink
Improve documentation of Settings Subsystem.
Browse files Browse the repository at this point in the history
Fixes description for Documentation Generation and adds some useful information to public methods.
  • Loading branch information
CakeVR authored May 26, 2024
1 parent 1bf165b commit 43f9b54
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions addons/dialogic/Modules/Settings/subsystem_settings.gd
Original file line number Diff line number Diff line change
@@ -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 := {}

Expand Down Expand Up @@ -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


Expand All @@ -72,18 +76,18 @@ 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])
else:
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

0 comments on commit 43f9b54

Please sign in to comment.