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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# 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_PROFILE := {
"username": "Giovanni",
"character": 0,
"last_server_url": ""
}
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 = ""
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]
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
|