aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/game.gd2
-rw-r--r--client/global.gd24
-rw-r--r--client/menu/character_menu.gd17
3 files changed, 24 insertions, 19 deletions
diff --git a/client/game.gd b/client/game.gd
index 16522706..3ee960f7 100644
--- a/client/game.gd
+++ b/client/game.gd
@@ -154,7 +154,7 @@ func _ready():
p.bubble.set_text(item_names[item])
)
- mp.send_join(Global.username, Global.character)
+ mp.send_join(Global.settings["username"], Global.settings["character"])
func _process(delta):
marker.position = lerp(marker.position, marker_target, delta * 40.0)
diff --git a/client/global.gd b/client/global.gd
index 02989b19..6d4cf4fc 100644
--- a/client/global.gd
+++ b/client/global.gd
@@ -1,21 +1,22 @@
extends Node
+const DEFAULT_SETTINGS := {
+ "username": "Giovanni",
+ "character": 0
+}
+
+var settings := DEFAULT_SETTINGS.duplicate(true)
+
var server_url = ""
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
- }))
+ f.store_line(JSON.stringify(settings))
func load_profile():
# TOCTOU here. Godot docs says its fine.
@@ -24,6 +25,9 @@ func load_profile():
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"]
+ settings = JSON.parse_string(f.get_line())
+
+ # Add missing keys
+ for k in DEFAULT_SETTINGS.keys():
+ if !settings.has(k):
+ settings[k] = DEFAULT_SETTINGS[k]
diff --git a/client/menu/character_menu.gd b/client/menu/character_menu.gd
index e63243e1..90bc9648 100644
--- a/client/menu/character_menu.gd
+++ b/client/menu/character_menu.gd
@@ -18,10 +18,9 @@ extends Control
@onready var character: Character = $Character
@onready var num_hairstyles := character.hairstyles.keys().size()
-var hairstyle := 0
-
func _ready():
- $VBoxContainer/top_panel/a/username.text = Global.username
+ $VBoxContainer/top_panel/a/username.text = Global.settings["username"]
+ character.select_hairstyle(Global.settings["character"])
func _notification(what):
if what == NOTIFICATION_PREDELETE:
@@ -31,12 +30,14 @@ func _on_back_pressed():
$SceneTransition.transition_to("res://menu/main_menu.tscn")
func _on_username_text_changed(new_text):
- Global.username = new_text
+ Global.settings["username"] = new_text
func _on_character_back_pressed():
- hairstyle = (hairstyle - 1) % num_hairstyles
- character.select_hairstyle(hairstyle)
+ Global.settings["character"] = (Global.settings["character"] - 1) % num_hairstyles
+ character.select_hairstyle(Global.settings["character"])
+ Global.save_profile()
func _on_character_forward_pressed():
- hairstyle = (hairstyle + 1) % num_hairstyles
- character.select_hairstyle(hairstyle)
+ Global.settings["character"] = (Global.settings["character"] + 1) % num_hairstyles
+ character.select_hairstyle(Global.settings["character"])
+ Global.save_profile()