Created
November 26, 2026 13:30
-
-
Save xphere/61e4e2e7de20bee77c64002dd74ee35e to your computer and use it in GitHub Desktop.
A general setting manager for plugins and games made with Godot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class_name SettingManager | |
| var _prefix: StringName | |
| func _get_config(path: StringName): | |
| return ProjectSettings.get_setting_with_override(_prefix + path) | |
| func _set_config(path: StringName, value): | |
| ProjectSettings.set_setting(_prefix + path, value) | |
| func _init( | |
| prefix: StringName, | |
| settings: Array[SettingDefinition], | |
| ) -> void: | |
| _prefix = prefix | |
| var is_editor: = Engine.is_editor_hint() | |
| for setting in settings: | |
| var path: = prefix + setting.name | |
| if not ProjectSettings.has_setting(path): | |
| ProjectSettings.set_setting(path, setting.default) | |
| if is_editor: | |
| ProjectSettings.set_as_basic(path, setting.is_basic) | |
| ProjectSettings.set_initial_value(path, setting.default) | |
| ProjectSettings.add_property_info({ | |
| "name": path, | |
| "type": setting.type, | |
| "hint": setting.hint, | |
| "hint_string": setting.hint_string, | |
| }) | |
| func define( | |
| name: StringName, | |
| default: Variant, | |
| type: Variant.Type, | |
| hint: PropertyHint = PROPERTY_HINT_NONE, | |
| hint_string: StringName = &"", | |
| is_basic: bool = false, | |
| ) -> SettingDefinition: | |
| var definition: = SettingDefinition.new() | |
| definition.name = name | |
| definition.default = default | |
| definition.type = type | |
| definition.hint = hint | |
| definition.hint_string = hint_string | |
| definition.is_basic = is_basic | |
| return definition | |
| class SettingDefinition: | |
| var name: StringName | |
| var default: Variant | |
| var type: Variant.Type | |
| var hint: PropertyHint | |
| var hint_string: StringName | |
| var is_basic: bool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class_name MyGameOrPluginSettings | |
| extends SettingManager | |
| const _USEFUL_PATH_NAME: = &"useful_path" | |
| var useful_path : StringName : | |
| get(): return _get_config(_USEFUL_PATH) | |
| set(value): return _set_config(_USEFUL_PATH, value) | |
| func _init() -> void: | |
| super( | |
| &"any_prefix_for_game_or_plugin/", | |
| [ | |
| define(_USEFUL_PATH, "default_value", TYPE_STRING, PROPERTY_HINT_FILE, &"*.tscn"), | |
| ] | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment