# 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_SETTINGS := { "username": "Giovanni", "character": 0, "last_server_url": "" } var settings := DEFAULT_SETTINGS.duplicate(true) var server_url = "" var error_message = "" func _ready(): load_profile() func save_profile(): var f = FileAccess.open("user://profile", FileAccess.WRITE) f.store_var(settings.duplicate(true)) print("Saved settings: ", settings) func load_profile(): # TOCTOU here. Godot docs says its fine. if not FileAccess.file_exists("user://profile"): 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] print("Loaded settings: ", settings)