blob: 83517b2d8f2e963022b89ad11558edad460b2f7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# 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 <https://www.gnu.org/licenses/>.
#
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)
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
|