Class SettingsManager
- Namespace
- AshesOfVelsingrad.Managers
- Assembly
- Ashes of Velsingrad.dll
Manages game settings and provides centralized access to configuration options. Follows the Manager Pattern from your architecture.
[ScriptPath("res://scripts/managers/SettingsManager.cs")]
public class SettingsManager : BaseManager, IDisposable
- Inheritance
-
GodotObjectNodeSettingsManager
- Implements
- Inherited Members
-
Node.NotificationEnterTreeNode.NotificationExitTreeNode.NotificationMovedInParentNode.NotificationReadyNode.NotificationPausedNode.NotificationUnpausedNode.NotificationPhysicsProcessNode.NotificationProcessNode.NotificationParentedNode.NotificationUnparentedNode.NotificationSceneInstantiatedNode.NotificationDragBeginNode.NotificationDragEndNode.NotificationPathRenamedNode.NotificationChildOrderChangedNode.NotificationInternalProcessNode.NotificationInternalPhysicsProcessNode.NotificationPostEnterTreeNode.NotificationDisabledNode.NotificationEnabledNode.NotificationResetPhysicsInterpolationNode.NotificationEditorPreSaveNode.NotificationEditorPostSaveNode.NotificationWMMouseEnterNode.NotificationWMMouseExitNode.NotificationWMWindowFocusInNode.NotificationWMWindowFocusOutNode.NotificationWMCloseRequestNode.NotificationWMGoBackRequestNode.NotificationWMSizeChangedNode.NotificationWMDpiChangeNode.NotificationVpMouseEnterNode.NotificationVpMouseExitNode.NotificationWMPositionChangedNode.NotificationOsMemoryWarningNode.NotificationTranslationChangedNode.NotificationWMAboutNode.NotificationCrashNode.NotificationOsImeUpdateNode.NotificationApplicationResumedNode.NotificationApplicationPausedNode.NotificationApplicationFocusInNode.NotificationApplicationFocusOutNode.NotificationTextServerChangedNode.NotificationAccessibilityUpdateNode.NotificationAccessibilityInvalidateNode.GetNode<T>(NodePath)Node.GetNodeOrNull<T>(NodePath)Node.GetOwner<T>()Node.GetOwnerOrNull<T>()Node.GetParent<T>()Node.GetParentOrNull<T>()Node._EnterTree()Node._GetAccessibilityConfigurationWarnings()Node._GetConfigurationWarnings()Node._GetFocusedAccessibilityElement()Node._Input(InputEvent)Node._ShortcutInput(InputEvent)Node._UnhandledInput(InputEvent)Node._UnhandledKeyInput(InputEvent)Node.PrintOrphanNodes()Node.GetOrphanNodeIds()Node.RemoveChild(Node)Node.HasNode(NodePath)Node.GetNode(NodePath)Node.GetNodeOrNull(NodePath)Node.GetParent()Node.HasNodeAndResource(NodePath)Node.GetNodeAndResource(NodePath)Node.IsInsideTree()Node.IsPartOfEditedScene()Node.IsAncestorOf(Node)Node.IsGreaterThan(Node)Node.GetPath()Node.RemoveFromGroup(StringName)Node.IsInGroup(StringName)Node.GetGroups()Node.PrintTree()Node.PrintTreePretty()Node.GetTreeString()Node.GetTreeStringPretty()Node.GetPhysicsProcessDeltaTime()Node.IsPhysicsProcessing()Node.GetProcessDeltaTime()Node.IsProcessing()Node.IsProcessingInput()Node.IsProcessingShortcutInput()Node.IsProcessingUnhandledInput()Node.IsProcessingUnhandledKeyInput()Node.CanProcess()Node.QueueAccessibilityUpdate()Node.GetAccessibilityElement()Node.IsDisplayedFolded()Node.IsProcessingInternal()Node.IsPhysicsProcessingInternal()Node.IsPhysicsInterpolated()Node.IsPhysicsInterpolatedAndEnabled()Node.ResetPhysicsInterpolation()Node.CanAutoTranslate()Node.SetTranslationDomainInherited()Node.GetWindow()Node.GetLastExclusiveWindow()Node.GetTree()Node.CreateTween()Node.GetSceneInstanceLoadPlaceholder()Node.IsEditableInstance(Node)Node.GetViewport()Node.QueueFree()Node.RequestReady()Node.IsNodeReady()Node.GetMultiplayerAuthority()Node.IsMultiplayerAuthority()Node.RpcConfig(StringName, Variant)Node.GetNodeRpcConfig()Node.Rpc(StringName, params Variant[])Node.UpdateConfigurationWarnings()Node.CallDeferredThreadGroup(StringName, params Variant[])Node.SetDeferredThreadGroup(StringName, Variant)Node.CallThreadSafe(StringName, params Variant[])Node.SetThreadSafe(StringName, Variant)Node.EmitSignalReady()Node.EmitSignalRenamed()Node.EmitSignalTreeEntered()Node.EmitSignalTreeExiting()Node.EmitSignalTreeExited()Node.EmitSignalChildEnteredTree(Node)Node.EmitSignalChildExitingTree(Node)Node.EmitSignalChildOrderChanged()Node.EmitSignalReplacingBy(Node)Node.EmitSignalEditorDescriptionChanged(Node)Node.EmitSignalEditorStateChanged()Node.InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)Node.HasGodotClassMethod(in godot_string_name)Node.HasGodotClassSignal(in godot_string_name)Node.NameNode.UniqueNameInOwnerNode.SceneFilePathNode.OwnerNode.MultiplayerNode.ProcessModeNode.ProcessPriorityNode.ProcessPhysicsPriorityNode.ProcessThreadGroupNode.ProcessThreadGroupOrderNode.ProcessThreadMessagesNode.PhysicsInterpolationModeNode.AutoTranslateModeNode.EditorDescriptionNode.ReadyNode.RenamedNode.TreeEnteredNode.TreeExitingNode.TreeExitedNode.ChildEnteredTreeNode.ChildExitingTreeNode.ChildOrderChangedNode.ReplacingByNode.EditorDescriptionChangedNode.EditorStateChangedGodotObject.NotificationPostinitializeGodotObject.NotificationPredeleteGodotObject.NotificationExtensionReloadedGodotObject.IsInstanceValid(GodotObject)GodotObject.WeakRef(GodotObject)GodotObject.Dispose()GodotObject.ToString()GodotObject.ToSignal(GodotObject, StringName)GodotObject._Get(StringName)GodotObject._GetPropertyList()GodotObject._IterGet(Variant)GodotObject._IterInit(Array)GodotObject._IterNext(Array)GodotObject._PropertyCanRevert(StringName)GodotObject._PropertyGetRevert(StringName)GodotObject._Set(StringName, Variant)GodotObject._ValidateProperty(Dictionary)GodotObject.Free()GodotObject.GetClass()GodotObject.Set(StringName, Variant)GodotObject.Get(StringName)GodotObject.SetIndexed(NodePath, Variant)GodotObject.GetIndexed(NodePath)GodotObject.GetPropertyList()GodotObject.GetMethodList()GodotObject.PropertyCanRevert(StringName)GodotObject.PropertyGetRevert(StringName)GodotObject.GetInstanceId()GodotObject.SetScript(Variant)GodotObject.GetScript()GodotObject.SetMeta(StringName, Variant)GodotObject.RemoveMeta(StringName)GodotObject.GetMeta(StringName, Variant)GodotObject.HasMeta(StringName)GodotObject.GetMetaList()GodotObject.HasUserSignal(StringName)GodotObject.RemoveUserSignal(StringName)GodotObject.EmitSignal(StringName, params Variant[])GodotObject.Call(StringName, params Variant[])GodotObject.CallDeferred(StringName, params Variant[])GodotObject.SetDeferred(StringName, Variant)GodotObject.Callv(StringName, Array)GodotObject.HasMethod(StringName)GodotObject.GetMethodArgumentCount(StringName)GodotObject.HasSignal(StringName)GodotObject.GetSignalList()GodotObject.GetSignalConnectionList(StringName)GodotObject.GetIncomingConnections()GodotObject.Disconnect(StringName, Callable)GodotObject.IsConnected(StringName, Callable)GodotObject.HasConnections(StringName)GodotObject.IsBlockingSignals()GodotObject.NotifyPropertyListChanged()GodotObject.CanTranslateMessages()GodotObject.Tr(StringName, StringName)GodotObject.GetTranslationDomain()GodotObject.SetTranslationDomain(StringName)GodotObject.IsQueuedForDeletion()GodotObject.CancelFree()GodotObject.EmitSignalScriptChanged()GodotObject.EmitSignalPropertyListChanged()GodotObject.NativeInstanceGodotObject.ScriptChangedGodotObject.PropertyListChanged
Properties
Instance
public static SettingsManager? Instance { get; }
Property Value
Methods
EmitSignalDialogueSizeChanged(float)
protected void EmitSignalDialogueSizeChanged(float newSize)
Parameters
newSizefloat
EmitSignalInputBindingChanged(string)
protected void EmitSignalInputBindingChanged(string action)
Parameters
actionstring
EmitSignalSettingsChanged(string, Variant)
protected void EmitSignalSettingsChanged(string settingKey, Variant newValue)
Parameters
settingKeystringnewValueVariant
GetDialogueSize()
Gets the current dialogue size setting.
public float GetDialogueSize()
Returns
- float
The dialogue size as a float, defaulting to 1.0f if not set.
Remarks
This method retrieves the dialogue size from the settings data. If the dialogue size is not set, it returns a default value of 1.0f.
GetInputBinding(string)
Gets the current input binding for an action.
public InputEvent? GetInputBinding(string action)
Parameters
actionstringThe action name to retrieve the binding for.
Returns
- InputEvent
The InputEvent bound to the action, or null if not found.
GetSetting<T>(string, T?)
Gets a custom setting by key, with an optional default value.
public T? GetSetting<T>(string key, T? defaultValue = default)
Parameters
keystringThe key of the setting to retrieve.
defaultValueTThe default value to return if the setting is not found.
Returns
- T
The setting value if found, otherwise the default value.
Type Parameters
TThe type of the setting value.
Remarks
This method retrieves a custom setting from the settings data. If the setting is not found, it returns the provided default value. It uses JSON serialization to convert the setting value to the specified type.
Initialize()
Initializes the SettingsManager singleton instance. Loads settings from the JSON file or creates a new default settings object.
protected override void Initialize()
Remarks
This method is called automatically by Godot when the node is ready. It ensures that only one instance of SettingsManager exists and initializes the settings data. If the settings file does not exist, it creates a new default settings object and saves it.
LoadSettings()
Loads settings from the JSON file. If the file does not exist, creates a new default settings object.
public virtual void LoadSettings()
Remarks
This method reads the settings from a JSON file located at user://settings.json. If the file is not found, it initializes a new SettingsData object with default values and saves it to create the settings file.
ResetToDefaults()
Resets all settings to their default values.
public void ResetToDefaults()
Remarks
This method clears the current settings and initializes a new SettingsData object with default values. It saves the new settings to the JSON file and emits a SettingsChanged signal to notify other components.
SaveSettings()
Saves the current settings to the JSON file.
public virtual void SaveSettings()
Remarks
This method serializes the current settings data to a JSON string and writes it to the user://settings.json file. It handles any exceptions that may occur during the file operations.
SetDialogueSize(float)
Sets the dialogue size and saves the settings. Emits a signal to notify other components of the change.
public void SetDialogueSize(float size)
Parameters
sizefloatThe new dialogue size to set.
Remarks
This method updates the dialogue size in the settings data and saves it to the JSON file. It also emits a SettingsChanged signal to notify other components of the change. The size is clamped between 0.5f and 2.0f to ensure it remains within a reasonable range.
SetInputBinding(string, InputEvent?)
Sets a new input binding for an action and saves the settings. Emits a signal to notify other components of the change.
public void SetInputBinding(string action, InputEvent? inputEvent)
Parameters
actionstringThe action name to set the binding for.
inputEventInputEventThe InputEvent to bind to the action.
SetSetting<T>(string, T)
Sets a custom setting by key and saves the settings. Emits a signal to notify other components of the change.
public void SetSetting<T>(string key, T value)
Parameters
keystringThe key of the setting to set.
valueTThe value to set for the setting.
Type Parameters
TThe type of the setting value.
Remarks
This method updates a custom setting in the settings data and saves it to the JSON file. It also emits a SettingsChanged signal to notify other components of the change. The value is serialized to JSON format before being stored.
Events
DialogueSizeChanged
public event SettingsManager.DialogueSizeChangedEventHandler DialogueSizeChanged
Event Type
InputBindingChanged
public event SettingsManager.InputBindingChangedEventHandler InputBindingChanged
Event Type
SettingsChanged
public event SettingsManager.SettingsChangedEventHandler SettingsChanged