aboutsummaryrefslogtreecommitdiff
path: root/client/global.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/global.gd')
-rw-r--r--client/global.gd26
1 files changed, 25 insertions, 1 deletions
diff --git a/client/global.gd b/client/global.gd
index c75d12f3..02989b19 100644
--- a/client/global.gd
+++ b/client/global.gd
@@ -1,5 +1,29 @@
extends Node
var server_url = ""
-var character = 1
var error_message = ""
+
+var character = 1
+var username = "Giovanni"
+
+func _ready():
+ load_profile()
+
+func save_profile():
+ print("Save profile")
+ var f = FileAccess.open("user://profile", FileAccess.WRITE)
+ f.store_line(JSON.stringify({
+ "username": username,
+ "character": character
+ }))
+
+func load_profile():
+ # TOCTOU here. Godot docs says its fine.
+ if not FileAccess.file_exists("user://profile"):
+ print("Skip profile load")
+ return
+ print("Load profile")
+ var f = FileAccess.open("user://profile", FileAccess.READ)
+ var ob = JSON.parse_string(f.get_line())
+ username = ob["username"]
+ character = ob["character"]