changeset 70:32ec6417874a

Change the internal data format (not done yet for the external window)
author contrebasse
date Sat, 14 May 2011 20:19:22 +0200
parents 0675410645de
children 4f9fd025112b
files MillingData.lua ProspectingData.lua ReagentMaker.lua data.lua utils.lua
diffstat 5 files changed, 101 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/MillingData.lua	Sat May 14 16:56:17 2011 +0200
+++ b/MillingData.lua	Sat May 14 20:19:22 2011 +0200
@@ -132,8 +132,11 @@
 local macroMill = "/cast "..GetSpellInfo(MillID).."\n/use %s"
 local MillLink = GetSpellLink(MillID)
 
-for k,v in pairs(A.MillingData) do
-	v.spell = macroMill
-	v.spellID = MillID
-	v.spellLink = MillLink
+-- Add "Tradeskill" data to each "recipe"
+for itemID,t in pairs(A.MillingData) do
+	for i,v in ipairs(t) do
+		v.macro = macroMill
+		v.spellID = MillID
+		v.spellLink = MillLink
+	end
 end
--- a/ProspectingData.lua	Sat May 14 16:56:17 2011 +0200
+++ b/ProspectingData.lua	Sat May 14 20:19:22 2011 +0200
@@ -57,8 +57,11 @@
 local macroProspect = "/cast "..GetSpellInfo(ProspectID).."\n/use %s"
 local ProspectLink = GetSpellLink(ProspectID)
 
-for k,v in pairs(A.ProspectingData) do
-	v.spell = macroProspect
-	v.spellID = ProspectID
-	v.spellLink = ProspectLink
+-- Add "Tradeskill" data to each "recipe"
+for itemID,t in pairs(A.ProspectingData) do
+	for i,v in ipairs(t) do
+		v.macro = macroProspect
+		v.spellID = ProspectID
+		v.spellLink = ProspectLink
+	end
 end
--- a/ReagentMaker.lua	Sat May 14 16:56:17 2011 +0200
+++ b/ReagentMaker.lua	Sat May 14 20:19:22 2011 +0200
@@ -126,7 +126,7 @@
 	if not reagentID or not A.data[reagentID] then return end
 
 	-- If only one recipe is known for the reagent, use it
-	if #(A.data[reagentID]) == 1 and not A.data[reagentID].spell then
+	if #(A.data[reagentID]) == 1 and not A.data[reagentID][1].macro then
 		local numMakable, reagentIndex = A.numMakable(reagentID)
 		if not numMakable then
 			A.Error(L["The recipe to make the reagent seems to be hidden, it is not makable."])
@@ -139,7 +139,7 @@
 
 		-- If we can make the item needed to make the reagent, open a window to make it
 		-- one step recursion, enables to mill to create an ink
-		if (not A.data[reagentID].manyReagents) and A.data[A.data[reagentID][1][1]] then
+		if (not A.data[reagentID][1].manyReagents) and A.data[A.data[reagentID][1][1]] then
 			A.externalCraftWindow(A.data[reagentID][1][1],reagentID)
 		else
 			A.Error(L["You do not have enough reagents to craft [%s]"]:format(GetItemInfo(reagentID) or "item #"..reagentID))
@@ -214,17 +214,28 @@
 
 	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
+
 	-- Tooltips
-	local link = A.data[reagentID].spellLink
+	local link = A.data[reagentID][1].spellLink
 	if link then
 		A.tooltipRecipe:SetOwner(btn)
 		A.tooltipRecipe:SetHyperlink(link)
 		A.tooltipRecipe:Show()
 		A.tooltipRecipe:ClearAllPoints()
 		A.tooltipRecipe:SetPoint("BOTTOMLEFT",GameTooltip,"BOTTOMRIGHT")
-	else
-		-- Shouldn't happend, but just in case...
-		A.Error(L["Recipe link not found for %s"]:format(reagentID))
 	end
 end
 
@@ -240,7 +251,11 @@
 	-- Do not manage guild tradeskill
 	if IsTradeSkillGuild() or IsTradeSkillLinked() then
 		for reagentRecipeIndex = 1,GetTradeSkillNumReagents(recipeIndex) do
-			_G["TradeSkillReagent"..reagentRecipeIndex].label:Hide()
+			-- If the normal tradeskill hasn't been opened yet, the field 'label' doesn't exists yet
+			local label = _G["TradeSkillReagent"..reagentRecipeIndex].label
+			if label then
+				label:Hide()
+			end
 		end
 		return
 	end
@@ -252,19 +267,24 @@
 		local reagentID = A.link2ID(reagentLink)
 
 		local label = _G["TradeSkillReagent"..reagentRecipeIndex].label
-		if not label then return end
+		if not label then break end -- Shouldn't happen...
 
 		-- Continue only if the reagent is known
-		if not reagentID or not A.data[reagentID] or #(A.data[reagentID]) ~= 1 or A.data[reagentID].spell then
+		if not reagentID or not A.data[reagentID] then
 			label:Hide()
 		else
 			-- Count and show
 			local numMakable = A.numMakable(reagentID)
-			label:SetText(numMakable or "?")
-			if not numMakable or numMakable==0 then
-				label:SetTextColor(1, 0, 0, 1)
+			if not numMakable or #(A.data[reagentID]) ~= 1 or A.data[reagentID][1].macro then
+				label:SetText("?")
+				label:SetTextColor(0, 0.5, 1, 1) -- blue
 			else
-				label:SetTextColor(0, 5, 0, 1)
+				label:SetText(numMakable)
+				if numMakable==0 then
+					label:SetTextColor(1, 0, 0, 1) -- red
+				else
+					label:SetTextColor(0, 1, 0, 1) -- green
+				end
 			end -- if
 			label:Show()
 		end -- if
--- a/data.lua	Sat May 14 16:56:17 2011 +0200
+++ b/data.lua	Sat May 14 20:19:22 2011 +0200
@@ -38,16 +38,18 @@
 		if NRecipes==0 or select(2,GetTradeSkillInfo(1))~="header" then
 			return
 		end
+		
+		tradeskillID = GetTradeSkillLine()
 
 		-- Check if the pseudo tradeskills have to be added
-		if GetTradeSkillLine() == GetSpellInfo(25229) then -- Jewelcrafting
+		if tradeskillID == GetSpellInfo(25229) then -- Jewelcrafting
 			if not A.ProspectingDataLoaded then
 				for itemID,data in pairs(A.ProspectingData) do
 					A.data[itemID] = data
 				end
 				A.ProspectingDataLoaded = true
 			end
-		elseif GetTradeSkillLine() == GetSpellInfo(45357) then -- Inscription
+		elseif tradeskillID == GetSpellInfo(45357) then -- Inscription
 			if not A.MillingDataLoaded then
 				for itemID,data in pairs(A.MillingData) do
 					A.data[itemID] = data
@@ -57,61 +59,66 @@
 		end
 
 		for i = 2,NRecipes do -- The first one is a header
-			local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(i)
-			if skillType ~= "header" then
-				--if GetTradeSkillNumReagents(i) == 1 then
-					-- item ID
-					local itemID = A.link2ID(GetTradeSkillItemLink(i))
+			-- skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(index)
+			-- serviceType is nil if the recipe creates an item
+			local _, skillType, _, _, serviceType = GetTradeSkillInfo(i)
+			if skillType and skillType ~= "header" and serviceType==nil then
+				-- item ID
+				local itemID = A.link2ID(GetTradeSkillItemLink(i))
 
-					-- reagent ID, valid only if there's only one reagent as we take only the first one
-					local reagentID = A.link2ID(GetTradeSkillReagentItemLink(i, 1))
+				-- reagent ID, valid only if there's only one reagent as we take only the first one
+				local reagentID = A.link2ID(GetTradeSkillReagentItemLink(i, 1))
 
-					-- reagent number needed
-					local _, _, reagentCount, _ = GetTradeSkillReagentInfo(i, 1)
+				-- reagent number needed
+				local _, _, reagentCount, _ = GetTradeSkillReagentInfo(i, 1)
 
-					-- number of reagent created by the recipe
-					local minMade, maxMade = GetTradeSkillNumMade(i)
+				-- number of reagent created by the recipe
+				local minMade, maxMade = GetTradeSkillNumMade(i)
 
-					-- recipe link (for tooltips)
-					local recipeLink = GetTradeSkillRecipeLink(i)
+				-- recipe link (for tooltips)
+				local recipeLink = GetTradeSkillRecipeLink(i)
 
-					-- error checking
-					if not reagentID or not reagentCount or not skillName or not itemID or not minMade or not maxMade or not recipeLink then
-						--@debug@
-						print("Erreur de scan :",itemID,skillName,reagentID,reagentCount,minMade,maxMade,recipeLink)
-						--@end-debug@
+				-- error checking
+				if itemID and reagentID and reagentCount and minMade and maxMade and recipeLink then
+					-- remove unneeded minMade/maxMade
+					if maxMade==minMade then
+						maxMade = nil
+						if minMade==1 then
+							minMade = nil
+						end -- if
+					end -- if
 
-					else -- Zap incomplete recipes, they will be scanned later
-						-- remove unneeded minMade/maxMade
-						if maxMade==minMade then
-							maxMade = nil
-							if minMade==1 then
-								minMade = nil
-							end -- if
-						end -- if
-
-						-- skillName or...???
-						-- There's still a problem when multiple recipes craft the same item
-						if not A.data[itemID] then
-							A.data[itemID] = {}
-						end -- if
-						local newSpell = true
+					-- As we scan multiple times, check if this recipe is already stored
+					local addSpell	= true
+					if not A.data[itemID] then
+						A.data[itemID] = {}
+					else
 						for _,v in ipairs(A.data[itemID]) do
-							if v.spellName==skillName then
-								newSpell = nil
+							if v.spellLink==recipeLink then
+								addSpell = nil
 								break
 							end -- if
 						end -- for
-						if newSpell then
-							A.data[itemID].spellLink = recipeLink
-							A.data[itemID].manyReagents = A.data[itemID].manyReagents or GetTradeSkillNumReagents(i)>1
-							tinsert(A.data[itemID],{reagentID,reagentCount,minMade,maxMade,spellName=skillName})
-						end -- if
 					end -- if
-				--end -- if
+				
+					-- Cache the data
+					if addSpell then
+						local spell = {reagentID,reagentCount,minMade,maxMade}
+						spell.spellID = tradeskillID
+						spell.spellLink = recipeLink
+						spell.manyReagents = GetTradeSkillNumReagents(i)>1
+						tinsert(A.data[itemID],spell)
+					end
+
+				else -- Zap incomplete recipes, they will be scanned later
+					--@debug@
+					print("Erreur de scan :",itemID,reagentID,reagentCount,minMade,maxMade,recipeLink)
+					--@end-debug@
+				end -- if
 			end -- if
 		end -- for
 
+		zzz = A.data
 		-- the scanning is complete
 		return true
 	end -- function
--- a/utils.lua	Sat May 14 16:56:17 2011 +0200
+++ b/utils.lua	Sat May 14 20:19:22 2011 +0200
@@ -56,14 +56,12 @@
 	-- 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)
+			local skillName, skillType = 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
+				local ID = A.link2ID(GetTradeSkillItemLink(i))
+				if ID and ID == itemID then
+					return i
 				end -- if
 			end -- if
 		end -- for