I already don't know what the heck you've done there.
I'd do something like this very light and totally untested system that uses AceDB and replicates the basic features of AceAddon and AceEvent, plus some specialized logic to automatically toggle modules on and off based on spec:
Lua Code:
-- create addon object:
local MyAddon = CreateFrame("Frame", "MyAddon")
-- create table to use as a module registry:
MyAddon.modules = {}
-- set up AceEvent-style event handling:
local function eventHandler(self, event, ...) return self[event](self, ...) end
MyAddon:SetScript("OnEvent", eventHandler)
MyAddon:RegisterEvent("PLAYER_LOGIN")
-- add module creation:
function MyAddon:NewModule(name, defaults)
-- make each module its own object with its own event handling:
local module = CreateFrame("Frame")
module:SetScript("OnEvent", eventHandler)
if defaults then
if self.db then
-- for modules registered after login:
module.db = self.db:RegisterNamespace(name, defaults)
else
-- for modules registered before/during login,
-- the core db doesn't exist yet, so hold onto it:
self.pending = self.pending or {}
self.pending[name] = defaults
end
end
-- add it to the registry:
self.modules[name] = module
-- and pass back a reference to the object:
return module
end
function MyAddon:GetModule(name)
return self.modules[name]
end
-- basically OnInitialize:
function MyAddon:PLAYER_LOGIN()
-- register the core addon db here:
local defaults = {
profile = {
cats = true,
dogs = false,
}
}
self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
-- deal with modules registered before/during login:
if self.pending then
for name, defaults in pairs(self.pending) do
local module = self.modules[name]
module.db = self.db:RegisterNamespace(name, defaults)
end
self.pending = nil
end
-- register your main logic event:
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
self:ACTIVE_TALENT_GROUP_CHANGED()
end
-- handle your main logic event:
function MyAddon:ACTIVE_TALENT_GROUP_CHANGED()
local id = GetSpecializationInfo(GetSpecialization())
-- go through all the registered modules:
for name, module in pairs(self.modules) do
-- and enable or disable them according to whether they match the current spec:
if module.specID == id then
module.enabled = true
module:Enable()
else
module:Disable()
module.enabled = false
end
end
end
And then in each module:
Lua Code:
-- create a new module with some default profile settings:
local DruidCatModule = MyAddon:NewModule("DruidCat", {
profile = {
fluffy = true,
}
})
-- give it a specID so the core can figure out when to toggle it:
DruidCatModule.specID = 12345 -- note: not the real spell ID!
-- and an Enable method the core can call to turn it on:
function DruidCatModule:Enable()
-- register for events, create frames if they don't exist yet, show frames
-- self.db gives you the module's specific db
-- register an event just like you would in the core or with AceEvent:
self:RegisterEvent("EXAMPLE_EVENT")
end
-- and a Disable method the core can call to turn it off:
function DruidCatModule:Disable()
-- unregister events, hide frames
self:UnregisterEvent("EXAMPLE_EVENT")
end
-- and handle an event like so:
function DruidCatModule:EXAMPLE_EVENT(fakeArg)
print("This will never happen.")
end