Changed how modules get their db. No longer embedding AceConsole so I acan register my own Print. Minor bug fixes.
This commit is contained in:
parent
0adbe3fd8c
commit
afe7bdb2a4
14 changed files with 43 additions and 46 deletions
|
@ -1,4 +1,4 @@
|
|||
local core = LibStub("AceAddon-3.0"):NewAddon("AllTheLittleThings", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0")
|
||||
local core = LibStub("AceAddon-3.0"):NewAddon("AllTheLittleThings", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0")
|
||||
local db
|
||||
atlt = core
|
||||
|
||||
|
@ -7,7 +7,7 @@ local defaults = {
|
|||
|
||||
},
|
||||
}
|
||||
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 core:UpdatePins(true) 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
|
||||
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",
|
||||
|
@ -15,20 +15,25 @@ local options = {
|
|||
set = options_setter,
|
||||
get = options_getter,
|
||||
args = {
|
||||
|
||||
},
|
||||
}
|
||||
local databaseCallback = {} -- functions to call when database is ready
|
||||
local slashCallback = {}
|
||||
local slashList = {}
|
||||
|
||||
local prototype = {}
|
||||
local mixins = {
|
||||
"RegisterOptions",
|
||||
"RegisterSlashCommand",
|
||||
"Print",
|
||||
}
|
||||
core:SetDefaultModulePrototype(prototype)
|
||||
core:SetDefaultModuleLibraries("AceConsole-3.0")
|
||||
|
||||
function core:OnInitialize()
|
||||
db = LibStub("AceDB-3.0"):New("AllTheLittleThingsDB", defaults, "Default")
|
||||
self.db = db
|
||||
self:RegisterChatCommand("atlt", "MainSlashHandle")
|
||||
-- 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
|
||||
|
||||
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("AllTheLittleThings", options)
|
||||
local ACD = LibStub("AceConfigDialog-3.0")
|
||||
|
@ -36,14 +41,15 @@ function core:OnInitialize()
|
|||
end
|
||||
|
||||
function core:OnEnable()
|
||||
self.db:RegisterDefaults(defaults)
|
||||
for mod,fn in pairs(databaseCallback) do fn(db[mod]) end
|
||||
end
|
||||
|
||||
function core:OnDisable()
|
||||
end
|
||||
|
||||
-- two registry functions called with self=mod
|
||||
local defaultsTimer
|
||||
function core:RegisterOptions(modOptions, modDefaults)
|
||||
function core:RegisterOptions(modOptions, modDefaults, callback)
|
||||
local name = self:GetName()
|
||||
defaults.profile[name] = modDefaults
|
||||
options.args[name] = {
|
||||
|
@ -52,12 +58,7 @@ function core:RegisterOptions(modOptions, modDefaults)
|
|||
args = modOptions
|
||||
}
|
||||
|
||||
if defaultsTimer then
|
||||
core:CancelTimer(defaultsTimer)
|
||||
end
|
||||
defaultsTimer = core:ScheduleTimer(function()
|
||||
db:RegisterDefaults(defaults)
|
||||
end, 0.01)
|
||||
databaseCallback[name] = callback
|
||||
end
|
||||
|
||||
function core:RegisterSlashCommand(callback, ...)
|
||||
|
@ -67,7 +68,9 @@ function core:RegisterSlashCommand(callback, ...)
|
|||
if slashCallback[slash] then
|
||||
error(("Slash command paramter already registered: '%s'"):format(slash))
|
||||
end
|
||||
slashCallback[slash] = self[callback]
|
||||
slashCallback[slash] = function(...)
|
||||
self[callback](self, ...)
|
||||
end
|
||||
|
||||
if not keyword or slash:len() < keyword:len() then
|
||||
keyword = slash
|
||||
|
@ -92,7 +95,13 @@ function core:MainSlashHandle(msg)
|
|||
end
|
||||
end
|
||||
|
||||
-- fill out our prototype now that our addon's indicies are populated
|
||||
prototype.RegisterOptions = core.RegisterOptions
|
||||
prototype.RegisterSlashCommand = core.RegisterSlashCommand
|
||||
function core:Print(...)
|
||||
LibStub("AceConsole-3.0").Print('atlt', ...)
|
||||
end
|
||||
|
||||
|
||||
-- fill out our prototype now that our addon's indicies are populated
|
||||
for _,method in ipairs(mixins) do
|
||||
prototype[method] = core[method]
|
||||
end
|
||||
|
||||
|
|
|
@ -56,8 +56,7 @@ local armorGlyphs = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterOptions(options, defaults)
|
||||
self:RegisterOptions(options, defaults, function(d) db=d end)
|
||||
end
|
||||
|
||||
function mod:OnEnable()
|
||||
|
|
|
@ -29,8 +29,7 @@ local wgStatus = 0
|
|||
local flagStatus = 0
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterOptions(options, defaults)
|
||||
self:RegisterOptions(options, defaults, function(d) db=d print(d) end)
|
||||
self:RegisterSlashCommand("ArathiPrint", "ab", "arathibasin")
|
||||
end
|
||||
|
||||
|
|
|
@ -13,11 +13,10 @@ local options = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterOptions(options, defaults, function(d) db=d end)
|
||||
-- self:FilterAll("achievement:284")
|
||||
self:FilterAll(nil, "Alabrooke")
|
||||
self:FilterAll(nil, "Warrwarr")
|
||||
|
||||
end
|
||||
|
||||
local chatEvents = {
|
||||
|
@ -87,12 +86,13 @@ local contentFilters = { }
|
|||
local sourceFilters = { }
|
||||
|
||||
function mod:FilterAll(filter, source)
|
||||
if not db.filterOn then return end
|
||||
|
||||
if filter or source then
|
||||
if not next(contentFilters) then
|
||||
-- first time registry
|
||||
for _,v in ipairs(chatEvents) do
|
||||
ChatFrame_AddMessageEventFilter(v, function(self, event, msg, sender)
|
||||
if not db.filterOn then return end
|
||||
if sourceFilters[sender] then
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -15,8 +15,7 @@ local options = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterOptions(options, defaults)
|
||||
self:RegisterOptions(options, defaults, function(d) db=d end)
|
||||
self:RegisterSlashCommand("method", "slsh1", "slash2")
|
||||
end
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ local rosterRaidersCount = 0
|
|||
local rosterRaidersOnline = 0
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterOptions(options, defaults)
|
||||
self:RegisterOptions(options, defaults, function(d) db=d end)
|
||||
end
|
||||
|
||||
function mod:OnEnable()
|
||||
|
|
|
@ -8,8 +8,7 @@ local options = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
-- self:RegisterOptions(options, defaults)
|
||||
-- self:RegisterOptions(options, defaults, function(d) db=d end)
|
||||
self:RegisterSlashCommand("DisbandRaid", "dr", "disbandraid")
|
||||
self:RegisterSlashCommand("InviteGuild", "ig", "inviteguild")
|
||||
self:RegisterSlashCommand("PromoteAll", "pa", "promoteall")
|
||||
|
|
|
@ -38,8 +38,7 @@ local options = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterOptions(options, defaults)
|
||||
self:RegisterOptions(options, defaults, function(d) db=d print(d, db) end)
|
||||
self:RegisterSlashCommand("RollTally", "rt", "rolltally")
|
||||
self:RegisterSlashCommand("FindPhones", "phone")
|
||||
self:RegisterSlashCommand("ActiveTally", "at", "activetally")
|
||||
|
@ -58,7 +57,7 @@ function mod:OnEnable()
|
|||
self:RegisterEvent("CHAT_MSG_SYSTEM")
|
||||
|
||||
-- nix afk
|
||||
ChatFrame_AddMessageEventFilter("CHAT_MSG_AFK", function(...) return self:NixAFK(...); end);
|
||||
ChatFrame_AddMessageEventFilter("CHAT_MSG_AFK", function(...) return self:NixAFK(...) end)
|
||||
|
||||
-- achieve filter
|
||||
self:RawHook("AchievementFrame_LoadUI", true)
|
||||
|
@ -67,7 +66,7 @@ function mod:OnEnable()
|
|||
self:SecureHook("TargetUnit")
|
||||
|
||||
-- filter self targets
|
||||
ChatFrame_AddMessageEventFilter("CHAT_MSG_TARGETICONS", function(_,_,msg) if (msg:find("%["..UnitName("player").."%]")) then return true; end end);
|
||||
ChatFrame_AddMessageEventFilter("CHAT_MSG_TARGETICONS", function(_,_,msg) if (msg:find("%["..UnitName("player").."%]")) then return true end end)
|
||||
|
||||
-- officer phone
|
||||
self:RegisterEvent("CHAT_MSG_OFFICER");
|
||||
|
@ -221,7 +220,7 @@ end
|
|||
|
||||
|
||||
function mod:NixAFK(_, _, ...)
|
||||
return (not not db.nixAFK), ...;
|
||||
return (not not db.nixAFK), ...
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ local potList = {
|
|||
local mailQueue = {} -- used in /atlt pots
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterSlashCommand("AddPotions", "pots")
|
||||
end
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ local options = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
end
|
||||
|
||||
function mod:OnEnable()
|
||||
|
|
|
@ -14,8 +14,7 @@ local options = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterOptions(options, defaults)
|
||||
self:RegisterOptions(options, defaults, function(d) db=d end)
|
||||
end
|
||||
|
||||
function mod:OnEnable()
|
||||
|
|
|
@ -8,7 +8,6 @@ local options = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
end
|
||||
|
||||
function mod:OnEnable()
|
||||
|
|
|
@ -8,7 +8,6 @@ local options = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterOptions(options, defaults)
|
||||
self:RegisterOptions(options, defaults, function(d) db=d end)
|
||||
end
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ local options = {
|
|||
}
|
||||
|
||||
function mod:OnInitialize()
|
||||
db = core.db.profile[self:GetName()] or {}
|
||||
self:RegisterOptions(options, defaults)
|
||||
self:RegisterOptions(options, defaults, function(d) db=d end)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue