From afe7bdb2a44321c72cb879d245c4bb40c1f968ee Mon Sep 17 00:00:00 2001 From: pigmonkey Date: Tue, 31 May 2011 02:40:36 -0400 Subject: [PATCH] Changed how modules get their db. No longer embedding AceConsole so I acan register my own Print. Minor bug fixes. --- AllTheLittleThings.lua | 47 +++++++++++++++++++++++---------------- modules/announce.lua | 3 +-- modules/battlegrounds.lua | 3 +-- modules/chatfilter.lua | 6 ++--- modules/deprecated.lua | 3 +-- modules/guildroster.lua | 3 +-- modules/macros.lua | 3 +-- modules/miscellaneous.lua | 9 ++++---- modules/potions.lua | 1 - modules/prat.lua | 1 - modules/raid.lua | 3 +-- modules/rbs.lua | 1 - modules/staging.lua | 3 +-- modules/template.lua | 3 +-- 14 files changed, 43 insertions(+), 46 deletions(-) diff --git a/AllTheLittleThings.lua b/AllTheLittleThings.lua index 1ab9ca6..e5cf692 100644 --- a/AllTheLittleThings.lua +++ b/AllTheLittleThings.lua @@ -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 diff --git a/modules/announce.lua b/modules/announce.lua index d8ace0e..a337078 100644 --- a/modules/announce.lua +++ b/modules/announce.lua @@ -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() diff --git a/modules/battlegrounds.lua b/modules/battlegrounds.lua index 8d0e5d0..26ca8cc 100644 --- a/modules/battlegrounds.lua +++ b/modules/battlegrounds.lua @@ -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 diff --git a/modules/chatfilter.lua b/modules/chatfilter.lua index 23e1df3..f1e0f7a 100644 --- a/modules/chatfilter.lua +++ b/modules/chatfilter.lua @@ -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 diff --git a/modules/deprecated.lua b/modules/deprecated.lua index d5f2a2a..957b4c8 100644 --- a/modules/deprecated.lua +++ b/modules/deprecated.lua @@ -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 diff --git a/modules/guildroster.lua b/modules/guildroster.lua index 5fda936..d08dfa3 100644 --- a/modules/guildroster.lua +++ b/modules/guildroster.lua @@ -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() diff --git a/modules/macros.lua b/modules/macros.lua index 14ade24..7bd7458 100644 --- a/modules/macros.lua +++ b/modules/macros.lua @@ -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") diff --git a/modules/miscellaneous.lua b/modules/miscellaneous.lua index 696820c..3de64b4 100644 --- a/modules/miscellaneous.lua +++ b/modules/miscellaneous.lua @@ -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 diff --git a/modules/potions.lua b/modules/potions.lua index b03f66d..f3a02f5 100644 --- a/modules/potions.lua +++ b/modules/potions.lua @@ -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 diff --git a/modules/prat.lua b/modules/prat.lua index 94765a4..598a4bb 100644 --- a/modules/prat.lua +++ b/modules/prat.lua @@ -8,7 +8,6 @@ local options = { } function mod:OnInitialize() - db = core.db.profile[self:GetName()] or {} end function mod:OnEnable() diff --git a/modules/raid.lua b/modules/raid.lua index 0331d8b..115e867 100644 --- a/modules/raid.lua +++ b/modules/raid.lua @@ -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() diff --git a/modules/rbs.lua b/modules/rbs.lua index 135ffcf..1e80568 100644 --- a/modules/rbs.lua +++ b/modules/rbs.lua @@ -8,7 +8,6 @@ local options = { } function mod:OnInitialize() - db = core.db.profile[self:GetName()] or {} end function mod:OnEnable() diff --git a/modules/staging.lua b/modules/staging.lua index 6978059..fdc1560 100644 --- a/modules/staging.lua +++ b/modules/staging.lua @@ -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 diff --git a/modules/template.lua b/modules/template.lua index 6978059..fdc1560 100644 --- a/modules/template.lua +++ b/modules/template.lua @@ -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