diff options
author | metamuffin <metamuffin@disroot.org> | 2025-09-15 01:26:13 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-09-15 01:38:34 +0200 |
commit | 676d4dcb6c439677b91b1b5cbc0bf08f98e2dd9d (patch) | |
tree | 5cd83591e230833735fbdacf41df5c1d69dd8c0e /client/global.gd | |
parent | 4e196b83a42b9b217e3b7107b55a14cb1a005b84 (diff) | |
download | hurrycurry-676d4dcb6c439677b91b1b5cbc0bf08f98e2dd9d.tar hurrycurry-676d4dcb6c439677b91b1b5cbc0bf08f98e2dd9d.tar.bz2 hurrycurry-676d4dcb6c439677b91b1b5cbc0bf08f98e2dd9d.tar.zst |
Refactor settings; store as JSON; input settings now broken
Diffstat (limited to 'client/global.gd')
-rw-r--r-- | client/global.gd | 54 |
1 files changed, 10 insertions, 44 deletions
diff --git a/client/global.gd b/client/global.gd index 5e538123..f308f847 100644 --- a/client/global.gd +++ b/client/global.gd @@ -69,21 +69,20 @@ var focused_menu: Menu # only use this as a last resort, currently exists to ope func _ready(): profile = load_dict("user://profile", default_profile) - load_settings("user://settings") - + Settings.load("user://settings.json") get_viewport().gui_focus_changed.connect(Sound.play_hover_maybe) get_viewport().gui_focus_changed.connect(func(node): focused_node = node) func _input(event): if Input.is_action_just_pressed("fullscreen"): - match Global.get_setting("graphics.fullscreen"): + match get("graphics.fullscreen"): "keep": if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) else: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) - "always": set_setting("graphics.fullscreen", "never") - "never": set_setting("graphics.fullscreen", "always") + "always": set("graphics.fullscreen", "never") + "never": set("graphics.fullscreen", "always") # Update using_joypad variable if event is InputEventMouseButton or event is InputEventKey: @@ -96,7 +95,7 @@ func _input(event): using_joypad_change.emit(using_joypad) # Update using_touch variable - if get_setting("ui.touch_controls") == "automatic": # Only if set to automatic + if Settings.read("ui.touch_controls") == "automatic": # Only if set to automatic if event is InputEventScreenTouch or event is InputEventScreenDrag: if not using_touch: using_touch = true @@ -109,12 +108,6 @@ func _input(event): func save_profile(): save_dict("user://profile", profile) -func save_settings(): - var saved = {} - for key in settings_tree.changed_keys(): - saved[key] = Global.get_setting(key) - save_dict("user://settings", saved) - func save_dict(path: String, dict: Dictionary): var f = FileAccess.open(path, FileAccess.WRITE) var to_save = dict.duplicate(true) @@ -130,19 +123,8 @@ func load_dict(path: String, default: Dictionary) -> Dictionary: if saved_dict != null and saved_dict is Dictionary: add_missing_keys(saved_dict, default) - - return saved_dict -func load_settings(path: String): - if FileAccess.file_exists(path): - var f = FileAccess.open(path, FileAccess.READ) - settings = f.get_var(true) - else: - print("No settings file found.") - settings = {} - settings_tree = Settings.get_root() - settings_tree.check() - Settings.apply_initial() + return saved_dict func on_mobile() -> bool: var os_name := OS.get_name() @@ -156,24 +138,6 @@ func on_high_end() -> bool: func on_vulkan() -> bool: return ProjectSettings.get_setting("rendering/rendering_device/driver") == "vulkan" -func get_setting(key: String): - if !settings.has(key): - push_error("Tried to access setting \"%s\", which does not exist (missing key)" % key) - return null - return settings[key] - -func set_setting_unchecked(key: String, value): - value = value.duplicate(true) if value is Array else value - if key in settings and typeof(settings[key]) == typeof(value) and not value is Array and settings[key] == value: return - settings[key] = value - Settings.trigger_hook(key, value) - -func set_setting(key: String, value): - if !settings.has(key): - push_error("Tried to set setting \"%s\", which does not yet exist (missing key)" % key) - return - else: set_setting_unchecked(key, value) - func get_profile(key: String): if profile.has(key): return profile[key] @@ -193,8 +157,8 @@ func set_hint(key: String, value: bool): push_error("Tried to set hint \"%s\", which does not yet exist (missing key)" % key) if profile["hints"][key] != value: if value: - set_setting("gameplay.hints_started", true) - save_settings() + Settings.write("gameplay.hints_started", true) + Settings.save() profile["hints"][key] = value save_profile() # TODO avoid this call when bulk-unsetting hints @@ -256,6 +220,7 @@ func array_has_all(parent: Array, children: Array) -> bool: return false return true +# TODO orphan class ParsedItem: var name: String var contents: Array @@ -280,6 +245,7 @@ func configure_viewport_aa(vp: Viewport, aa: String) -> void: vp.msaa_3d = Viewport.MSAA_4X vp.screen_space_aa = Viewport.SCREEN_SPACE_AA_DISABLED +# TODO orphan static func index_to_hand(i): match i: 0: return "left" |