Files

113 lines
5.7 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Lazy original-data requests, preserving native tooltip layout and item context.
-- No stat, name, set count, item, spell, combat or secret-value API overrides.
local data = GWItemDependencyData
local diagnostics = { version = 2, requests = 0, spellRequests = 0, rebuilds = 0, errors = 0 }
GWItemDependencyDiagnostics = diagnostics
local function public(value)
return type(issecretvalue) ~= "function" or not issecretvalue(value)
end
local function itemID(value)
return public(value) and type(value) == "number" and value > 0 and value < 2147483648 and value == math.floor(value)
end
if type(data) ~= "table" or type(data.itemSets) ~= "table" or type(data.sets) ~= "table" or
type(C_Item) ~= "table" or type(C_Item.GetItemInfo) ~= "function" or type(C_Item.RequestLoadItemDataByID) ~= "function" or
type(TooltipDataProcessor) ~= "table" or type(TooltipDataProcessor.AddTooltipPostCall) ~= "function" or
type(Enum) ~= "table" or type(Enum.TooltipDataType) ~= "table" or Enum.TooltipDataType.Item ~= 0 or
type(C_Timer) ~= "table" or type(C_Timer.After) ~= "function" then return end
local requested = {}
local requestedSpells = {}
local spellAPI = type(C_Spell)=="table" and type(C_Spell.IsSpellDataCached)=="function" and type(C_Spell.RequestLoadSpellData)=="function"
local pending = setmetatable({}, { __mode = "k" })
local scheduled = false
local function rebuild()
scheduled = false
local snapshot = pending
pending = setmetatable({}, { __mode = "k" })
for tooltip, expected in pairs(snapshot) do
if type(tooltip.IsShown) == "function" and tooltip:IsShown() and
type(tooltip.GetTooltipData) == "function" and type(tooltip.RebuildFromTooltipInfo) == "function" then
local current = tooltip:GetTooltipData()
if type(current) == "table" and itemID(current.id) and current.id == expected then
local ok = pcall(tooltip.RebuildFromTooltipInfo, tooltip)
if ok then diagnostics.rebuilds = diagnostics.rebuilds + 1 else diagnostics.errors = diagnostics.errors + 1 end
end
end
end
end
local function schedule()
if not scheduled then scheduled = true; C_Timer.After(0.15, rebuild) end
end
local function primaryTooltip(tooltip)
if tooltip == GameTooltip or tooltip == ItemRefTooltip then return tooltip end
if tooltip == ShoppingTooltip1 or tooltip == ShoppingTooltip2 or tooltip == ShoppingTooltip3 then return GameTooltip end
if tooltip == ItemRefShoppingTooltip1 or tooltip == ItemRefShoppingTooltip2 then return ItemRefTooltip end
end
local function warm(tooltip, info)
if type(info) ~= "table" or not itemID(info.id) then return end
local primary = primaryTooltip(tooltip)
if not primary or type(primary.GetTooltipData) ~= "function" then return end
local setID = data.itemSets[info.id]
local members = data.sets[setID]
local spells = type(data.itemSpells)=="table" and data.itemSpells[info.id]
local bonuses = type(data.setSpells)=="table" and data.setSpells[setID]
if type(members) ~= "table" and type(spells) ~= "table" and type(bonuses) ~= "table" then return end
local missing, started = false, false
for _, id in ipairs(type(members)=="table" and members or {}) do
local name = C_Item.GetItemInfo(id)
if public(name) and (name == nil or name == "") then
missing = true
if not requested[id] then
requested[id] = true
C_Item.RequestLoadItemDataByID(id)
diagnostics.requests = diagnostics.requests + 1
started = true
end
end
end
if spellAPI then
for _, group in ipairs({type(spells)=="table" and spells or {},type(bonuses)=="table" and bonuses or {}}) do
for _, id in ipairs(group) do
if itemID(id) then
local cached=C_Spell.IsSpellDataCached(id)
if public(cached) and cached==false then
missing=true
if not requestedSpells[id] then
requestedSpells[id]=true
C_Spell.RequestLoadSpellData(id)
diagnostics.spellRequests=diagnostics.spellRequests+1
started=true
end
end
end
end
end
end
if missing then
local current = primary:GetTooltipData()
if type(current) == "table" and itemID(current.id) then
pending[primary] = current.id
if started then schedule() end
end
end
end
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(tooltip, info)
local ok = pcall(warm, tooltip, info)
if not ok then diagnostics.errors = diagnostics.errors + 1 end
end)
-- Native70334 RebuildFromTooltipInfo retains getters, enchant/instance arguments,
-- appended comparisons and rebuild callbacks. Rebuild only the primary owner;
-- independently rebuilding ShoppingTooltip corrupts its append-only info list.
-- Do not substitute SetHyperlink.
if type(CreateFrame) == "function" then
local frame = CreateFrame("Frame")
pcall(frame.RegisterEvent, frame, "GET_ITEM_INFO_RECEIVED")
pcall(frame.RegisterEvent, frame, "ITEM_DATA_LOAD_RESULT")
if spellAPI then pcall(frame.RegisterEvent, frame, "SPELL_DATA_LOAD_RESULT") end
frame:SetScript("OnEvent", function(_, event, id, success)
local watched=event=="SPELL_DATA_LOAD_RESULT" and requestedSpells or requested
if itemID(id) and watched[id] and public(success) and success then schedule() end
end)
end