Skip to content

Commit

Permalink
Implement our own EventUtil.ContinueOnAddOnLoaded to avoid some rare …
Browse files Browse the repository at this point in the history
…errors
  • Loading branch information
Numynum committed Nov 13, 2024
1 parent 7fc3780 commit 401eba0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
17 changes: 17 additions & 0 deletions SharedUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ do
end

Util.configIDLookup = {};
Util.addonLoadedRegistry = {};

function Util:DebugPrint(...)
if not self.debug then return; end
Expand Down Expand Up @@ -76,6 +77,12 @@ function Util:OnInitialize()
eventFrame:UnregisterEvent('ADDON_LOADED');
self:RunOnLoadCallbacks();
end
if self.addonLoadedRegistry[addonName] then
for _, callback in ipairs(self.addonLoadedRegistry[addonName]) do
securecallfunction(callback);
end
self.addonLoadedRegistry[addonName] = nil;
end
end
if event == 'TRAIT_CONFIG_LIST_UPDATED' then
self:RefreshConfigIDLookup();
Expand Down Expand Up @@ -107,6 +114,16 @@ function Util:GetterSetterIncrementFactory(db, postSetCallback)
return getter, setter, increment;
end

function Util:ContinueOnAddonLoaded(addonName, callback)
if C_AddOns.IsAddOnLoaded(addonName) then
callback();
return;
end

self.addonLoadedRegistry[addonName] = self.addonLoadedRegistry[addonName] or {};
table.insert(self.addonLoadedRegistry[addonName], callback);
end

function Util:ResetRegistry()
self.classTalentUILoadCallbacks = {
minPriority = 1,
Expand Down
2 changes: 1 addition & 1 deletion modules/changeBackground.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Module:OnEnable()
Util:OnTalentUILoad(function()
self:SetupDefaultUI();
end);
EventUtil.ContinueOnAddOnLoaded(TalentViewerLoader and TalentViewerLoader:GetLodAddonName() or 'TalentTreeViewer', function()
Util:ContinueOnAddonLoaded(TalentViewerLoader and TalentViewerLoader:GetLodAddonName() or 'TalentTreeViewer', function()
self:SetupTTVUI();
end);
end
Expand Down
8 changes: 4 additions & 4 deletions modules/copyTalentButtonInfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ function Module:OnEnable()
Util:OnTalentUILoad(function()
self:SetupHook(Util:GetTalentFrame());
end);
EventUtil.ContinueOnAddOnLoaded('Blizzard_GenericTraitUI', function()
Util:ContinueOnAddonLoaded('Blizzard_GenericTraitUI', function()
self:SetupHook(GenericTraitFrame);
end);
EventUtil.ContinueOnAddOnLoaded(TalentViewerLoader and TalentViewerLoader:GetLodAddonName() or 'TalentTreeViewer', function()
Util:ContinueOnAddonLoaded(TalentViewerLoader and TalentViewerLoader:GetLodAddonName() or 'TalentTreeViewer', function()
local talentsTab = TalentViewer and TalentViewer.GetTalentFrame and TalentViewer:GetTalentFrame();
if not talentsTab then return; end
self:SetupHook(talentsTab);
end)
end);
self:RegisterEvent('PLAYER_REGEN_DISABLED');
self:RegisterEvent('PLAYER_REGEN_ENABLED');
EventRegistry:RegisterCallback("TalentDisplay.TooltipCreated", self.OnTalentTooltipCreated, self)
Expand Down Expand Up @@ -127,7 +127,7 @@ function Module:OnSpellbookButtonEnter(button)
if not spellID then return; end
self.textToCopy = spellID;
self:EnableBinding();
self:OnTalentTooltipCreated(nil, GameTooltip);
self:OnTalentTooltipCreated(nil, ElvUI_SpellBookTooltip or GameTooltip);
end

function Module:OnSpellbookButtonLeave()
Expand Down
2 changes: 1 addition & 1 deletion modules/inspectDiff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Module:OnEnable()
end);

self.viewerButtonTextures = self.viewerButtonTextures or {};
EventUtil.ContinueOnAddOnLoaded(TalentViewerLoader and TalentViewerLoader:GetLodAddonName() or 'TalentTreeViewer', function()
Util:ContinueOnAddonLoaded(TalentViewerLoader and TalentViewerLoader:GetLodAddonName() or 'TalentTreeViewer', function()
self:SetupViewerHook();
end);
end
Expand Down
4 changes: 2 additions & 2 deletions modules/miniTreeInTooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ function Module:OnEnable()
end)
self:SecureHook(GameTooltip, "Show", "OnTooltipShow");

EventUtil.ContinueOnAddOnLoaded("Blizzard_InspectUI", function()
Util:ContinueOnAddonLoaded("Blizzard_InspectUI", function()
self:HookInspectTalentsButton();
end)
end);
end

function Module:OnDisable()
Expand Down
4 changes: 2 additions & 2 deletions modules/scaleTalentFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function Module:OnEnable()
Util:OnTalentUILoad(function()
self:SetupHook(BLIZZARD_TALENT_UI);
end);
EventUtil.ContinueOnAddOnLoaded(TALENT_TREE_VIEWER, function()
Util:ContinueOnAddonLoaded(TALENT_TREE_VIEWER, function()
self:SetupHook(TALENT_TREE_VIEWER);
end)
end);
end

function Module:OnDisable()
Expand Down
4 changes: 2 additions & 2 deletions modules/searchForIds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function Module:OnEnable()
Util:OnTalentUILoad(function()
self:SetupHook(BLIZZARD_TALENT_UI);
end);
EventUtil.ContinueOnAddOnLoaded(TalentViewerLoader and TalentViewerLoader:GetLodAddonName() or 'TalentTreeViewer', function()
Util:ContinueOnAddonLoaded(TalentViewerLoader and TalentViewerLoader:GetLodAddonName() or 'TalentTreeViewer', function()
self:SetupHook(TALENT_TREE_VIEWER);
end)
end);
end

function Module:OnDisable()
Expand Down

0 comments on commit 401eba0

Please sign in to comment.