changeset 116:7ce304c296b0

Display then number of makable items instead of the number of times the recipe is craftable
author contrebasse
date Wed, 15 Jun 2011 01:14:00 +0200
parents 5a3fb8fea026
children e6bb47c6d8d6
files ReagentMaker.lua utils.lua
diffstat 2 files changed, 34 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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