view utils.lua @ 14:5c8fcfdd1e24

Remove incorrect warnings
author contrebasse
date Tue, 05 Apr 2011 21:59:01 +0200
parents ed0582126cae
children 250d01156e21
line wrap: on
line source
local addonName, A = ...

-- DEBUG Print
function A.DEBUG(msg)
	DEFAULT_CHAT_FRAME:AddMessage(msg or "nil",1,0,0)
end -- function

-- Returns the item ID from its link
function A.link2ID(link)
	return tonumber(select(3,string.find(link or "", "-*:(%d+)[:|].*")) or "")
end -- function

-- Returns the button number for the reagents buttons
function A.buttonNumber(btn)
	-- "TradeSkillReagentN"
	return tonumber(btn:GetName():sub(-1))
end

-- Gives the number of craftable objects
function A.numMakable(reagentID)
	-- Look for the recipe to make the item
	local reagentIndex = A.findSkillIndex(reagentID)
	if not reagentIndex then return 0 end

	-- Check how many items we can craft
	local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex)
	return numReagentMakable or 0, reagentIndex
end

-- Find the first tradeskill index of the recipe to make an item
function A.findSkillIndex(itemID)
	for i = 1,GetNumTradeSkills() do
		local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(i)
		if skillType == "header" then
		else
			if skillName then
				local ID = A.link2ID(GetTradeSkillItemLink(i))
				if ID and ID == itemID then
					return i
				end -- if
			end -- if
		end -- if
	end -- for
	A.DEBUG("Tradeskill not found for "..itemID)
end -- function