Fix problem with shopping list

katkat42 [11-29-14 - 04:59]
Fix problem with shopping list
Filename
Provisioning.lua
SousChef.lua
Utility.lua
diff --git a/Provisioning.lua b/Provisioning.lua
index 48c4b29..44df00a 100644
--- a/Provisioning.lua
+++ b/Provisioning.lua
@@ -67,8 +67,8 @@ function SousChef:HookRecipeTreeFunction()
             function(...)
                 local node, control, data, open, userRequested, enabled = ...
                 SousChef.hookedProvisioningFunction(...)
-                local link = GetItemLinkName(GetRecipeResultItemLink(data.recipeListIndex, data.recipeIndex, LINK_STYLE_BRACKETS))
-                if link then
+                local link = u.GetColoredLinkName(GetRecipeResultItemLink(data.recipeListIndex, data.recipeIndex))
+                if link ~= "" then
                     SousChef:AddNotifier(control, type(SousChef.settings.shoppingList[link]) == "table" and u.TableKeyConcat(SousChef.settings.shoppingList[link]))
                 end
             end
@@ -125,17 +125,17 @@ function SousChef:IsOnShoppingList(id)
 end

 function SousChef:MarkRecipe()
-    local link = GetItemLinkName(GetRecipeResultItemLink(PROVISIONER:GetSelectedRecipeListIndex(), PROVISIONER:GetSelectedRecipeIndex(), LINK_STYLE_BRACKETS))
+	local link = GetRecipeResultItemLink(PROVISIONER:GetSelectedRecipeListIndex(), PROVISIONER:GetSelectedRecipeIndex())
+	local coloredName = u.GetColoredLinkName(link)
+    if type(SousChef.settings.shoppingList[coloredName]) ~= "table" then SousChef.settings.shoppingList[coloredName]  = {} end

-    if type(SousChef.settings.shoppingList[link]) ~= "table" then SousChef.settings.shoppingList[link]  = {} end
-
-    if not SousChef.settings.shoppingList[link][GetUnitName("player")] then
-        SousChef.settings.shoppingList[link][GetUnitName("player")] = true -- we're now marked
+    if not SousChef.settings.shoppingList[coloredName][GetUnitName("player")] then
+        SousChef.settings.shoppingList[coloredName][GetUnitName("player")] = true -- we're now marked
     else
-        SousChef.settings.shoppingList[link][GetUnitName("player")] = nil -- we're now unmarked
+        SousChef.settings.shoppingList[coloredName][GetUnitName("player")] = nil -- we're now unmarked
 		-- if that was the last mark we just got rid of, then nil out the entire recipe entry
-		if NonContiguousCount(SousChef.settings.shoppingList[link]) == 0 then
-			SousChef.settings.shoppingList[link] = nil
+		if NonContiguousCount(SousChef.settings.shoppingList[coloredName]) == 0 then
+			SousChef.settings.shoppingList[coloredName] = nil
 		end
     end

diff --git a/SousChef.lua b/SousChef.lua
index fcc0923..f842a6e 100644
--- a/SousChef.lua
+++ b/SousChef.lua
@@ -10,7 +10,7 @@ Thanks to Ayantir for the French translations, and sirinsidiator for the German
 SousChef = {}
 SousChef.Utility = {}
 SousChef.Media = {}
-SousChef.version = "2.14"
+SousChef.version = "2.15"

 local SousChef = SousChef
 local u = SousChef.Utility
@@ -58,14 +58,6 @@ local typeIconLookup = {
 	["Vin"] = 14,
 }

-local colors = {
-	["green"] = "|c00ff00",
-	["blue"] = "|c0066ff",
-	["purple"] = "|c782ee6",
-	["white"] = "|cFFFFFF",
-	["ending"] = "|r",
-}
-
 -- FUNCTIONS
 -- AddRecipe(Cookbook, link) adds the linked recipe to the player cookbook if it isn't there already.
 local function AddRecipe(Cookbook, link)
@@ -104,18 +96,7 @@ function SousChef:ParseRecipes()
 				local _, _, ingredientCount, level, _, specialType = GetRecipeInfo(listIndex, recipeIndex)
 				-- store the recipe's index numbers and number of ingredients
 				local resultLink = GetRecipeResultItemLink(listIndex, recipeIndex)
-				local plainName = GetItemLinkName(resultLink)
-				local recipeColor = GetItemLinkQuality(resultLink)
-				local coloredName
-				if recipeColor == ITEM_QUALITY_MAGIC then -- green
-					coloredName = colors.green .. zo_strformat("<<t:1>>", plainName) .. colors.ending
-				elseif recipeColor == ITEM_QUALITY_ARCANE then -- blue
-					coloredName = colors.blue .. zo_strformat("<<t:1>>", plainName) .. colors.ending
-				elseif recipeColor == ITEM_QUALITY_ARTIFACT then -- purple
-					coloredName = colors.purple .. zo_strformat("<<t:1>>", plainName) .. colors.ending
-				else -- can't happen
-					coloredName = zo_strformat("<<t:1>>", plainName)
-				end
+				local coloredName = u.GetColoredLinkName(resultLink)
 				SousChef.CookbookIndex[coloredName] = {listIndex = listIndex, recipeIndex = recipeIndex, numIngredients = ingredientCount}
 				-- now, for every ingredient in the current recipe...
 				for ingredientIndex = 1, ingredientCount do
diff --git a/Utility.lua b/Utility.lua
index 0222cdd..3cd7e93 100644
--- a/Utility.lua
+++ b/Utility.lua
@@ -1,5 +1,13 @@
 local SousChef = SousChef
 local u =  SousChef.Utility
+local colors = {
+	["green"] = "|c00ff00",
+	["blue"] = "|c0066ff",
+	["purple"] = "|c782ee6",
+	["gold"] = "|cE6B800",
+	["white"] = "|cFFFFFF",
+	["ending"] = "|r",
+}

 function u.GetItemID(link)
     if link == "" or not link then return -1 end
@@ -7,6 +15,27 @@ function u.GetItemID(link)
 	return tonumber(itemid)
 end

+function u.GetColoredLinkName(link)
+	if link == nil or link == "" then return "" end
+	local plainName = GetItemLinkName(link)
+	local color = GetItemLinkQuality(link)
+	local coloredName
+	if color == ITEM_QUALITY_NORMAL then -- white
+		return colors.white .. zo_strformat("<<t:1>>", plainName) .. colors.ending
+	elseif color == ITEM_QUALITY_MAGIC then -- green
+		return colors.green .. zo_strformat("<<t:1>>", plainName) .. colors.ending
+	elseif color == ITEM_QUALITY_ARCANE then -- blue
+		return colors.blue .. zo_strformat("<<t:1>>", plainName) .. colors.ending
+	elseif color == ITEM_QUALITY_ARTIFACT then -- purple
+		return colors.purple .. zo_strformat("<<t:1>>", plainName) .. colors.ending
+	elseif color == ITEM_QUALITY_LEGENDARY then -- gold
+		return colors.gold .. zo_strformat("<<t:1>>", plainName) .. colors.ending
+	else
+		return zo_strformat("<<t:1>>", plainName)
+	end
+	return coloredName
+end
+
 function u.EndsWith(String,End)
    return End=='' or string.sub(String,-string.len(End))==End
 end