From 6fb52d3ddf2f515fd0bf3c2e877793799f55cab5 Mon Sep 17 00:00:00 2001 From: Casey Raethke Date: Wed, 30 Aug 2023 09:49:28 -0500 Subject: [PATCH] Change TipHooker from lib into single-purpose module --- .pkgmeta | 83 +++--- RatingBuster.lua | 23 +- RatingBuster.toc | 3 +- RatingBuster_TBC.toc | 5 +- RatingBuster_Vanilla.toc | 3 +- TipHooker.lua | 62 +++++ embeds.xml | 2 - libs/TipHooker-1.0/TipHooker-1.0.lua | 378 --------------------------- 8 files changed, 115 insertions(+), 444 deletions(-) create mode 100644 TipHooker.lua delete mode 100644 libs/TipHooker-1.0/TipHooker-1.0.lua diff --git a/.pkgmeta b/.pkgmeta index 401d6fc..09ee925 100644 --- a/.pkgmeta +++ b/.pkgmeta @@ -1,43 +1,40 @@ -package-as: RatingBuster - -externals: - libs/StatLogic/libs/LibStub: - url: https://repos.wowace.com/wow/libstub/trunk - libs/StatLogic/libs/AceLocale-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceLocale-3.0 - - libs/CallbackHandler-1.0: - url: https://repos.wowace.com/wow/callbackhandler/trunk/CallbackHandler-1.0 - libs/AceConsole-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceConsole-3.0 - libs/AceEvent-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceEvent-3.0 - libs/AceTimer-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceTimer-3.0 - libs/AceBucket-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceBucket-3.0 - libs/AceDB-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceDB-3.0 - libs/AceDBOptions-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceDBOptions-3.0 - libs/AceAddon-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceAddon-3.0 - libs/AceGUI-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceGUI-3.0 - libs/AceConfig-3.0: - url: https://repos.wowace.com/wow/ace3/trunk/AceConfig-3.0 - libs/LibDualSpec-1.0: - url: git://git.wowace.com/wow/libdualspec-1-0/mainline.git - -move-folders: - RatingBuster/libs/StatLogic: StatLogic - -ignore: - - *.txt - - *.jpg - -plain-copy: - - LICENSE.txt - -embedded-libraries: - - TipHookerLib +package-as: RatingBuster + +externals: + libs/StatLogic/libs/LibStub: + url: https://repos.wowace.com/wow/libstub/trunk + libs/StatLogic/libs/AceLocale-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceLocale-3.0 + + libs/CallbackHandler-1.0: + url: https://repos.wowace.com/wow/callbackhandler/trunk/CallbackHandler-1.0 + libs/AceConsole-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceConsole-3.0 + libs/AceEvent-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceEvent-3.0 + libs/AceTimer-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceTimer-3.0 + libs/AceBucket-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceBucket-3.0 + libs/AceDB-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceDB-3.0 + libs/AceDBOptions-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceDBOptions-3.0 + libs/AceAddon-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceAddon-3.0 + libs/AceGUI-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceGUI-3.0 + libs/AceConfig-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceConfig-3.0 + libs/LibDualSpec-1.0: + url: git://git.wowace.com/wow/libdualspec-1-0/mainline.git + +move-folders: + RatingBuster/libs/StatLogic: StatLogic + +ignore: + - *.txt + - *.jpg + +plain-copy: + - LICENSE.txt \ No newline at end of file diff --git a/RatingBuster.lua b/RatingBuster.lua index b1fe4c5..637ef4b 100644 --- a/RatingBuster.lua +++ b/RatingBuster.lua @@ -1,4 +1,4 @@ -local addonName = ... +local addonName, addon = ... --[[ Name: RatingBuster @@ -10,7 +10,6 @@ Description: Converts combat ratings in tooltips into normal percentages. --------------- -- Libraries -- --------------- -local TipHooker = LibStub("TipHooker-1.0") local StatLogic = LibStub("StatLogic") local GSM = function(...) return StatLogic:GetStatMod(...) @@ -1637,8 +1636,7 @@ end -- OnEnable() called at PLAYER_LOGIN function RatingBuster:OnEnable() - -- Hook item tooltips - TipHooker:Hook(self.ProcessTooltip, "item") + addon:EnableHook(self.ProcessTooltip) -- Initialize playerLevel playerLevel = UnitLevel("player") -- for setting a new level @@ -1649,8 +1647,7 @@ function RatingBuster:OnEnable() end function RatingBuster:OnDisable() - -- Unhook item tooltips - TipHooker:Unhook(self.ProcessTooltip, "item") + addon:DisableHook() end -- event = PLAYER_LEVEL_UP @@ -3472,17 +3469,9 @@ function RatingBuster:StatSummary(tooltip, name, link) -- Determine tooltipLevel and id if globalDB.calcDiff and (globalDB.sumDiffStyle == "comp") then -- Obtain main tooltip - for _, t in pairs(TipHooker.SupportedTooltips) do - if mainTooltip:IsOwned(t) then - mainTooltip = t - break - end - end - for _, t in pairs(TipHooker.SupportedTooltips) do - if mainTooltip:IsOwned(t) then - mainTooltip = t - break - end + local owner = tooltip:GetOwner() + if owner.GetObjectType and owner:GetObjectType() == "GameTooltip" then + mainTooltip = owner end -- Detemine tooltip level local _, mainlink, difflink1, difflink2 = StatLogic:GetDiffID(mainTooltip, globalDB.sumIgnoreEnchant, globalDB.sumIgnoreGems, globalDB.sumIgnoreExtraSockets, red, yellow, blue, meta) diff --git a/RatingBuster.toc b/RatingBuster.toc index 3d3e634..4b8f915 100644 --- a/RatingBuster.toc +++ b/RatingBuster.toc @@ -5,7 +5,7 @@ ## Author: Whitetooth, raethkcj ## SavedVariables: RatingBusterDB ## Dependencies: StatLogic -## OptionalDeps: Ace3, TipHookerLib, LibDualSpec-1.0 +## OptionalDeps: Ace3, LibDualSpec-1.0 ## X-Category: Interface Enhancements ## X-License: GPL v2 ## X-WoWI-ID: 26235 @@ -19,4 +19,5 @@ embeds.xml locales\locales.xml # Core +TipHooker.lua RatingBuster.lua diff --git a/RatingBuster_TBC.toc b/RatingBuster_TBC.toc index 2700094..7daddd3 100644 --- a/RatingBuster_TBC.toc +++ b/RatingBuster_TBC.toc @@ -1,11 +1,11 @@ -## Interface: 20504 +## Interface: 20504 ## Title: RatingBuster ## Notes: Item stat breakdown, analysis and comparing ## Notes-zhTW: 裝備數值解析與比較 ## Author: Whitetooth, raethkcj ## SavedVariables: RatingBusterDB ## Dependencies: StatLogic -## OptionalDeps: Ace3, TipHookerLib +## OptionalDeps: Ace3 ## X-Category: Interface Enhancements ## X-License: GPL v2 ## X-WoWI-ID: 26235 @@ -19,4 +19,5 @@ embeds.xml locales\locales.xml # Core +TipHooker.lua RatingBuster.lua diff --git a/RatingBuster_Vanilla.toc b/RatingBuster_Vanilla.toc index c188e40..4fcd672 100644 --- a/RatingBuster_Vanilla.toc +++ b/RatingBuster_Vanilla.toc @@ -5,7 +5,7 @@ ## Author: Whitetooth, raethkcj ## SavedVariables: RatingBusterDB ## Dependencies: StatLogic -## OptionalDeps: Ace3, TipHookerLib +## OptionalDeps: Ace3 ## X-Category: Interface Enhancements ## X-License: GPL v2 ## X-WoWI-ID: 26235 @@ -19,4 +19,5 @@ embeds.xml locales\locales.xml # Core +TipHooker.lua RatingBuster.lua diff --git a/TipHooker.lua b/TipHooker.lua new file mode 100644 index 0000000..ed7090f --- /dev/null +++ b/TipHooker.lua @@ -0,0 +1,62 @@ +local _, addon = ... + +local handler +local enabled = false + +local OnTooltipSetItem = function(tooltip) + if not tooltip.GetItem then return end + local name, link = tooltip:GetItem() + if not name then return end + + if enabled then + handler(tooltip, name, link) + end +end + +local TooltipList = { + "GameTooltip", + "ItemRefTooltip", + "ShoppingTooltip", + "LinkWrangler", + "AtlasLootTooltip", +} + +local initialized = false +local function InitializeHook() + local frame = EnumerateFrames() + while frame do + if frame.GetObjectType and frame:GetObjectType() == "GameTooltip" then + local name = frame:GetName() + if name then + for _, v in ipairs(TooltipList) do + if strfind(name, v) then + frame:HookScript("OnTooltipSetItem", OnTooltipSetItem) + break + end + end + end + end + frame = EnumerateFrames(frame) + end + initialized = true +end + +local variablesLoaded = false +EventRegistry:RegisterFrameEventAndCallbackWithHandle("VARIABLES_LOADED", function() + variablesLoaded = true + if handler and not initialized then + InitializeHook() + end +end) + +function addon:EnableHook(h) + handler = h + if variablesLoaded and not initialized then + InitializeHook() + end + enabled = true +end + +function addon:DisableHook() + enabled = false +end \ No newline at end of file diff --git a/embeds.xml b/embeds.xml index d398bcb..4f9ba7d 100644 --- a/embeds.xml +++ b/embeds.xml @@ -16,6 +16,4 @@ @end-non-debug@--> -