move GetInventoryItemDurability function to global for future plugin use

This commit is contained in:
Crum
2018-06-06 23:42:24 -05:00
parent 2222abe39c
commit 265b0559f8
2 changed files with 23 additions and 22 deletions
+22
View File
@@ -10,6 +10,7 @@ local unpack = unpack
local find, format, gsub, lower, match, upper = string.find, string.format, string.gsub, string.lower, string.match, string.upper local find, format, gsub, lower, match, upper = string.find, string.format, string.gsub, string.lower, string.match, string.upper
local getn = table.getn local getn = table.getn
--WoW API --WoW API
local GetInventoryItemTexture = GetInventoryItemTexture
local GetItemInfo = GetItemInfo local GetItemInfo = GetItemInfo
local GetQuestGreenRange = GetQuestGreenRange local GetQuestGreenRange = GetQuestGreenRange
local GetRealZoneText = GetRealZoneText local GetRealZoneText = GetRealZoneText
@@ -21,6 +22,7 @@ local UnitLevel = UnitLevel
local DUNGEON_DIFFICULTY1 = DUNGEON_DIFFICULTY1 local DUNGEON_DIFFICULTY1 = DUNGEON_DIFFICULTY1
local TIMEMANAGER_AM = gsub(TIME_TWELVEHOURAM, "^.-(%w+)$", "%1") local TIMEMANAGER_AM = gsub(TIME_TWELVEHOURAM, "^.-(%w+)$", "%1")
local TIMEMANAGER_PM = gsub(TIME_TWELVEHOURPM, "^.-(%w+)$", "%1") local TIMEMANAGER_PM = gsub(TIME_TWELVEHOURPM, "^.-(%w+)$", "%1")
local DURABILITY_TEMPLATE = gsub(DURABILITY_TEMPLATE, "%%d / %%d", "(%%d+) / (%%d+)")
--Libs --Libs
local LBC = LibStub("LibBabble-Class-3.0"):GetLookupTable() local LBC = LibStub("LibBabble-Class-3.0"):GetLookupTable()
local LBZ = LibStub("LibBabble-Zone-3.0"):GetLookupTable() local LBZ = LibStub("LibBabble-Zone-3.0"):GetLookupTable()
@@ -472,4 +474,24 @@ function GetItemCount(itemName)
end end
return count return count
end
local scan
function GetInventoryItemDurability(slot)
if not GetInventoryItemTexture("player", slot) then return nil, nil end
if not scan then
scan = CreateFrame("GameTooltip", "DurabilityScan", nil, "ShoppingTooltipTemplate")
scan:SetOwner(UIParent, "ANCHOR_NONE")
end
scan:ClearLines()
scan:SetInventoryItem("player", slot)
for i = 4, scan:NumLines() do
local text = _G[scan:GetName().."TextLeft"..i]:GetText()
for durability, max in string.gfind(text, DURABILITY_TEMPLATE) do
return tonumber(durability), tonumber(max)
end
end
end end
+1 -22
View File
@@ -11,9 +11,8 @@ local GetInventoryItemDurability = GetInventoryItemDurability
local GetInventoryItemTexture = GetInventoryItemTexture local GetInventoryItemTexture = GetInventoryItemTexture
local GetInventorySlotInfo = GetInventorySlotInfo local GetInventorySlotInfo = GetInventorySlotInfo
local ToggleCharacter = ToggleCharacter local ToggleCharacter = ToggleCharacter
local DURABILITY_TEMPLATE = string.gsub(DURABILITY_TEMPLATE, "%%d / %%d", "(%%d+) / (%%d+)")
local DURABILITY = "Durability" -- Neel ElvUI locale local DURABILITY = "Durability"
local displayString = "" local displayString = ""
local tooltipString = "%d%%" local tooltipString = "%d%%"
@@ -34,26 +33,6 @@ local slots = {
"HeadSlot" "HeadSlot"
} }
local scan
local function GetInventoryItemDurability(slot)
if not GetInventoryItemTexture("player", slot) then return nil, nil end
if not scan then
scan = CreateFrame("GameTooltip", "DurabilityScan", nil, "ShoppingTooltipTemplate")
scan:SetOwner(UIParent, "ANCHOR_NONE")
end
scan:ClearLines()
scan:SetInventoryItem("player", slot)
for i = 4, scan:NumLines() do
local text = _G[scan:GetName().."TextLeft"..i]:GetText()
for durability, max in string.gfind(text, DURABILITY_TEMPLATE) do
return tonumber(durability), tonumber(max)
end
end
end
local function OnEvent(self, t) local function OnEvent(self, t)
lastPanel = self lastPanel = self
totalDurability = 100 totalDurability = 100