# HG changeset patch # User contrebasse # Date 1308093240 -7200 # Node ID 7ce304c296b0aa7c95e49428834a0c27328d008b # Parent 5a3fb8fea0265ca8fa72670744a653279581cacb Display then number of makable items instead of the number of times the recipe is craftable diff -r 5a3fb8fea026 -r 7ce304c296b0 ReagentMaker.lua --- a/ReagentMaker.lua Wed Jun 15 00:05:35 2011 +0200 +++ b/ReagentMaker.lua Wed Jun 15 01:14:00 2011 +0200 @@ -197,13 +197,18 @@ label:Hide() else -- Count and show - local numMakable = A.numMakable(reagentID) - if not numMakable then + local numMakableMin, numMakableMax, numMakableIsApprox = A.numMakable(reagentID) + if not numMakableMin then label:SetText("?") label:SetTextColor(0, 0.5, 1, 1) -- blue else - label:SetText(numMakable) - if numMakable==0 then + local txt = numMakableIsApprox and "~" or "" + if numMakableMin == numMakableMax then + label:SetFormattedText("%s%.2g",txt,numMakableMin) + else + label:SetFormattedText("%s%.2g-%.2g",txt,numMakableMin,numMakableMax) + end + if numMakableMax==0 then label:SetTextColor(1, 0, 0, 1) -- red else label:SetTextColor(0, 1, 0, 1) -- green diff -r 5a3fb8fea026 -r 7ce304c296b0 utils.lua --- a/utils.lua Wed Jun 15 00:05:35 2011 +0200 +++ b/utils.lua Wed Jun 15 01:14:00 2011 +0200 @@ -69,18 +69,38 @@ end -- if end - -- Gives the total number of craftable objects + -- Gives the total number of craftable items function A.numMakable(reagentID) -- No recipe if not A.data[reagentID] then return 0 end -- Many recipes - local n = 0 - local itemCount + local n1 = 0 + local n2 = 0 + local m + local approx = nil for _,recipe in pairs(A.data[reagentID]) do - n = n + A.numRecipeMakable(recipe[1],recipe[2]) + -- number of times the recipe is makable + m = A.numRecipeMakable(recipe[1],recipe[2]) + if not m then return end + + -- number of items it gives + if not recipe[3] or recipe[3]==1 then + n1 = n1 + m + n2 = n2 + m + elseif recipe[3]<1 then + approx = approx or m>0 -- 0 is not approx + n1 = n1 + m*recipe[3] + n2 = n2 + m*recipe[3] + elseif recipe[4] then + n1 = n1 + m*recipe[3] + n2 = n2 + m*recipe[4] + else + n1 = n1 + m*recipe[3] + n2 = n2 + m*recipe[3] + end end -- for - return n + return n1,n2,approx end -- function -- Find the first tradeskill index of the recipe to make an item