Commit 1d4b10ed authored by Robin Schoonover's avatar Robin Schoonover

Refactor addon loaded functionality.

parent fc5fd30c
local addon_name, addon = ...
local event_frame = CreateFrame("FRAME")
event_frame:SetScript("OnEvent", function(frame, event, ...)
local func = frame[event]
if func then
return func(frame, ...)
end
end)
event_frame.on_addon = {}
local function OnAddOnLoaded(addon, func)
if IsAddOnLoaded(addon) then
return func()
end
if event_frame.on_addon[addon] ~= nil then
tinsert(event_frame.on_addon[addon], func)
else
event_frame.on_addon[addon] = {func}
end
end
function event_frame:ADDON_LOADED(addon_name)
if event_frame.on_addon[addon_name] ~= nil then
for i, func in ipairs(event_frame.on_addon[addon_name]) do
func()
end
event_frame.on_addon[addon_name] = nil
end
end
event_frame:RegisterEvent("ADDON_LOADED")
--
-- PetJournal
--
do
local function HookPetCard()
OnAddOnLoaded("Blizzard_Collections", function()
PetJournalPetCardPetInfo:HookScript("OnEnter", function(self)
if GameTooltip:GetOwner() == self then
local speciesID = PetJournalPetCard.speciesID
......@@ -14,7 +45,7 @@ do
addon:AddIDLine(GameTooltip, "Species", speciesID, "NPC", creatureID)
end
end)
end
end)
local origSharedPetBattleAbilityTooltip_SetAbility = SharedPetBattleAbilityTooltip_SetAbility
......@@ -32,20 +63,6 @@ do
return origSharedPetBattleAbilityTooltip_SetAbility(tip, abilityInfo, additionalInfo)
end
if IsAddOnLoaded("Blizzard_Collections") then
HookPetCard()
else
local frame = CreateFrame("FRAME")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, addon_name)
if addon_name == "Blizzard_Collections" then
HookPetCard()
self:UnregisterEvent("ADDON_LOADED")
end
end)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment