A global function to check the source of an item
birdryoo opened this issue ยท 2 comments
Is it possible to create a global function to utilize in other addons?
If this feature already exists, please let me know.
What I need is the source information of the item.
In the OnTooltipSetItem_Hook event defined in Addons/Sources.lua, the source is directly written to the ToolTip.
I would like to take advantage of this and add a global function so that other addons can acquire the source.
For example, I added a function to Sources.lua referring to the codes of OnTooltipSetItem_Hook.
function Sources:GetSources(item)
local sourceData
for i = #SOURCE_DATA, 1, -1 do
if item and SOURCE_DATA[i].ItemData[item] then
sourceData = SOURCE_DATA[i]
end
end
if item and sourceData then
if TooltipTextCache[item] ~= false then
if not TooltipTextCache[item] then
local iconTexture, baseItem
if type(sourceData.ItemData[item]) == "number" then
iconTexture = format(TEXTURE_ICON_FN, GetItemIcon(sourceData.ItemData[item]))
baseItem = sourceData.ItemData[item]
end
TooltipTextCache[item] = {}
if type(sourceData.ItemData[baseItem or item][1]) == "table" then
for i = 1, #sourceData.ItemData[baseItem or item] do
local data = sourceData.ItemData[baseItem or item][i]
if data[3] and Sources.db.Sources[data[3]] then
TooltipTextCache[item][i] = format(TT_F, iconTexture or ICON_TEXTURE[data[3] or 0], BuildSource(sourceData.AtlasLootIDs[data[1]], data[2], data[3], data[4] or baseItem or item, data[5]))
end
end
else
local data = sourceData.ItemData[baseItem or item]
if data[3] and Sources.db.Sources[data[3]] then
TooltipTextCache[item][1] = format(TT_F, iconTexture or ICON_TEXTURE[data[3] or 0], BuildSource(sourceData.AtlasLootIDs[data[1]], data[2], data[3], data[4] or baseItem or item, data[5]))
end
end
if #TooltipTextCache[item] < 1 then
TooltipTextCache[item] = false
end
end
end
if TooltipTextCache[item] then
return TooltipTextCache[item]
end
end
return nil
end
I hope this is officially released.