2011-05-31 02:40:36 -04:00
|
|
|
local core = LibStub("AceAddon-3.0"):NewAddon("AllTheLittleThings", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0")
|
2011-05-30 18:53:33 -04:00
|
|
|
local db
|
2011-05-30 13:01:19 -04:00
|
|
|
atlt = core
|
|
|
|
|
|
|
|
local defaults = {
|
|
|
|
profile = {
|
2011-05-31 03:26:46 -04:00
|
|
|
enabled = { },
|
|
|
|
modules = { },
|
2011-05-30 13:01:19 -04:00
|
|
|
},
|
|
|
|
}
|
2011-05-31 02:40:36 -04:00
|
|
|
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
|
2011-05-30 13:01:19 -04:00
|
|
|
local options_getter = function(info) local t=core.db.profile for k=1,#info-1 do t=t[info[k]] end return t[info[#info]] end
|
|
|
|
local options = {
|
|
|
|
name = "AllTheLittleThings",
|
|
|
|
type = 'group',
|
|
|
|
set = options_setter,
|
|
|
|
get = options_getter,
|
|
|
|
args = {
|
2011-05-31 03:26:46 -04:00
|
|
|
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 = { },
|
|
|
|
},
|
2011-05-30 13:01:19 -04:00
|
|
|
},
|
|
|
|
}
|
2011-05-31 02:40:36 -04:00
|
|
|
local databaseCallback = {} -- functions to call when database is ready
|
2011-05-30 14:57:41 -04:00
|
|
|
local slashCallback = {}
|
2011-05-30 18:13:08 -04:00
|
|
|
local slashList = {}
|
|
|
|
|
|
|
|
local prototype = {}
|
2011-05-31 02:40:36 -04:00
|
|
|
local mixins = {
|
|
|
|
"RegisterOptions",
|
|
|
|
"RegisterSlashCommand",
|
|
|
|
"Print",
|
|
|
|
}
|
2011-05-30 18:13:08 -04:00
|
|
|
core:SetDefaultModulePrototype(prototype)
|
2011-05-30 13:01:19 -04:00
|
|
|
|
|
|
|
function core:OnInitialize()
|
2011-05-31 04:01:50 -04:00
|
|
|
-- Get basic information about modules
|
|
|
|
for name, mod in self:IterateModules() do
|
|
|
|
defaults.profile.enabled[name] = true
|
|
|
|
options.args.enabled.args[name] = {
|
|
|
|
name = name,
|
|
|
|
type = 'toggle',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2011-05-31 02:40:36 -04:00
|
|
|
-- Not embedding AceConsole-3.0 so that we can have our own :Print()
|
|
|
|
LibStub("AceConsole-3.0").RegisterChatCommand(self, "atlt", "MainSlashHandle")
|
|
|
|
self.db = LibStub("AceDB-3.0"):New("AllTheLittleThingsDB", defaults, "Default")
|
|
|
|
db = self.db.profile
|
2011-05-31 04:01:50 -04:00
|
|
|
|
|
|
|
-- Now that we have our SavedVars, we can toggle modules
|
|
|
|
for name, mod in self:IterateModules() do
|
|
|
|
mod:SetEnabledState(db.enabled[name])
|
|
|
|
end
|
2011-05-30 13:01:19 -04:00
|
|
|
|
2011-05-31 04:01:50 -04:00
|
|
|
-- Generate our options and add them to Blizzard Interface
|
2011-05-30 18:13:08 -04:00
|
|
|
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("AllTheLittleThings", options)
|
|
|
|
local ACD = LibStub("AceConfigDialog-3.0")
|
|
|
|
ACD:AddToBlizOptions("AllTheLittleThings", "AllTheLittleThings")
|
2011-05-30 13:01:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:OnEnable()
|
2011-05-31 02:40:36 -04:00
|
|
|
self.db:RegisterDefaults(defaults)
|
2011-06-04 03:13:27 -04:00
|
|
|
for mod,fn in pairs(databaseCallback) do
|
|
|
|
xpcall(function()
|
|
|
|
fn(db.modules[mod])
|
|
|
|
end, geterrorhandler())
|
|
|
|
end
|
2011-05-30 13:01:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:OnDisable()
|
|
|
|
end
|
|
|
|
|
2011-05-31 03:26:46 -04:00
|
|
|
function core:SetModule(name, status)
|
|
|
|
local mod = self:GetModule(name)
|
|
|
|
if mod then
|
|
|
|
if status then
|
|
|
|
mod:Enable()
|
|
|
|
else
|
|
|
|
mod:Disable()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-30 14:57:41 -04:00
|
|
|
-- two registry functions called with self=mod
|
2011-05-31 02:40:36 -04:00
|
|
|
function core:RegisterOptions(modOptions, modDefaults, callback)
|
2011-05-30 14:57:41 -04:00
|
|
|
local name = self:GetName()
|
2011-05-31 03:26:46 -04:00
|
|
|
defaults.profile.modules[name] = modDefaults
|
|
|
|
options.args.modules.args[name] = {
|
2011-05-30 13:01:19 -04:00
|
|
|
name = name,
|
|
|
|
type = 'group',
|
2011-05-30 18:13:08 -04:00
|
|
|
args = modOptions
|
2011-05-30 13:01:19 -04:00
|
|
|
}
|
2011-05-30 18:53:33 -04:00
|
|
|
|
2011-05-31 02:40:36 -04:00
|
|
|
databaseCallback[name] = callback
|
2011-05-30 13:01:19 -04:00
|
|
|
end
|
|
|
|
|
2011-05-30 14:57:41 -04:00
|
|
|
function core:RegisterSlashCommand(callback, ...)
|
2011-05-30 19:07:01 -04:00
|
|
|
local keyword
|
2011-05-30 14:57:41 -04:00
|
|
|
for i=1,select('#', ...) do
|
2011-05-30 18:13:08 -04:00
|
|
|
local slash = select(i, ...)
|
2011-05-30 19:07:01 -04:00
|
|
|
if slashCallback[slash] then
|
|
|
|
error(("Slash command paramter already registered: '%s'"):format(slash))
|
|
|
|
end
|
2011-05-31 02:40:36 -04:00
|
|
|
slashCallback[slash] = function(...)
|
|
|
|
self[callback](self, ...)
|
|
|
|
end
|
2011-05-30 19:07:01 -04:00
|
|
|
|
|
|
|
if not keyword or slash:len() < keyword:len() then
|
|
|
|
keyword = slash
|
|
|
|
end
|
2011-05-30 14:57:41 -04:00
|
|
|
end
|
2011-05-30 18:13:08 -04:00
|
|
|
|
2011-05-30 19:07:01 -04:00
|
|
|
slashList[("|cff33ff99%s|r:|cffcc7833%s()|r"):format(self:GetName(), callback)] = keyword
|
2011-05-30 14:57:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:MainSlashHandle(msg)
|
2011-05-30 18:53:33 -04:00
|
|
|
local _, e, command = msg:find("(%S+)")
|
2011-05-30 14:57:41 -04:00
|
|
|
|
|
|
|
if command and slashCallback[command] then
|
2011-05-30 18:53:33 -04:00
|
|
|
msg = msg:sub(e+1)
|
2011-05-30 14:57:41 -04:00
|
|
|
slashCallback[command](msg)
|
|
|
|
else
|
|
|
|
-- print all commands
|
2011-05-30 18:53:33 -04:00
|
|
|
print("|cff33ff99AllTheLittleThings|r available commands:")
|
|
|
|
for cmd,call in pairs(slashList) do
|
|
|
|
print((" %s - %s"):format(cmd, call))
|
|
|
|
end
|
2011-05-30 14:57:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-31 02:40:36 -04:00
|
|
|
function core:Print(...)
|
|
|
|
LibStub("AceConsole-3.0").Print('atlt', ...)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-05-30 18:13:08 -04:00
|
|
|
-- fill out our prototype now that our addon's indicies are populated
|
2011-05-31 02:40:36 -04:00
|
|
|
for _,method in ipairs(mixins) do
|
|
|
|
prototype[method] = core[method]
|
|
|
|
end
|
2011-05-30 18:13:08 -04:00
|
|
|
|