# Undercooked - a game about cooking # Copyright 2024 metamuffin # Copyright 2024 tpart # Copyright 2024 nokoe # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, version 3 of the License only. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # extends Node const DEFAULT_PROFILE := { "username": "Giovanni", "character": 0, "last_server_url": "" } var default_settings := { "interpolate_camera_rotation": { "value": true, "description": tr("Interpolate the camera rotation") }, "server_binary": { "value": "", "description": tr("Server binary (leave empty to search PATH)") }, "server_data": { "value": "", "description": tr("Server data directory (leave empty to auto-detect)") }, "voxel_gi": { "value": false, "description": tr("Use VoxelGI (Blocks the game on map update)") }, "sdfgi": { "value": false, "description": tr("Use SDFGI (Doesn't block the game but is more resource-hungry)") }, } var profile: Dictionary var settings: Dictionary var server_url = "" var error_message = "" var fade_next := false # Set true when transitioning from another scene (fade in requried) func _ready(): profile = load_dict("user://profile", DEFAULT_PROFILE) settings = load_dict("user://settings", default_settings) func save_profile(): save_dict("user://profile", profile) func save_settings(): save_dict("user://settings", settings) 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(path): print("Skip profile load") 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] else: res[i] = default[i] print("Loaded dict: ", res) return res func on_vulkan() -> bool: return ProjectSettings.get_setting("rendering/rendering_device/driver") == "vulkan" 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