diff options
| author | nokoe <nokoe@mailbox.org> | 2024-06-26 16:34:55 +0200 | 
|---|---|---|
| committer | nokoe <nokoe@mailbox.org> | 2024-06-26 16:34:55 +0200 | 
| commit | 5654b69e4c7e0aafe258ad0ab73105722a389def (patch) | |
| tree | 7e51e306380cd08219a96d4e21db32869e9b9eab /client/global.gd | |
| parent | 974d5151b28faf94dfa73e33a484eecaa2f69e40 (diff) | |
| download | hurrycurry-5654b69e4c7e0aafe258ad0ab73105722a389def.tar hurrycurry-5654b69e4c7e0aafe258ad0ab73105722a389def.tar.bz2 hurrycurry-5654b69e4c7e0aafe258ad0ab73105722a389def.tar.zst | |
add settings row
Diffstat (limited to 'client/global.gd')
| -rw-r--r-- | client/global.gd | 51 | 
1 files changed, 35 insertions, 16 deletions
| diff --git a/client/global.gd b/client/global.gd index 095deec8..be230890 100644 --- a/client/global.gd +++ b/client/global.gd @@ -17,36 +17,55 @@  #  extends Node -const DEFAULT_SETTINGS := { +const DEFAULT_PROFILE := {  	"username": "Giovanni",  	"character": 0,  	"last_server_url": ""  } -var settings := DEFAULT_SETTINGS.duplicate(true) +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 = ""  func _ready(): -	load_profile() +	profile = load_dict("user://profile", DEFAULT_PROFILE) +	settings = load_dict("user://settings", default_settings)  func save_profile(): -	var f = FileAccess.open("user://profile", FileAccess.WRITE) -	f.store_var(settings.duplicate(true)) +	save_dict("user://profile", profile) + +func save_settings(): +	save_dict("user://settings", settings) -	print("Saved settings: ", settings) +func save_dict(path: String, dict: Dictionary): +	var f = FileAccess.open(path, FileAccess.WRITE) +	f.store_var(dict.duplicate(true)) -func load_profile(): +func load_dict(path: String, default: Dictionary) -> Dictionary:  	# TOCTOU here. Godot docs says its fine. -	if not FileAccess.file_exists("user://profile"): +	if not FileAccess.file_exists(path):  		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] +		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 settings: ", settings) +	print("Loaded dict: ", res) +	return res | 
