Quantcast

Refactored how skill information is stored. Now, only the base skill is stored, with some other

pschifferer [01-25-09 - 16:28]
Refactored how skill information is stored.  Now, only the base skill is stored, with some other
metadata, and reagent info is queried from PeriodicTable as needed.  This also has a noticeable
speed improvement when opening the main window.
Reinstated tooltips for queue items.
Filename
CauldronMain.xml
CauldronMainUI.lua
CauldronQueue.lua
CauldronTradeskill.lua
CauldronUtil.lua
diff --git a/CauldronMain.xml b/CauldronMain.xml
index d1bb075..a501f81 100644
--- a/CauldronMain.xml
+++ b/CauldronMain.xml
@@ -28,7 +28,7 @@
 		<Scripts>
 			<OnEnter>
 				GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT");
-				GameTooltip:SetTradeSkillItem(self.skillIndex, self.reagentIndex);
+				GameTooltip:SetHyperlink(self.link);
 				CursorUpdate(self);
 			</OnEnter>
 			<OnLeave>
@@ -39,7 +39,7 @@
 				CursorOnUpdate(self);
 			</OnUpdate>
 			<OnClick>
-				HandleModifiedItemClick(GetTradeSkillReagentItemLink(self.skillIndex, self.reagentIndex));
+				HandleModifiedItemClick(self.link);
 			</OnClick>
 		</Scripts>
 	</Button>
@@ -337,13 +337,11 @@
 						-- self.hasItem = 1;
 					</OnLoad>
 					<OnClick>
-						-- HandleModifiedItemClick(GetTradeSkillItemLink(TradeSkillFrame.selectedSkill));
+						HandleModifiedItemClick(self.link);
 					</OnClick>
 					<OnEnter>
 						GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
-						if self.link then
-							GameTooltip:SetHyperlink(self.link);
-						end
+						GameTooltip:SetHyperlink(self.link);
 						CursorUpdate(self);
 					</OnEnter>
 					<OnLeave>
@@ -353,9 +351,7 @@
 					<OnUpdate>
 						if GameTooltip:IsOwned(self) then
 							GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
-							if self.link then
-								GameTooltip:SetHyperlink(self.link);
-							end
+							GameTooltip:SetHyperlink(self.link);
 							CursorUpdate(self);
 						end
 						CursorOnUpdate(self);
@@ -538,6 +534,9 @@
 			</Button>
     	</Frames>
     	<Scripts>
+    		<OnClick>
+				HandleModifiedItemClick(self.link);
+    		</OnClick>
     		<OnEnter>
     			if self.removeable then
     				_G[self:GetName().."RemoveItem"]:Show();
diff --git a/CauldronMainUI.lua b/CauldronMainUI.lua
index 09eb7af..5969975 100644
--- a/CauldronMainUI.lua
+++ b/CauldronMainUI.lua
@@ -299,7 +299,10 @@ function Cauldron:UpdateSkillList()

 			-- fill in the reagents
 			_G["CauldronSkillItem"..i.."Reagents"]:SetScale(0.86);
-			local reagentCount = #skillInfo.reagents;
+
+			-- get reagents table
+			local reagents = self:GetReagentsForSkill(skillInfo);
+			local reagentCount = #reagents;

 			for j=1,8 do
 				local reagentFrame = _G["CauldronSkillItem"..i.."ReagentsItemDetail"..j];
@@ -307,10 +310,11 @@ function Cauldron:UpdateSkillList()
 				if j > reagentCount then
 					reagentFrame:Hide();
 				else
-					local reagentInfo = skillInfo.reagents[j];
+					local reagentInfo = reagents[j];

-					reagentFrame.skillIndex = skillInfo.index;
-					reagentFrame.reagentIndex = reagentInfo.index;
+--					reagentFrame.skillIndex = skillInfo.index;
+--					reagentFrame.reagentIndex = reagentInfo.index;
+					reagentFrame.link = reagentInfo.link;

 					local reagentNameFrame = _G["CauldronSkillItem"..i.."ReagentsItemDetail"..j.."Name"];
 					local reagentCountFrame = _G["CauldronSkillItem"..i.."ReagentsItemDetail"..j.."Count"];
@@ -646,7 +650,10 @@ function Cauldron:UpdateQueue()
 			if not skillInfo then
 				-- the skill isn't available (character doesn't know it?)
 				-- TODO
+				self:error("No skill info available for: "..queueInfo.name.."!");
 			end
+
+			queueItemFrame.link = skillInfo.recipeLink;

 			-- populate the frame
 			local frame = nil;
diff --git a/CauldronQueue.lua b/CauldronQueue.lua
index b6b3550..ad813f0 100644
--- a/CauldronQueue.lua
+++ b/CauldronQueue.lua
@@ -154,7 +154,7 @@ function CauldronQueue:AddItem(queue, skillInfo, amount, suppressCalc)
 		item.amount = item.amount + amount;
 	else
 		-- it's not there, so create a new instance
-		queue.main[skillInfo.name] = CauldronQueue:NewItem(skillInfo.name, skillInfo.icon, amount, nil, skillInfo.tradeskill);
+		queue.main[skillInfo.name] = CauldronQueue:NewItem(skillInfo.name, skillInfo.icon, amount, nil, skillInfo.tradeskill, skillInfo.itemLink);
 	end

 	if not suppressCalc then
@@ -242,7 +242,7 @@ function CauldronQueue:CalculateRequiredItems(queue, skillInfo, amount)
 	end

 	for i, reagent in ipairs(reagents) do
-		CauldronQueue:AddReagent(queue, reagent, reagent.numRequired, skillInfo.tradeskill);
+		CauldronQueue:AddReagent(queue, reagent, reagent.numRequired, skillInfo.tradeskill, reagent.link);
 	end

 end
@@ -270,7 +270,7 @@ function CauldronQueue:AddIntermediate(queue, reagent, amount)
 		local skillInfo = Cauldron:GetSkillInfoForItem(reagent.name);

 		-- it's not there, so create a new instance
-		queue.intermediate[reagent.name] = CauldronQueue:NewItem(reagent.name, reagent.icon, amount, nil, skillInfo.tradeskill);
+		queue.intermediate[reagent.name] = CauldronQueue:NewItem(reagent.name, reagent.icon, amount, nil, skillInfo.tradeskill, reagent.link);
 	end

 end
@@ -296,7 +296,7 @@ function CauldronQueue:AddReagent(queue, reagent, amount, tradeskill)
 		item.amount = (tonumber(item.amount) or 0) + amount;
 	else
 		-- it's not there, so create a new instance
-		queue.reagents[reagent.name] = CauldronQueue:NewReagent(reagent.name, reagent.icon, amount, tradeskill);
+		queue.reagents[reagent.name] = CauldronQueue:NewReagent(reagent.name, reagent.icon, amount, tradeskill, reagent.link);
 	end

 end
diff --git a/CauldronTradeskill.lua b/CauldronTradeskill.lua
index 82065dd..d5debb5 100644
--- a/CauldronTradeskill.lua
+++ b/CauldronTradeskill.lua
@@ -60,9 +60,10 @@ function Cauldron:UpdateSkills()
 --		self:debug("UpdateSkills: name="..name.."; difficulty="..difficulty.."; avail="..avail);

 		if name and difficulty ~= "header" then
-			local link = GetTradeSkillItemLink(i);
+			local itemLink = GetTradeSkillItemLink(i);
+			local recipeLink = GetTradeSkillRecipeLink(i);
 			local minMade, maxMade = GetTradeSkillNumMade(i);
-			local _, _, _, _, _, _, _, _, slot, _ = GetItemInfo(link);
+			local _, _, _, _, _, _, _, _, slot, _ = GetItemInfo(itemLink);

 			local keywords = name;

@@ -70,7 +71,8 @@ function Cauldron:UpdateSkills()
 			skillDB.recipes[name] = {
 				['index'] = i,
 				['name'] = name,
-				['link'] = link,
+				['itemLink'] = itemLink,
+				['recipeLink'] = recipeLink,
 				['icon'] = GetTradeSkillIcon(i),
 				['tradeskill'] = baseSkillName,
 				['difficulty'] = difficulty,
@@ -113,7 +115,8 @@ function Cauldron:UpdateSkills()

 			-- clear the reagent list
 			skillDB.recipes[name].reagents = {};
-
+
+--[[
 			for j=1,GetTradeSkillNumReagents(i) do
 				local rname, rtex, rcount, hasCount = GetTradeSkillReagentInfo(i,j);
 				self:debug("UpdateSkills: rname="..tostring(rname).."; rtex="..tostring(rtex).."; rcount="..tostring(rcount).."; hasCount="..tostring(hasCount));
@@ -131,6 +134,7 @@ function Cauldron:UpdateSkills()
 					keywords = keywords..","..rname;
 				end
 			end
+--]]

 			-- fill in the db entry
 			skillDB.recipes[name].keywords = keywords;
@@ -373,7 +377,7 @@ function Cauldron:GetSkillInfo(tradeskill, skill)
 		-- couldn't find a skill with the item name, so scan the list for skills that craft
 		-- the item
 		for _, recipe in pairs(self.db.realm.userdata[self.vars.playername].skills[tradeskill].recipes) do
-			local name, _ = GetItemInfo(recipe.link);
+			local name, _ = GetItemInfo(recipe.itemLink);
 			if name == skill then
 				return recipe;
 			end
@@ -391,7 +395,7 @@ function Cauldron:GetSkillInfoForItem(item)
 		-- skip linked skills
 		if not (string.find(tradeskill, "Linked-")) then
 			for _, recipeInfo in pairs(list.recipes) do
-				local name, _ = GetItemInfo(recipeInfo.link);
+				local name, _ = GetItemInfo(recipeInfo.itemLink);
 				if name == item then
 					return recipeInfo;
 				end
@@ -416,7 +420,7 @@ function Cauldron:GetRequiredItems(skillInfo, amount)
 	amount = math.max(1, tonumber(amount) or 1);

 	-- find out what the reagents are
-	for i, reagent in ipairs(skillInfo.reagents) do
+	for i, reagent in ipairs(Cauldron:GetReagentsForSkill(skillInfo)) do

 		-- copy the reagent info so we can modify the amounts
 		local r = CopyTable(reagent);
@@ -434,3 +438,53 @@ function Cauldron:GetRequiredItems(skillInfo, amount)
 	return intermediates, reagents;
 end

+local function split(sep, str)
+	local result = {};
+
+	while str do
+		local s1, rest = strsplit(sep, str, 2);
+		table.insert(result, s1);
+		str = rest;
+	end
+
+	return result;
+end
+
+function Cauldron:GetReagentsForSkill(skillInfo)
+
+	if not skillInfo then
+		self:error("No skill info provided!");
+		return {};
+	end
+
+	local reagents = {};
+
+	local itemId = self:GetIdFromLink(skillInfo.itemLink);
+
+	local reagentStr = self.libs.PT:ItemInSet(itemId, "TradeskillResultMats.Forward."..skillInfo.tradeskill);
+	if not reagentStr then
+		self:error("No reagents found for skill: "..skillInfo.name);
+		return {};
+	end
+
+	-- split the reagent info
+	for _, reagent in ipairs(split(";", reagentStr)) do
+		local id, numRequired = strsplit("x", reagent);
+
+		-- get item details for the reagent
+		local name, link, _, _, _, _, _, _, _, icon = GetItemInfo(id);
+
+		local r = {
+			["toonHas"] = GetItemCount(id),
+			["name"] = name,
+			["numRequired"] = tonumber(numRequired),
+			["skillIndex"] = skillInfo.index,
+			["icon"] = icon,
+			["link"] = link,
+		};
+
+		table.insert(reagents, r);
+	end
+
+	return reagents;
+end
diff --git a/CauldronUtil.lua b/CauldronUtil.lua
index ab6aaf4..ec8d5c9 100644
--- a/CauldronUtil.lua
+++ b/CauldronUtil.lua
@@ -82,3 +82,23 @@ function Cauldron:SkillContainsText(recipe, text)

 	return false;
 end
+
+function Cauldron:GetIdFromLink(link)
+  	if not link then return end
+--  local _,_,id,name = strfind(link,"|Hitem:(%d+):.+%[(.+)%]")
+  	local _,_,id = strfind(link,"item:(%d+):")
+  	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
+	else
+		return tonumber(id)
+	end
+end
+
+function Cauldron:GetNameFromLink(link)
+	if not link then return end
+  	local _,_,name = strfind(link,"|Hitem:.+%[(.+)%]")
+	return name
+end
+