From 2ce769dc68d730944ea9884cabb38eee185a4812 Mon Sep 17 00:00:00 2001 From: mkargus <14226603+mkargus@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:38:45 -0500 Subject: [PATCH] Improved settings typing --- src/Util/Settings.lua | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Util/Settings.lua b/src/Util/Settings.lua index 7a23ec0..b3534fd 100644 --- a/src/Util/Settings.lua +++ b/src/Util/Settings.lua @@ -9,17 +9,19 @@ local DEFAULT_SETTINGS = { } local Settings = {} -Settings._values = DEFAULT_SETTINGS +Settings._values = table.clone(DEFAULT_SETTINGS) Settings._updateListeners = {} -for key, defaultValue in Settings._values do - local savedValue = plugin:GetSetting(key) +if plugin then + for key, defaultValue in Settings._values do + local savedValue = plugin:GetSetting(key) - if savedValue == nil then - Settings._values[key] = defaultValue - plugin:SetSetting(key, defaultValue) - else - Settings._values[key] = savedValue + if savedValue == nil then + Settings._values[key] = defaultValue + plugin:SetSetting(key, defaultValue) + else + Settings._values[key] = savedValue + end end end @@ -33,7 +35,10 @@ end function Settings:Set(key: string, value: any) self._values[key] = value - plugin:SetSetting(key, value) + + if plugin then + plugin:SetSetting(key, value) + end if self._updateListeners[key] then for callback in self._updateListeners[key] do