aboutsummaryrefslogtreecommitdiff
path: root/client/global.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/global.gd')
-rw-r--r--client/global.gd69
1 files changed, 59 insertions, 10 deletions
diff --git a/client/global.gd b/client/global.gd
index f25845a6..35244fa7 100644
--- a/client/global.gd
+++ b/client/global.gd
@@ -17,6 +17,15 @@
#
extends Node
+# Each setting contains a dictionary with the following keys:
+# "type": The type of the setting. Can be "toggle", "line", "dropdown", or "dropdown_preset"
+# "value": The value of the setting. When using "dropdown", this contains an int
+# as the index for the respecitve element in the "options" array.
+# "apply": Only for type "dropdown_preset": A dictionary to override all other settings.
+# "description": The setting name displayed in the settings menu.
+# (Optional: Only when type = "dropdown") "options": An array which contains all
+# possible values.
+
const DEFAULT_PROFILE := {
"username": "Giovanni",
"character": 0,
@@ -25,27 +34,62 @@ const DEFAULT_PROFILE := {
var default_settings := {
"interpolate_camera_rotation": {
+ "type": "toggle",
"value": true,
"description": tr("Interpolate the camera rotation")
},
"server_binary": {
+ "type": "line",
"value": "",
"description": tr("Server binary (leave empty to search PATH)")
},
"server_data": {
+ "type": "line",
"value": "",
"description": tr("Server data directory (leave empty to auto-detect)")
},
+ "graphics_preset": {
+ "type": "dropdown_preset",
+ "options": [tr("Low"), tr("Medium"), tr("High"), tr("Ultra")],
+ "value":1,
+ "description": tr("Graphics preset"),
+ "apply": GRAPHICS_PRESETS
+ },
"voxel_gi": {
+ "type": "toggle",
"value": false,
"description": tr("Use VoxelGI (Blocks the game on map update)")
},
"sdfgi": {
+ "type": "toggle",
"value": false,
"description": tr("Use SDFGI (Doesn't block the game but is more resource-hungry)")
- },
+ }
}
+const GRAPHICS_PRESETS = [
+ # Low:
+ {
+ "voxel_gi": false,
+ "sdfgi": false
+ },
+ # Medium:
+ {
+ "voxel_gi": false,
+ "sdfgi": false
+ },
+ # High:
+ {
+ "voxel_gi": false,
+ "sdfgi": true
+ },
+ # Ultra:
+ {
+ "voxel_gi": true,
+ "sdfgi": false
+ }
+]
+
var profile: Dictionary
var settings: Dictionary
@@ -54,9 +98,10 @@ var error_message = ""
var fade_next := false # Set true when transitioning from another scene (fade in requried)
-func _ready():
+func _init():
profile = load_dict("user://profile", DEFAULT_PROFILE)
settings = load_dict("user://settings", default_settings)
+ print("DONE LOADING")
func save_profile():
save_dict("user://profile", profile)
@@ -75,16 +120,12 @@ func load_dict(path: String, default: Dictionary) -> Dictionary:
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]
- else:
- res[i] = default[i]
+ add_missing_keys(saved_dict, default)
- print("Loaded dict: ", res)
- return res
+ print("Loaded dict: ", saved_dict)
+ return saved_dict
func on_vulkan() -> bool:
return ProjectSettings.get_setting("rendering/rendering_device/driver") == "vulkan"
@@ -98,3 +139,11 @@ func focus_first_button(node: Node) -> bool:
if focus_first_button(c):
return true
return false
+
+func add_missing_keys(dict: Dictionary, reference: Dictionary):
+ for k in reference.keys():
+ if !dict.has(k):
+ dict[k] = reference
+ else:
+ if dict[k] is Dictionary:
+ add_missing_keys(dict[k], reference[k])