Quantcast

Minor fixes in incorrect usage of string.split().

pschifferer [11-01-09 - 15:27]
Minor fixes in incorrect usage of string.split().
Added a color map to use when the built-in tradeskill color map is not initialized.
Made the recipe checker use ID instead of string comparison.
Filename
CauldronMain.lua
CauldronTradeskill.lua
CauldronUtil.lua
diff --git a/CauldronMain.lua b/CauldronMain.lua
index 8c7c24b..eca671d 100644
--- a/CauldronMain.lua
+++ b/CauldronMain.lua
@@ -945,7 +945,6 @@ function Cauldron:AddToTooltip(tooltip, id)
 	-- add favorite info
 	local favSkills = filterFavoriteSkills(skillList);
 	if favSkills and #favSkills > 0 then
-		local color = "|cffffffff";
 		local favInfo = "";
 		if #favSkills > 3 then
 			-- if the skill list has more than 3 items, summarize
@@ -954,26 +953,35 @@ function Cauldron:AddToTooltip(tooltip, id)
 			-- if the skill list is 3 or less, list all
 			favInfo = L["Needed for favorites: "];
 			for i,skill in ipairs(favSkills) do
-				local skillName,skillLink = string.split(skill, ";", 2);
+				local skillName,skillLink = string.split(";", skill, 2);
 				if i > 1 then
-					favInfo = favInfo.."|cffffffff, |r";
+					favInfo = favInfo..", ";
 				end
-				local skillInfo = Cauldron:GetSkillForLink(skillLink);
-				local color = TradeSkillTypeColor[skillInfo.difficulty];
-				local colorStr = "ffffff";
+				local skillInfo = Cauldron:GetSkillInfoForLink(skillLink);
+				local color;
+				if TradeSkillTypeColor then
+					color = TradeSkillTypeColor[skillInfo.difficulty];
+				else
+					local colorMap = {
+						optimal = {r=1.0, g=0.5, b=0.25},
+						medium = {r=1.0, g=1.0, b=0.0},
+						easy = {r=0.25, g=0.75, b=0.25},
+					};
+					color = colorMap[skillInfo.difficulty];
+				end
+				local colorStr = "|r";
 				if color then
-					string.format("%02x%02x%02x", color.r, color.g, color.b);
+					colorStr = string.format("|cff%02x%02x%02x", (color.r*255), (color.g*255), (color.b*255));
 				end
-				favInfo = favInfo.."|cff"..colorStr..skillInfo.name.."|r";
+				favInfo = favInfo..colorStr..skillInfo.name.."|r";
 			end
 		end
-		tooltip:AddLine(color..favInfo.."|r");
+		tooltip:AddLine("|r"..favInfo.."|r");
 	end

 	-- add skill-up info
 	local skillups = filterSkillups(skillList);
 	if skillups and #skillups > 0 then
-		local color = "|cffffffff";
 		local levelInfo = "";
 		if #skillups > 3 then
 			-- if the skill list has more than 3 items, summarize
@@ -982,20 +990,25 @@ function Cauldron:AddToTooltip(tooltip, id)
 			-- if the skill list is 3 or less, list all
 			levelInfo = L["Needed for leveling: "];
 			for i,skill in ipairs(skillups) do
-				local skillName,skillLink = string.split(skill, ";", 2);
+				local skillName,skillLink = string.split(";", skill, 2);
 				if i > 1 then
-					levelInfo = levelInfo.."|cffffffff, |r";
+					levelInfo = levelInfo..", ";
+				end
+				local skillInfo = Cauldron:GetSkillInfoForLink(skillLink);
+				local color;
+				if TradeSkillTypeColor then
+					color = TradeSkillTypeColor[skillInfo.difficulty];
+--				else
+--					color = {r=1.0, g=1.0, b=1.0};
 				end
-				local skillInfo = Cauldron:GetSkillForLink(skillLink);
-				local color = TradeSkillTypeColor[skillInfo.difficulty];
-				local colorStr = "ffffff";
+				local colorStr = "|r";
 				if color then
-					string.format("%02x%02x%02x", color.r, color.g, color.b);
+					colorStr = string.format("|cff%02x%02x%02x", (color.r*255), (color.g*255), (color.b*255));
 				end
-				levelInfo = levelInfo.."|cff"..colorStr..skillInfo.name.."|r";
+				levelInfo = levelInfo..colorStr..skillInfo.name.."|r";
 			end
 		end
-		tooltip:AddLine(color..levelInfo.."|r");
+		tooltip:AddLine("|r"..levelInfo.."|r");
 	end
 end

@@ -1008,8 +1021,8 @@ function filterFavoriteSkills(skillList)
 	local faves = {};

 	for i,skill in ipairs(skillList) do
-		local skillName, skillLink = string.split(skill, ";", 2);
-		local skillInfo = Cauldron:GetSkillForLink(skillLink);
+		local skillName, skillLink = string.split(";", skill, 2);
+		local skillInfo = Cauldron:GetSkillInfoForLink(skillLink);

 		if skillInfo and skillName then
 			if Cauldron.db.realm.userdata[Cauldron.vars.playername].skills[skillName] then
@@ -1041,8 +1054,8 @@ function filterSkillups(skillList)
 	};

 	for i,skill in ipairs(skillList) do
-		local skillName, skillLink = string.split(skill, ";", 2);
-		local skillInfo = Cauldron:GetSkillForLink(skillLink);
+		local skillName, skillLink = string.split(";", skill, 2);
+		local skillInfo = Cauldron:GetSkillInfoForLink(skillLink);

 		if skillInfo then
 			if difficulty[skillInfo.difficulty] > 1 then
diff --git a/CauldronTradeskill.lua b/CauldronTradeskill.lua
index c782527..a951aae 100644
--- a/CauldronTradeskill.lua
+++ b/CauldronTradeskill.lua
@@ -533,7 +533,9 @@ function Cauldron:GetSkillInfoForLink(recipeLink)
 		-- skip linked skills
 		if not (string.find(tradeskill, "Linked-")) then
 			for _, recipeInfo in pairs(list.recipes) do
-				if recipeLink == recipeInfo.recipeLink then
+				local id = Cauldron:GetIdFromLink(recipeLink);
+				local recipeId = Cauldron:GetIdFromLink(recipeInfo.recipeLink);
+				if id == recipeId then
 					return recipeInfo;
 				end
 			end
diff --git a/CauldronUtil.lua b/CauldronUtil.lua
index b436d71..92b9ed1 100644
--- a/CauldronUtil.lua
+++ b/CauldronUtil.lua
@@ -134,7 +134,7 @@ function Cauldron:GetIdFromLink(link)
   	if not id then
 --  	local _,_,id,name = strfind(link,"|Henchant:(%d+)|h%[(.+)%]")
   		local _,_,id = strfind(link,"enchant:(%d+)")
-	  	if id then return -tonumber(id) end
+	  	if id then return tonumber(id) end
 	else
 		return tonumber(id)
 	end