diff Modules/Utils.lua @ 9:374dd1a90d02

Changed the way things are stored so that items known only by name, usually from AH mail, will be stored by their name, but will get converted if the link is discovered through a tooltip. This version is funcioning again
author Asa Ayers <Asa.Ayers@Gmail.com>
date Fri, 25 Jun 2010 01:17:58 -0700
parents 0271e781b154
children 03e2d9edc344
line wrap: on
line diff
--- a/Modules/Utils.lua	Wed Jun 23 23:47:48 2010 -0700
+++ b/Modules/Utils.lua	Fri Jun 25 01:17:58 2010 -0700
@@ -5,6 +5,7 @@
 AceConsole:Embed(addon)
 
 addonTable.utils = addon
+IAUtils = addon
 
 function addon:FormatMoney(money)
 	local prefix = ""
@@ -36,9 +37,30 @@
 		end
 	end
 	
+	if tmp_item_cache[itemName] == nil then
+		for link, data in pairs(ItemAuditor.db.factionrealm.items) do
+			local name, itemLink = GetItemInfo (link);
+			if name == itemName then
+				local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
+				tmp_item_cache[itemName] = tonumber(itemID)
+			end
+		end
+		
+	end
+	
 	return tmp_item_cache[itemName]
 end
 
+function addon:GetLinkFromName(itemName)
+	local itemID = self:GetItemID(itemName)
+	local itemLink
+	if itemID ~= nil then
+		_, itemLink = GetItemInfo(itemID)
+	end
+	
+	return itemLink
+end
+
 function addon:SaveItemID(itemName, id)
 	item_db[itemName] = tonumber(id)
 end
@@ -71,17 +93,7 @@
    return n
 end
 
-function addon:GetSafeLink(link)
-	if link ~= string.match(link, '.-:[-0-9]+[:0-9]*') then
-		link = link and string.match(link, "|H(.-):([-0-9]+):([0-9]+)|h")
-	end
-	return link and string.gsub(link, ":0:0:0:0:0:0", "")
-end
 
-function addon:GetIDFromLink(link)
-	local _, _, _, _, Id = string.find(link, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
-	return tonumber(Id)
-end
 
 function addon:GetDebug(info)
 	return true