comparison 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
comparison
equal deleted inserted replaced
8:0271e781b154 9:374dd1a90d02
3 3
4 local AceConsole = LibStub("AceConsole-3.0") 4 local AceConsole = LibStub("AceConsole-3.0")
5 AceConsole:Embed(addon) 5 AceConsole:Embed(addon)
6 6
7 addonTable.utils = addon 7 addonTable.utils = addon
8 IAUtils = addon
8 9
9 function addon:FormatMoney(money) 10 function addon:FormatMoney(money)
10 local prefix = "" 11 local prefix = ""
11 if money < 0 then 12 if money < 0 then
12 prefix = "-" 13 prefix = "-"
34 local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?") 35 local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
35 tmp_item_cache[itemName] = tonumber(itemID) 36 tmp_item_cache[itemName] = tonumber(itemID)
36 end 37 end
37 end 38 end
38 39
40 if tmp_item_cache[itemName] == nil then
41 for link, data in pairs(ItemAuditor.db.factionrealm.items) do
42 local name, itemLink = GetItemInfo (link);
43 if name == itemName then
44 local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
45 tmp_item_cache[itemName] = tonumber(itemID)
46 end
47 end
48
49 end
50
39 return tmp_item_cache[itemName] 51 return tmp_item_cache[itemName]
52 end
53
54 function addon:GetLinkFromName(itemName)
55 local itemID = self:GetItemID(itemName)
56 local itemLink
57 if itemID ~= nil then
58 _, itemLink = GetItemInfo(itemID)
59 end
60
61 return itemLink
40 end 62 end
41 63
42 function addon:SaveItemID(itemName, id) 64 function addon:SaveItemID(itemName, id)
43 item_db[itemName] = tonumber(id) 65 item_db[itemName] = tonumber(id)
44 end 66 end
69 end 91 end
70 end 92 end
71 return n 93 return n
72 end 94 end
73 95
74 function addon:GetSafeLink(link)
75 if link ~= string.match(link, '.-:[-0-9]+[:0-9]*') then
76 link = link and string.match(link, "|H(.-):([-0-9]+):([0-9]+)|h")
77 end
78 return link and string.gsub(link, ":0:0:0:0:0:0", "")
79 end
80 96
81 function addon:GetIDFromLink(link)
82 local _, _, _, _, Id = string.find(link, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
83 return tonumber(Id)
84 end
85 97
86 function addon:GetDebug(info) 98 function addon:GetDebug(info)
87 return true 99 return true
88 -- return self.db.char.debug 100 -- return self.db.char.debug
89 end 101 end