refactor: replace table.foreach with recursive deep copy functions for config defaults

This commit is contained in:
Bluewhale1337
2026-09-08 20:32:36 +02:00
parent 03114d4802
commit 604a26dbb3
2 changed files with 22 additions and 13 deletions
+10 -9
View File
@@ -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
View File
@@ -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();