diff options
Diffstat (limited to 'client/global.gd')
-rw-r--r-- | client/global.gd | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/client/global.gd b/client/global.gd index 095deec8..6e12d0cf 100644 --- a/client/global.gd +++ b/client/global.gd @@ -17,36 +17,65 @@ # extends Node -const DEFAULT_SETTINGS := { +const DEFAULT_PROFILE := { "username": "Giovanni", "character": 0, "last_server_url": "" } -var settings := DEFAULT_SETTINGS.duplicate(true) +var default_settings := { + "interpolate_camera_rotation": { + "value": true, + "description": tr("Interpolate the camera rotation") + }, + "test": { + "value": "hehe", + "description": tr("Just a test value") + }, +} + +var profile: Dictionary +var settings: Dictionary var server_url = "" var error_message = "" func _ready(): - load_profile() + profile = load_dict("user://profile", DEFAULT_PROFILE) + settings = load_dict("user://settings", default_settings) func save_profile(): - var f = FileAccess.open("user://profile", FileAccess.WRITE) - f.store_var(settings.duplicate(true)) + save_dict("user://profile", profile) - print("Saved settings: ", settings) +func save_settings(): + save_dict("user://settings", settings) -func load_profile(): +func save_dict(path: String, dict: Dictionary): + var f = FileAccess.open(path, FileAccess.WRITE) + f.store_var(dict.duplicate(true)) + +func load_dict(path: String, default: Dictionary) -> Dictionary: # TOCTOU here. Godot docs says its fine. - if not FileAccess.file_exists("user://profile"): + if not FileAccess.file_exists(path): print("Skip profile load") - return - var f = FileAccess.open("user://profile", FileAccess.READ) - var saved_settings = f.get_var() - if saved_settings != null and saved_settings is Dictionary: - for i in DEFAULT_SETTINGS.keys(): - if saved_settings.has(i): - settings[i] = saved_settings[i] + return default + var f = FileAccess.open(path, FileAccess.READ) + var saved_dict = f.get_var() + var res: Dictionary = {} + if saved_dict != null and saved_dict is Dictionary: + for i in default.keys(): + if saved_dict.has(i): + res[i] = saved_dict[i] + + print("Loaded dict: ", res) + return res - print("Loaded settings: ", settings) +func focus_first_button(node: Node) -> bool: + if node is Button: + node.grab_focus() + print("Node %s (%s) was selected for focus" % [node.name, node]) + return true + for c in node.get_children(): + if focus_first_button(c): + return true + return false |