Something like:
Code:
-- Construct your saarch pattern based on the existing global string:
local S_UPGRADE_LEVEL = "^" .. gsub(ITEM_UPGRADE_TOOLTIP_FORMAT, "%%d", "(%%d+)")
-- Create the tooltip:
local scantip = CreateFrame("GameTooltip", "MyScanningTooltip", nil, "GameTooltipTemplate")
scantip:SetOwner(UIParent, "ANCHOR_NONE")
-- Create a function for simplicity's sake:
local function GetItemUpgradeLevel(itemLink)
-- Pass the item link to the tooltip:
scantip:SetHyperlink(itemLink)
-- Scan the tooltip:
for i = 2, scantip:NumLines() do -- Line 1 is always the name so you can skip it.
local text = _G["MyScanningTooltipTextLeft"..i]:GetText()
if text and text ~= "" then
local currentUpgradeLevel, maxUpgradeLevel = strmatch(text, S_UPGRADE_LEVEL)
if currentUpgradeLevel then
return currentUpgradeLevel, maxUpgradeLevel
end
end
end
end
-- Now you can just call the function to get the levels:
local currentUpgradeLevel, maxUpgradeLevel = GetItemUpgradeLevel(itemLink)