Skip to content

Commit

Permalink
Change TipHooker from lib into single-purpose module
Browse files Browse the repository at this point in the history
  • Loading branch information
raethkcj committed Aug 30, 2023
1 parent dc8cf71 commit 6fb52d3
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 444 deletions.
83 changes: 40 additions & 43 deletions .pkgmeta
Original file line number Diff line number Diff line change
@@ -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
23 changes: 6 additions & 17 deletions RatingBuster.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local addonName = ...
local addonName, addon = ...

--[[
Name: RatingBuster
Expand All @@ -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(...)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand 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)
Expand Down
3 changes: 2 additions & 1 deletion RatingBuster.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,4 +19,5 @@ embeds.xml
locales\locales.xml

# Core
TipHooker.lua
RatingBuster.lua
5 changes: 3 additions & 2 deletions RatingBuster_TBC.toc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,4 +19,5 @@ embeds.xml
locales\locales.xml

# Core
TipHooker.lua
RatingBuster.lua
3 changes: 2 additions & 1 deletion RatingBuster_Vanilla.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,4 +19,5 @@ embeds.xml
locales\locales.xml

# Core
TipHooker.lua
RatingBuster.lua
62 changes: 62 additions & 0 deletions TipHooker.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions embeds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@
<Include file="libs\LibDualSpec-1.0\LibDualSpec-1.0.lua"/>
@end-non-debug@-->

<Script file="libs\TipHooker-1.0\TipHooker-1.0.lua"/>

</Ui>
Loading

0 comments on commit 6fb52d3

Please sign in to comment.