1
0
Fork 0

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:
pigmonkey 2011-05-31 02:40:36 -04:00
parent 0adbe3fd8c
commit afe7bdb2a4
14 changed files with 43 additions and 46 deletions

View file

@ -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 local db
atlt = core 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_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 = { local options = {
name = "AllTheLittleThings", name = "AllTheLittleThings",
@ -15,20 +15,25 @@ local options = {
set = options_setter, set = options_setter,
get = options_getter, get = options_getter,
args = { args = {
}, },
} }
local databaseCallback = {} -- functions to call when database is ready
local slashCallback = {} local slashCallback = {}
local slashList = {} local slashList = {}
local prototype = {} local prototype = {}
local mixins = {
"RegisterOptions",
"RegisterSlashCommand",
"Print",
}
core:SetDefaultModulePrototype(prototype) core:SetDefaultModulePrototype(prototype)
core:SetDefaultModuleLibraries("AceConsole-3.0")
function core:OnInitialize() function core:OnInitialize()
db = LibStub("AceDB-3.0"):New("AllTheLittleThingsDB", defaults, "Default") -- Not embedding AceConsole-3.0 so that we can have our own :Print()
self.db = db LibStub("AceConsole-3.0").RegisterChatCommand(self, "atlt", "MainSlashHandle")
self:RegisterChatCommand("atlt", "MainSlashHandle") self.db = LibStub("AceDB-3.0"):New("AllTheLittleThingsDB", defaults, "Default")
db = self.db.profile
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("AllTheLittleThings", options) LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("AllTheLittleThings", options)
local ACD = LibStub("AceConfigDialog-3.0") local ACD = LibStub("AceConfigDialog-3.0")
@ -36,14 +41,15 @@ function core:OnInitialize()
end end
function core:OnEnable() function core:OnEnable()
self.db:RegisterDefaults(defaults)
for mod,fn in pairs(databaseCallback) do fn(db[mod]) end
end end
function core:OnDisable() function core:OnDisable()
end end
-- two registry functions called with self=mod -- two registry functions called with self=mod
local defaultsTimer function core:RegisterOptions(modOptions, modDefaults, callback)
function core:RegisterOptions(modOptions, modDefaults)
local name = self:GetName() local name = self:GetName()
defaults.profile[name] = modDefaults defaults.profile[name] = modDefaults
options.args[name] = { options.args[name] = {
@ -52,12 +58,7 @@ function core:RegisterOptions(modOptions, modDefaults)
args = modOptions args = modOptions
} }
if defaultsTimer then databaseCallback[name] = callback
core:CancelTimer(defaultsTimer)
end
defaultsTimer = core:ScheduleTimer(function()
db:RegisterDefaults(defaults)
end, 0.01)
end end
function core:RegisterSlashCommand(callback, ...) function core:RegisterSlashCommand(callback, ...)
@ -67,7 +68,9 @@ function core:RegisterSlashCommand(callback, ...)
if slashCallback[slash] then if slashCallback[slash] then
error(("Slash command paramter already registered: '%s'"):format(slash)) error(("Slash command paramter already registered: '%s'"):format(slash))
end end
slashCallback[slash] = self[callback] slashCallback[slash] = function(...)
self[callback](self, ...)
end
if not keyword or slash:len() < keyword:len() then if not keyword or slash:len() < keyword:len() then
keyword = slash keyword = slash
@ -92,7 +95,13 @@ function core:MainSlashHandle(msg)
end end
end end
-- fill out our prototype now that our addon's indicies are populated function core:Print(...)
prototype.RegisterOptions = core.RegisterOptions LibStub("AceConsole-3.0").Print('atlt', ...)
prototype.RegisterSlashCommand = core.RegisterSlashCommand end
-- fill out our prototype now that our addon's indicies are populated
for _,method in ipairs(mixins) do
prototype[method] = core[method]
end

View file

@ -56,8 +56,7 @@ local armorGlyphs = {
} }
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {} self:RegisterOptions(options, defaults, function(d) db=d end)
self:RegisterOptions(options, defaults)
end end
function mod:OnEnable() function mod:OnEnable()

View file

@ -29,8 +29,7 @@ local wgStatus = 0
local flagStatus = 0 local flagStatus = 0
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {} self:RegisterOptions(options, defaults, function(d) db=d print(d) end)
self:RegisterOptions(options, defaults)
self:RegisterSlashCommand("ArathiPrint", "ab", "arathibasin") self:RegisterSlashCommand("ArathiPrint", "ab", "arathibasin")
end end

View file

@ -13,11 +13,10 @@ local options = {
} }
function mod:OnInitialize() 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("achievement:284")
self:FilterAll(nil, "Alabrooke") self:FilterAll(nil, "Alabrooke")
self:FilterAll(nil, "Warrwarr") self:FilterAll(nil, "Warrwarr")
end end
local chatEvents = { local chatEvents = {
@ -87,12 +86,13 @@ local contentFilters = { }
local sourceFilters = { } local sourceFilters = { }
function mod:FilterAll(filter, source) function mod:FilterAll(filter, source)
if not db.filterOn then return end
if filter or source then if filter or source then
if not next(contentFilters) then if not next(contentFilters) then
-- first time registry
for _,v in ipairs(chatEvents) do for _,v in ipairs(chatEvents) do
ChatFrame_AddMessageEventFilter(v, function(self, event, msg, sender) ChatFrame_AddMessageEventFilter(v, function(self, event, msg, sender)
if not db.filterOn then return end
if sourceFilters[sender] then if sourceFilters[sender] then
return true return true
end end

View file

@ -15,8 +15,7 @@ local options = {
} }
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {} self:RegisterOptions(options, defaults, function(d) db=d end)
self:RegisterOptions(options, defaults)
self:RegisterSlashCommand("method", "slsh1", "slash2") self:RegisterSlashCommand("method", "slsh1", "slash2")
end end

View file

@ -20,8 +20,7 @@ local rosterRaidersCount = 0
local rosterRaidersOnline = 0 local rosterRaidersOnline = 0
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {} self:RegisterOptions(options, defaults, function(d) db=d end)
self:RegisterOptions(options, defaults)
end end
function mod:OnEnable() function mod:OnEnable()

View file

@ -8,8 +8,7 @@ local options = {
} }
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {} -- self:RegisterOptions(options, defaults, function(d) db=d end)
-- self:RegisterOptions(options, defaults)
self:RegisterSlashCommand("DisbandRaid", "dr", "disbandraid") self:RegisterSlashCommand("DisbandRaid", "dr", "disbandraid")
self:RegisterSlashCommand("InviteGuild", "ig", "inviteguild") self:RegisterSlashCommand("InviteGuild", "ig", "inviteguild")
self:RegisterSlashCommand("PromoteAll", "pa", "promoteall") self:RegisterSlashCommand("PromoteAll", "pa", "promoteall")

View file

@ -38,8 +38,7 @@ local options = {
} }
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {} self:RegisterOptions(options, defaults, function(d) db=d print(d, db) end)
self:RegisterOptions(options, defaults)
self:RegisterSlashCommand("RollTally", "rt", "rolltally") self:RegisterSlashCommand("RollTally", "rt", "rolltally")
self:RegisterSlashCommand("FindPhones", "phone") self:RegisterSlashCommand("FindPhones", "phone")
self:RegisterSlashCommand("ActiveTally", "at", "activetally") self:RegisterSlashCommand("ActiveTally", "at", "activetally")
@ -58,7 +57,7 @@ function mod:OnEnable()
self:RegisterEvent("CHAT_MSG_SYSTEM") self:RegisterEvent("CHAT_MSG_SYSTEM")
-- nix afk -- nix afk
ChatFrame_AddMessageEventFilter("CHAT_MSG_AFK", function(...) return self:NixAFK(...); end); ChatFrame_AddMessageEventFilter("CHAT_MSG_AFK", function(...) return self:NixAFK(...) end)
-- achieve filter -- achieve filter
self:RawHook("AchievementFrame_LoadUI", true) self:RawHook("AchievementFrame_LoadUI", true)
@ -67,7 +66,7 @@ function mod:OnEnable()
self:SecureHook("TargetUnit") self:SecureHook("TargetUnit")
-- filter self targets -- 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 -- officer phone
self:RegisterEvent("CHAT_MSG_OFFICER"); self:RegisterEvent("CHAT_MSG_OFFICER");
@ -221,7 +220,7 @@ end
function mod:NixAFK(_, _, ...) function mod:NixAFK(_, _, ...)
return (not not db.nixAFK), ...; return (not not db.nixAFK), ...
end end

View file

@ -18,7 +18,6 @@ local potList = {
local mailQueue = {} -- used in /atlt pots local mailQueue = {} -- used in /atlt pots
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {}
self:RegisterSlashCommand("AddPotions", "pots") self:RegisterSlashCommand("AddPotions", "pots")
end end

View file

@ -8,7 +8,6 @@ local options = {
} }
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {}
end end
function mod:OnEnable() function mod:OnEnable()

View file

@ -14,8 +14,7 @@ local options = {
} }
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {} self:RegisterOptions(options, defaults, function(d) db=d end)
self:RegisterOptions(options, defaults)
end end
function mod:OnEnable() function mod:OnEnable()

View file

@ -8,7 +8,6 @@ local options = {
} }
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {}
end end
function mod:OnEnable() function mod:OnEnable()

View file

@ -8,7 +8,6 @@ local options = {
} }
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {} self:RegisterOptions(options, defaults, function(d) db=d end)
self:RegisterOptions(options, defaults)
end end

View file

@ -8,7 +8,6 @@ local options = {
} }
function mod:OnInitialize() function mod:OnInitialize()
db = core.db.profile[self:GetName()] or {} self:RegisterOptions(options, defaults, function(d) db=d end)
self:RegisterOptions(options, defaults)
end end