Skip to content

Commit

Permalink
Improved settings typing
Browse files Browse the repository at this point in the history
  • Loading branch information
mkargus committed Dec 16, 2024
1 parent 70c8731 commit 2ce769d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Util/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 2ce769d

Please sign in to comment.