aboutsummaryrefslogtreecommitdiff
path: root/client/settings.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/settings.gd')
-rw-r--r--client/settings.gd50
1 files changed, 41 insertions, 9 deletions
diff --git a/client/settings.gd b/client/settings.gd
index fa400821..8381ddc2 100644
--- a/client/settings.gd
+++ b/client/settings.gd
@@ -82,9 +82,46 @@ static func get_root():
])
])
+static var tree: GameSetting
+static var values: Dictionary = {}
+static var loaded_path: String
+
+static func read(key: String):
+ if !values.has(key):
+ push_error("Tried to access setting \"%s\", which does not exist (missing key)" % key)
+ return null
+ return values[key]
+
+static func write_unchecked(key: String, value):
+ value = value.duplicate(true) if value is Array else value
+ if key in values and typeof(values[key]) == typeof(value) and not value is Array and values[key] == value: return
+ values[key] = value
+ trigger_hook(key, value)
+
+static func write(key: String, value):
+ if !values.has(key):
+ push_error("Tried to set setting \"%s\", which does not yet exist (missing key)" % key)
+ return
+ else: write_unchecked(key, value)
+
+static func load(path: String):
+ tree = get_root()
+ loaded_path = path
+ var changed = {}
+ if FileAccess.file_exists(path):
+ var f = FileAccess.open(path, FileAccess.READ)
+ changed = JSON.parse_string(f.get_as_text())
+ tree.load(changed)
+
+static func save():
+ var changed = {}
+ tree.save(changed)
+ var f = FileAccess.open(loaded_path, FileAccess.WRITE)
+ f.store_string(JSON.stringify(changed))
+
static func trigger_hook(key: String, value):
- if Settings.change_hooks_display.get(key) != null: Settings.change_hooks_display.get(key).callv([value] if value != null else [])
- if Settings.change_hooks_apply.get(key) != null: Settings.change_hooks_apply.get(key).callv([value] if value != null else [])
+ if change_hooks_display.get(key) != null: change_hooks_display.get(key).callv([value] if value != null else [])
+ if change_hooks_apply.get(key) != null: change_hooks_apply.get(key).callv([value] if value != null else [])
if key.find(".") != -1: trigger_hook(key.rsplit(".", false, 1)[0], null)
static func hook_changed(key: String, display: bool, callable: Callable):
@@ -93,14 +130,14 @@ static func hook_changed(key: String, display: bool, callable: Callable):
static func hook_changed_init(key: String, display: bool, callable: Callable):
hook_changed(key, display, callable)
- callable.call(Global.get_setting(key))
+ callable.call(read(key))
static func get_category_dict(prefix: String):
var map = {}
for k in Global.settings.keys():
var kn = k.trim_prefix(prefix + ".")
if kn == k: continue
- map[kn] = Global.get_setting(k)
+ map[kn] = read(k)
return map
static func launch_setup():
@@ -121,11 +158,6 @@ static var change_hooks_apply = {
"audio.sfx_volume": h_volume_sfx,
}
-static func apply_initial():
- for key in change_hooks_apply.keys():
- if Global.settings.has(key): change_hooks_apply[key].call(Global.get_setting(key))
- else: change_hooks_apply[key].call()
-
static func h_aa(mode):
var vp = Global.get_viewport()
Global.configure_viewport_aa(vp, mode)