Mercurial > wow > reagentmaker
changeset 73:a77fd9d06ba4
Use the new internal data format everywhere
author | contrebasse |
---|---|
date | Sat, 14 May 2011 20:55:49 +0200 |
parents | 9cf4ca2145a3 |
children | e837f5681fbb |
files | ReagentMaker.lua SecureMenu.lua utils.lua |
diffstat | 3 files changed, 34 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/ReagentMaker.lua Sat May 14 20:28:05 2011 +0200 +++ b/ReagentMaker.lua Sat May 14 20:55:49 2011 +0200 @@ -215,18 +215,7 @@ btn.textureHighlight:Show() -- Check if the item is made by only one recipe. If not, return - if #A.data[reagentID]>1 then - local spellLink - for _,v in ipairs(A.data[reagentID]) do - if not spellLink then - spellLink = v.spellLink - else - if v.spellLink ~= spellLink then - return - end - end - end - end + if not A.isRecipeUnique(A.data[reagentID]) then return end -- Tooltips local link = A.data[reagentID][1].spellLink
--- a/SecureMenu.lua Sat May 14 20:28:05 2011 +0200 +++ b/SecureMenu.lua Sat May 14 20:55:49 2011 +0200 @@ -210,14 +210,14 @@ if numMakable>0 then -- Set action - if type(action)=="function" then + if type(btn.action)=="function" then btn:SetScript("PreClick",btn.action) btn:SetAttribute("type", nil) btn:SetAttribute("macrotext", nil) else --if type(action)=="string" then btn:SetScript("PreClick",nil) btn:SetAttribute("type", "macro") - btn:SetAttribute("macrotext", btn.action..btn.itemNameString) + btn:SetAttribute("macrotext", btn.action:format(btn.itemNameString)) end -- if anyMakable = true @@ -249,7 +249,7 @@ end end -local function menuAddItem(action,itemID,reagent,spellLink) +local function menuAddItem(action,itemID,reagent) local btn -- Create a button only if necessary if numActiveEntries >= #menuEntries then @@ -260,19 +260,12 @@ -- Set text and icon local name, link, _, _, _, _, _, _, _, texture = GetItemInfo(reagent[1]) - if name then - btn.itemName:SetText(name) - else - --A.DEBUG("No item name : "..reagent[1]) + if not (name and link and texture) then + -- Will be retried on next OnUpdate return end - - if texture then - btn.icon:SetTexture(texture) - else - --A.DEBUG("No item texture : "..reagent[1]) - return - end + btn.itemName:SetText(name) + btn.icon:SetTexture(texture) -- Set chance to have the item or the number of items created if reagent[3] then @@ -290,7 +283,7 @@ btn.reagentID = reagent[1] btn.reagentLink = link btn.reagentsForOneRecipe = reagent[2] - btn.spellLink = spellLink + btn.spellLink = reagent.spellLink btn.action = action btn.itemNameString = name @@ -336,16 +329,16 @@ -- Save vars to show the tooltip later MenuFrame.reagentLink = link - MenuFrame.spellLink = A.data[itemID].spellLink + MenuFrame.spellLink = A.isRecipeUnique(A.data[itemID]) and A.data[itemID][1].spellLink MenuFrame.itemID = itemID - MenuFrame.superItemID = superItemID -- optional + MenuFrame.superItemID = superItemID -- optional, will be nil if not set -- Loop over the available recipes MenuFrame.state = true for _,reagent in ipairs(A.data[itemID]) do - if A.data[itemID].spell then + if reagent.macro then -- Special spell - MenuFrame.state = menuAddItem(A.data[itemID].spell,itemID,reagent,A.data[itemID].spellLink) and MenuFrame.state + MenuFrame.state = menuAddItem(reagent.macro,itemID,reagent) and MenuFrame.state else -- Standard tradeskill spell UNTESTED MenuFrame.state = menuAddItem(A.craft,itemID,reagent) and MenuFrame.state
--- a/utils.lua Sat May 14 20:28:05 2011 +0200 +++ b/utils.lua Sat May 14 20:55:49 2011 +0200 @@ -214,3 +214,24 @@ end print("restored") end + +function A.isRecipeUnique(itemData) + local unique = true + + -- Check if the item is made by only one recipe. If not, return + if #itemData>1 then + local spellLink + for _,v in ipairs(itemData) do + if not spellLink then + spellLink = v.spellLink + else + if v.spellLink ~= spellLink then + unique = nil + break + end + end + end + end + + return unique +end