1
0
Fork 0

Added entire module toggling and separated options/defaults from module specific data

This commit is contained in:
pigmonkey 2011-05-31 03:26:46 -04:00
parent afe7bdb2a4
commit 84c06d47c7

View file

@ -4,7 +4,8 @@ atlt = core
local defaults = { local defaults = {
profile = { profile = {
enabled = { },
modules = { },
}, },
} }
local options_setter = function(info, v) local t=core.db.profile for k=1,#info-1 do t=t[info[k]] end t[info[#info]]=v end local options_setter = function(info, v) local t=core.db.profile for k=1,#info-1 do t=t[info[k]] end t[info[#info]]=v end
@ -15,6 +16,19 @@ local options = {
set = options_setter, set = options_setter,
get = options_getter, get = options_getter,
args = { args = {
enabled = {
name = "Toggle Modules",
type = 'group',
order = 10,
args = { },
set = function(info, v) options_setter(info, v) core:SetModule(info[#info], v) end,
},
modules = {
name = "Module Options",
type = 'group',
order = 20,
args = { },
},
}, },
} }
local databaseCallback = {} -- functions to call when database is ready local databaseCallback = {} -- functions to call when database is ready
@ -42,17 +56,40 @@ end
function core:OnEnable() function core:OnEnable()
self.db:RegisterDefaults(defaults) self.db:RegisterDefaults(defaults)
for mod,fn in pairs(databaseCallback) do fn(db[mod]) end for mod,fn in pairs(databaseCallback) do print(mod) fn(db.modules[mod]) end
for name, mod in self:IterateModules() do
if db.enabled[name] then
mod:Enable()
else
mod:Disable()
end
end
end end
function core:OnDisable() function core:OnDisable()
end end
function core:SetModule(name, status)
local mod = self:GetModule(name)
if mod then
if status then
mod:Enable()
else
mod:Disable()
end
end
end
-- two registry functions called with self=mod -- two registry functions called with self=mod
function core:RegisterOptions(modOptions, modDefaults, callback) function core:RegisterOptions(modOptions, modDefaults, callback)
local name = self:GetName() local name = self:GetName()
defaults.profile[name] = modDefaults defaults.profile.enabled[name] = true
options.args[name] = { defaults.profile.modules[name] = modDefaults
options.args.enabled.args[name] = {
name = name,
type = 'toggle',
}
options.args.modules.args[name] = {
name = name, name = name,
type = 'group', type = 'group',
args = modOptions args = modOptions