aboutsummaryrefslogtreecommitdiff
path: root/client/system
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-08 01:01:53 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-08 01:01:53 +0200
commitfe711a11cfcfeca06c085a56f2e1d5f68a049337 (patch)
tree42d6bd6ef076b95ab86e64dda36552e45fd34a11 /client/system
parent4e655f4e648b64b6f416da7183a8d555745fa163 (diff)
downloadhurrycurry-fe711a11cfcfeca06c085a56f2e1d5f68a049337.tar
hurrycurry-fe711a11cfcfeca06c085a56f2e1d5f68a049337.tar.bz2
hurrycurry-fe711a11cfcfeca06c085a56f2e1d5f68a049337.tar.zst
Unhook setting callbacks when hooking node is freed
Diffstat (limited to 'client/system')
-rw-r--r--client/system/settings.gd50
1 files changed, 32 insertions, 18 deletions
diff --git a/client/system/settings.gd b/client/system/settings.gd
index e7f3e2f7..e7f718fb 100644
--- a/client/system/settings.gd
+++ b/client/system/settings.gd
@@ -115,6 +115,7 @@ static func load(path: String):
var f = FileAccess.open(path, FileAccess.READ)
changed = JSON.parse_string(f.get_as_text())
tree.load(changed)
+ setup_static_hooks()
static func save():
var changed = {}
@@ -128,11 +129,25 @@ static func trigger_hook(key: String, value):
change_hooks[key][slot].callv([value] if value != null else [])
if key.find(".") != -1: trigger_hook(key.rsplit(".", false, 1)[0], key.rsplit(".", false, 1)[1])
-static func hook_changed(key: String, slot: String, callable: Callable):
+# slot: String | Node
+static func hook_changed(key: String, slot, callable: Callable):
+ var slot_id = 0
+ if slot is Node:
+ slot_id = slot.get_instance_id()
+ slot.tree_exiting.connect(_unhook_changed.bind(key, slot_id))
+ elif slot is String:
+ slot_id = slot.hash()
+ else:
+ push_error("hook_changed called with invalid slot")
+ return
if not change_hooks.has(key): change_hooks[key] = {}
- change_hooks[key][slot] = callable
+ change_hooks[key][slot_id] = callable
+
+static func _unhook_changed(key: String, slot_id: int):
+ change_hooks[key].erase(slot_id)
-static func hook_changed_init(key: String, slot: String, callable: Callable):
+# slot: String | Node
+static func hook_changed_init(key: String, slot, callable: Callable):
hook_changed(key, slot, callable)
callable.call(read(key))
@@ -147,18 +162,20 @@ static func get_category_dict(prefix: String):
static func launch_setup():
Global.focused_menu.submenu("res://gui/menus/setup/setup.tscn")
-static var change_hooks = {
- "input": { "static": h_input },
- "graphics.aa": { "static": h_aa },
- "graphics.taa": { "static": h_taa },
- "graphics.fullscreen": { "static": h_fullscreen },
- "ui.scale_mode": { "static": h_scale_mode },
- "ui.scale_factor": { "static": h_scale_factor },
- "ui.language": { "static": h_language },
- "audio.master_volume": { "static": h_volume_master },
- "audio.music_volume": { "static": h_volume_music },
- "audio.sfx_volume": { "static": h_volume_sfx },
-}
+static var change_hooks = {}
+
+static func setup_static_hooks():
+ for action in InputManager.action_list():
+ hook_changed_init("input.%s" % action, "static", InputManager.update_input_map.bind(action))
+ hook_changed_init("graphics.aa", "static", h_aa)
+ hook_changed_init("graphics.taa", "static", h_taa)
+ hook_changed_init("graphics.fullscreen", "static", h_fullscreen)
+ hook_changed_init("ui.scale_mode", "static", h_scale_mode)
+ hook_changed_init("ui.scale_factor", "static", h_scale_factor)
+ hook_changed_init("ui.language", "static", h_language)
+ hook_changed_init("audio.master_volume", "static", h_volume_master)
+ hook_changed_init("audio.music_volume", "static", h_volume_music)
+ hook_changed_init("audio.sfx_volume", "static", h_volume_sfx)
static func h_aa(_mode):
Global.configure_viewport_aa(Global.get_viewport())
@@ -186,9 +203,6 @@ static func h_language(language: String):
if language == "system": language = OS.get_locale_language()
TranslationServer.set_locale(language)
-static func h_input(key: String):
- InputManager.update_input_map(key)
-
static func h_fullscreen(mode: String):
match mode:
"keep": pass