mirror of
https://github.com/Bluewhale1337/HealBotBlue.git
synced 2026-09-10 09:20:21 +00:00
refactor: replace table.foreach with recursive deep copy functions for config defaults
This commit is contained in:
@@ -350,18 +350,19 @@ end
|
||||
function HealBot_OnEvent_VariablesLoaded(this)
|
||||
local class = HealBot_UnitClass("player")
|
||||
|
||||
table.foreach(HealBot_ConfigDefaults, function (key, val)
|
||||
if not HealBot_Config[key] then
|
||||
HealBot_Config[key] = val;
|
||||
end
|
||||
if type(val) == "table" and type(HealBot_Config[key]) == "table" then
|
||||
for k, v in pairs(val) do
|
||||
if HealBot_Config[key][k] == nil then
|
||||
HealBot_Config[key][k] = v
|
||||
local function DeepCopyMissing(src, dest)
|
||||
for k, v in pairs(src) do
|
||||
if type(v) == "table" then
|
||||
if type(dest[k]) ~= "table" then dest[k] = {} end
|
||||
DeepCopyMissing(v, dest[k])
|
||||
else
|
||||
if dest[k] == nil then
|
||||
dest[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
end);
|
||||
end
|
||||
DeepCopyMissing(HealBot_ConfigDefaults, HealBot_Config)
|
||||
|
||||
local foundModern = false
|
||||
if HealBot_Config.Skins then
|
||||
|
||||
+12
-4
@@ -234,10 +234,18 @@ end
|
||||
-- HealBot_Options_Defaults_OnClick: UI handler for OnClick options panel.
|
||||
function HealBot_Options_Defaults_OnClick(this)
|
||||
HealBot_Options_CastNotify_OnClick(nil,0);
|
||||
-- HealBot_Config = HealBot_ConfigDefaults;
|
||||
table.foreach(HealBot_ConfigDefaults, function (key,val)
|
||||
HealBot_Config[key] = val;
|
||||
end);
|
||||
HealBot_Config = {}
|
||||
local function DeepCopy(src, dest)
|
||||
for k, v in pairs(src) do
|
||||
if type(v) == "table" then
|
||||
dest[k] = {}
|
||||
DeepCopy(v, dest[k])
|
||||
else
|
||||
dest[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
DeepCopy(HealBot_ConfigDefaults, HealBot_Config)
|
||||
HealBot_Options_OnShow(HealBot_Options);
|
||||
HealBot_RecalcSpells();
|
||||
HealBot_Action_Reset();
|
||||
|
||||
Reference in New Issue
Block a user