Skip to content

Commit

Permalink
Fix settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghostopheles committed Jul 25, 2024
1 parent d24e1a9 commit 3c7ff52
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions Datamine/Settings/SettingsCore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,32 @@ local defaultConfig = {

local allSettings = {};

local mt = {
__index = function(t, k)
if DatamineConfig then
return DatamineConfig[k];
end
end,
__newindex = function(t, k, v)
if DatamineConfig then
DatamineConfig[k] = v;
else
rawset(t, k, v);
end
end
};
local middleman = {};
setmetatable(middleman, mt);

local function InitSavedVariables()
if not DatamineConfig then
DatamineConfig = CopyTable(defaultConfig);
end

for name, setting in pairs(allSettings) do
local var = DatamineConfig[name];

if var == nil then
DatamineConfig[name] = setting:GetValue();
else
setting:SetValue(DatamineConfig[name]);
end
for k, v in pairs(middleman) do
DatamineConfig[k] = v;
wipe(middleman);
setmetatable(middleman, mt);
end

Datamine.Constants.ChatPrefixColor = CreateColorFromHexString(DatamineConfig.ChatPrefixColor);
Expand All @@ -62,7 +75,7 @@ local function CreateCVarSetting(category, name, variable, defaultValue)
local variableType = type(defaultValue);
local setting;
if IS_FUTURE then
setting = Settings.RegisterAddOnSetting(category, variable, variable, DatamineConfig, variableType, name, defaultValue);
setting = Settings.RegisterAddOnSetting(category, name, variable, variable, middleman, variableType, defaultValue);
else
setting = Settings.RegisterAddOnSetting(category, name, variable, variableType, defaultValue);
end
Expand Down Expand Up @@ -124,7 +137,7 @@ local function RegisterSetting(category, variable, name, defaultValue)

local setting;
if IS_FUTURE then
setting = Settings.RegisterAddOnSetting(category, variable, variable, DatamineConfig, variableType, name, defaultValue);
setting = Settings.RegisterAddOnSetting(category, name, variable, variable, middleman, variableType, defaultValue);
else
setting = Settings.RegisterAddOnSetting(category, name, variable, variableType, defaultValue);
end
Expand Down

0 comments on commit 3c7ff52

Please sign in to comment.