Mercurial > wow > reagentmaker
comparison utils.lua @ 16:250d01156e21
Use local references to global functions in the utils functions
| author | contrebasse |
|---|---|
| date | Wed, 06 Apr 2011 00:32:00 +0200 |
| parents | ed0582126cae |
| children | 5f3a5b88fb19 |
comparison
equal
deleted
inserted
replaced
| 15:cc56799582f2 | 16:250d01156e21 |
|---|---|
| 1 local addonName, A = ... | 1 local addonName, A = ... |
| 2 | |
| 3 -- Lua functions | |
| 4 local tonumber = tonumber | |
| 5 local select = select | |
| 6 local sfind = string.find | |
| 7 | |
| 8 -- Wow functions | |
| 2 | 9 |
| 3 -- DEBUG Print | 10 -- DEBUG Print |
| 4 function A.DEBUG(msg) | 11 function A.DEBUG(msg) |
| 12 -- GLOBALS: DEFAULT_CHAT_FRAME | |
| 5 DEFAULT_CHAT_FRAME:AddMessage(msg or "nil",1,0,0) | 13 DEFAULT_CHAT_FRAME:AddMessage(msg or "nil",1,0,0) |
| 6 end -- function | 14 end -- function |
| 7 | 15 |
| 8 -- Returns the item ID from its link | 16 -- Returns the item ID from its link |
| 9 function A.link2ID(link) | 17 function A.link2ID(link) |
| 10 return tonumber(select(3,string.find(link or "", "-*:(%d+)[:|].*")) or "") | 18 return tonumber(select(3,sfind(link or "", "-*:(%d+)[:|].*")) or "") |
| 11 end -- function | 19 end -- function |
| 12 | 20 |
| 13 -- Returns the button number for the reagents buttons | 21 -- Returns the button number for the reagents buttons |
| 14 function A.buttonNumber(btn) | 22 function A.buttonNumber(btn) |
| 15 -- "TradeSkillReagentN" | 23 -- "TradeSkillReagentN" |
| 16 return tonumber(btn:GetName():sub(-1)) | 24 return tonumber(btn:GetName():sub(-1)) |
| 17 end | 25 end |
| 18 | 26 |
| 19 -- Gives the number of craftable objects | 27 do |
| 20 function A.numMakable(reagentID) | 28 -- Wow functions |
| 21 -- Look for the recipe to make the item | 29 local GetTradeSkillInfo = GetTradeSkillInfo |
| 22 local reagentIndex = A.findSkillIndex(reagentID) | 30 local GetNumTradeSkills = GetNumTradeSkills |
| 23 if not reagentIndex then return 0 end | 31 local GetTradeSkillItemLink = GetTradeSkillItemLink |
| 24 | 32 |
| 25 -- Check how many items we can craft | 33 -- Gives the number of craftable objects |
| 26 local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex) | 34 function A.numMakable(reagentID) |
| 27 return numReagentMakable or 0, reagentIndex | 35 -- Look for the recipe to make the item |
| 28 end | 36 local reagentIndex = A.findSkillIndex(reagentID) |
| 37 if not reagentIndex then return 0 end | |
| 29 | 38 |
| 30 -- Find the first tradeskill index of the recipe to make an item | 39 -- Check how many items we can craft |
| 31 function A.findSkillIndex(itemID) | 40 local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex) |
| 32 for i = 1,GetNumTradeSkills() do | 41 return numReagentMakable or 0, reagentIndex |
| 33 local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(i) | 42 end |
| 34 if skillType == "header" then | 43 |
| 35 else | 44 -- Find the first tradeskill index of the recipe to make an item |
| 36 if skillName then | 45 function A.findSkillIndex(itemID) |
| 37 local ID = A.link2ID(GetTradeSkillItemLink(i)) | 46 for i = 1,GetNumTradeSkills() do |
| 38 if ID and ID == itemID then | 47 local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(i) |
| 39 return i | 48 if skillType == "header" then |
| 49 else | |
| 50 if skillName then | |
| 51 local ID = A.link2ID(GetTradeSkillItemLink(i)) | |
| 52 if ID and ID == itemID then | |
| 53 return i | |
| 54 end -- if | |
| 40 end -- if | 55 end -- if |
| 41 end -- if | 56 end -- if |
| 42 end -- if | 57 end -- for |
| 43 end -- for | 58 A.DEBUG("Tradeskill not found for "..itemID) |
| 44 A.DEBUG("Tradeskill not found for "..itemID) | 59 end -- function |
| 45 end -- function | 60 end -- do |
