aboutsummaryrefslogtreecommitdiff
path: root/client/global.gd
blob: a09f869614e2adcfb3e2cf7506bf7643093ee093 (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
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)
	settings = f.get_var()
	
	# Add missing keys
	for k in DEFAULT_SETTINGS.keys():
		if !settings.has(k):
			settings[k] = DEFAULT_SETTINGS[k]
	
	print("Loaded settings: ", settings)