Hi again all,
I personally thought that I'm pretty familiar with AceAddon-3.0, but seems I'm not
Okay, so I'm currently trying to make an AceAddon-3.0 based addon with three different modules that gets enabled & disabled based on player's current specialization and here's what I have done so far.
init.lua
Lua Code:
local name, ns = ...;
-- Upvalue
local _G = _G;
-- Addon
local E = LibStub("AceAddon-3.0"):NewAddon(name, "AceEvent-3.0");
local L = LibStub("AceLocale-3.0"):GetLocale(name, false);
local D = {};
ns[1] = E; -- Engine
ns[2] = L; -- Locale
ns[3] = D; -- Defaults
_G[name] = ns;
-- Variable
local specNameByID = { -- Needed for non English client
[259] = "Assassination",
[260] = "Outlaw",
[261] = "Subtlety",
}
-- Function
function E:OnInitialize()
self.db = LibStub("AceDB-3.0"):New(name .. "DB", D, true);
self:ACTIVE_TALENT_GROUP_CHANGED(nil, nil, nil, true);
end
function E:OnEnable()
print(E:GetName() .. " OnEnable");
end
function E:OnDisable()
print(E:GetName() .. " OnDisable");
end
function E:ACTIVE_TALENT_GROUP_CHANGED(event, arg1, arg2, isOnInitialize)
local db = self.db.global;
local newSpecID = GetSpecializationInfo(GetSpecialization());
if isOnInitialize or (db.currentSpecID and db.currentSpecID ~= newSpecID) then
db.currentSpecID = newSpecID;
for id, name in pairs(specNameByID) do
local module = self:GetModule(name);
(id == db.currentSpecID and module.Enable or module.Disable)(module);
end
end
end
E:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
Outlaw.lua
Lua Code:
local E, L, D = unpack(select(2, ...));
-- Module
local M = E:NewModule("Outlaw");
-- Variable
local RtBIDs = {
199603, -- Jolly Roger
193358, -- Grand Melee
193357, -- Shark Infested Waters
193359, -- True Bearing
199600, -- Buried Treasure
193356, -- Broadsides
}
local CotDID = 202665; -- Curse of the Dradeblades
local SaDID = 5171; -- Slice and Dice
local selectedSaD;
local InitializeObjects, ManageObjectStates;
-- Function
function M:OnInitialize()
InitializeObjects();
end
function M:OnEnable()
print(M:GetName(), "OnEnable");
local holder = self.holder;
holder:Show();
holder:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
holder:RegisterUnitEvent("UNIT_AURA", "player");
holder:SetScript("OnEvent", function(self, event, ...)
M[event](M, ...);
end);
ManageObjectStates();
end
function M:OnDisable()
print(M:GetName(), "OnDisable");
local holder = self.holder;
holder:UnregisterAllEvents();
holder:Hide();
end
The current problem is that after calling
Enable/Disable functions within
ACTIVE_TALENT_GROUP_CHANGED method on addon initialization, the module's
OnEnable/OnDisable functions don't get called on login, reload and etc, but only gets affected when the player actually changes his/her spec.
(talent changes are not considered on purpose)
According to the description in AceAddon-3.0.lua file, OnEnable functions get called during the PLAYER_LOGIN event (normally I'd say right after OnInitialize function gets called) and the state of modules are changed while initialization (L#50 of init.lua), thus I can't really think why it is not working
Am I doing something wrong?