Mercurial > wow > itemauditor
diff Modules/Utils.lua @ 7:bbba2fae0f69
Removed some of the extra debugging that isn't neccessary any more and abtracted out the item ids so they can be cached.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Tue, 08 Jun 2010 11:19:16 -0700 |
parents | 5dddd73b2220 |
children | 0271e781b154 |
line wrap: on
line diff
--- a/Modules/Utils.lua Wed May 26 22:41:47 2010 -0700 +++ b/Modules/Utils.lua Tue Jun 08 11:19:16 2010 -0700 @@ -14,6 +14,35 @@ return prefix .. Altoholic:GetMoneyString(abs(money), WHITE, false) end + -- This is only here to make sure this doesn't blow up if ReplaceItemCache is never called +local item_db = {} + +function addon:ReplaceItemCache(new_cache) + item_db = new_cache +end + +-- This will be reset every session +local tmp_item_cache = {} +function addon:GetItemID(itemName) + if item_db[itemName] ~= nil then + return item_db[itemName] + end + + if tmp_item_cache[itemName] == nil then + local _, itemLink = GetItemInfo (itemName); + if itemLink ~= nil 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 + + return tmp_item_cache[itemName] +end + +function addon:SaveItemID(itemName, id) + item_db[itemName] = tonumber(id) +end + local SubjectPatterns = { AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"), AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"),