1 extends DialogicSubsystem
2 ## Subsystem that allows setting and getting settings that are automatically saved slot independent.
4 ## All settings that are stored in the project settings dialogic/settings section are supported.
5 ## For example the text_speed setting is stored there.
6 ## How to access this subsystem via code:
8 ## Dialogic.Settings.text_speed = 0.05
11 ## Settings stored there can also be changed with the Settings event.
15 var _connections := {}
19 ####################################################################################################
21 ## Built-in, called by DialogicGameHandler.
22 func clear_game_state(_clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR):
26 func _reload_settings() -> void:
28 for prop in ProjectSettings.get_property_list():
29 if prop.name.begins_with('dialogic/settings'):
30 settings[prop.name.trim_prefix('dialogic/settings/')] = ProjectSettings.get_setting(prop.name)
32 if dialogic.has_subsystem('Save'):
34 settings[i] = dialogic.Save.get_global_info(i, settings[i])
37 func _set(property:StringName, value:Variant) -> bool:
38 if not settings.has(property) or settings[property] != value:
39 _setting_changed(property, value)
40 settings[property] = value
41 if dialogic.has_subsystem('Save'):
42 dialogic.Save.set_global_info(property, value)
46 func _get(property:StringName) -> Variant:
47 if property in settings:
48 return settings[property]
52 func _setting_changed(property:StringName, value:Variant) -> void:
53 if !property in _connections:
56 for i in _connections[property]:
57 if not is_instance_valid(i.get_object()):
58 var remove := func(): _connections[property].erase(i)
59 remove.call_deferred()
67 ####################################################################################################
69 ## Get a setting named `property`, if it does not exist, falls back to `default`.
70 func get_setting(property: StringName, default: Variant) -> Variant:
71 return _get(property) if _get(property) != null else default
73 ## Whether a setting has been set/stored before.
74 func has_setting(property: StringName) -> bool:
75 return property in settings
78 func reset_all() -> void:
79 for setting in settings:
80 reset_setting(setting)
83 func reset_setting(property: StringName) -> void:
84 if ProjectSettings.has_setting('dialogic/settings/'+property):
85 settings[property] = ProjectSettings.get_setting('dialogic/settings/'+property)
86 _setting_changed(property, settings[property])
88 settings.erase(property)
89 _setting_changed(property, null)
92 ## If a setting named `property` changes its value, this will emit `Callable`.
93 func connect_to_change(property: StringName, callable: Callable) -> void:
94 if not property in _connections:
95 _connections[property] = []
96 _connections[property].append(callable)