Mercurial > wow > itemauditor
comparison Modules/Utils.lua @ 63:e7d287cc3b02
Replaced all instances of addon with ItemAuditor and I moved ItemAuditor out of the global namespace. The conversion was mostly a search/replace offering no new functionality. That will come in a later commit.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Tue, 27 Jul 2010 17:58:33 -0700 |
parents | bdf3aba93aa9 |
children | 32d53abee666 |
comparison
equal
deleted
inserted
replaced
62:70dc84df13b3 | 63:e7d287cc3b02 |
---|---|
1 local addonName, addonTable = ...; | 1 local ItemAuditor = select(2, ...) |
2 local addon = _G[addonName] | 2 local Utils = ItemAuditor:NewModule("Utils") |
3 | 3 |
4 function addon:FormatMoney(copper, color, textOnly) | 4 function ItemAuditor:FormatMoney(copper, color, textOnly) |
5 color = color or "|cFFFFFFFF" | 5 color = color or "|cFFFFFFFF" |
6 local prefix = "" | 6 local prefix = "" |
7 if copper < 0 then | 7 if copper < 0 then |
8 prefix = "-" | 8 prefix = "-" |
9 copper = abs(copper) | 9 copper = abs(copper) |
65 end | 65 end |
66 | 66 |
67 -- This is only here to make sure this doesn't blow up if ReplaceItemCache is never called | 67 -- This is only here to make sure this doesn't blow up if ReplaceItemCache is never called |
68 local item_db = {} | 68 local item_db = {} |
69 | 69 |
70 function addon:ReplaceItemCache(new_cache) | 70 function ItemAuditor:ReplaceItemCache(new_cache) |
71 item_db = new_cache | 71 item_db = new_cache |
72 end | 72 end |
73 | 73 |
74 -- This will be reset every session | 74 -- This will be reset every session |
75 local tmp_item_cache = {} | 75 local tmp_item_cache = {} |
76 function addon:GetItemID(itemName) | 76 function ItemAuditor:GetItemID(itemName) |
77 if item_db[itemName] ~= nil then | 77 if item_db[itemName] ~= nil then |
78 return item_db[itemName] | 78 return item_db[itemName] |
79 end | 79 end |
80 | 80 |
81 if tmp_item_cache[itemName] == nil then | 81 if tmp_item_cache[itemName] == nil then |
98 end | 98 end |
99 | 99 |
100 return tmp_item_cache[itemName] | 100 return tmp_item_cache[itemName] |
101 end | 101 end |
102 | 102 |
103 function addon:GetLinkFromName(itemName) | 103 function ItemAuditor:GetLinkFromName(itemName) |
104 local itemID = self:GetItemID(itemName) | 104 local itemID = self:GetItemID(itemName) |
105 local itemLink | 105 local itemLink |
106 if itemID ~= nil then | 106 if itemID ~= nil then |
107 _, itemLink = GetItemInfo(itemID) | 107 _, itemLink = GetItemInfo(itemID) |
108 end | 108 end |
109 | 109 |
110 return itemLink | 110 return itemLink |
111 end | 111 end |
112 | 112 |
113 function addon:SaveItemID(itemName, id) | 113 function ItemAuditor:SaveItemID(itemName, id) |
114 item_db[itemName] = tonumber(id) | 114 item_db[itemName] = tonumber(id) |
115 end | 115 end |
116 | 116 |
117 addon.SubjectPatterns = { | 117 ItemAuditor.SubjectPatterns = { |
118 AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"), | 118 AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"), |
119 AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"), | 119 AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"), |
120 AHOutbid = gsub(AUCTION_OUTBID_MAIL_SUBJECT, "%%s", ".*"), | 120 AHOutbid = gsub(AUCTION_OUTBID_MAIL_SUBJECT, "%%s", ".*"), |
121 AHSuccess = gsub(AUCTION_SOLD_MAIL_SUBJECT, "%%s", ".*"), | 121 AHSuccess = gsub(AUCTION_SOLD_MAIL_SUBJECT, "%%s", ".*"), |
122 AHWon = gsub(AUCTION_WON_MAIL_SUBJECT, "%%s", ".*"), | 122 AHWon = gsub(AUCTION_WON_MAIL_SUBJECT, "%%s", ".*"), |
123 CODPayment = gsub(COD_PAYMENT, "%%s", "(.*)"), | 123 CODPayment = gsub(COD_PAYMENT, "%%s", "(.*)"), |
124 } | 124 } |
125 | 125 |
126 function addon:GetMailType(msgSubject) | 126 function ItemAuditor:GetMailType(msgSubject) |
127 if msgSubject then | 127 if msgSubject then |
128 for k, v in pairs(self.SubjectPatterns) do | 128 for k, v in pairs(self.SubjectPatterns) do |
129 if msgSubject:find(v) then return k end | 129 if msgSubject:find(v) then return k end |
130 end | 130 end |
131 end | 131 end |
132 return "NonAHMail" | 132 return "NonAHMail" |
133 end | 133 end |
134 | 134 |
135 function addon:tcount(tab) | 135 function ItemAuditor:tcount(tab) |
136 local n = #tab | 136 local n = #tab |
137 if (n == 0) then | 137 if (n == 0) then |
138 for _ in pairs(tab) do | 138 for _ in pairs(tab) do |
139 n = n + 1 | 139 n = n + 1 |
140 end | 140 end |
141 end | 141 end |
142 return n | 142 return n |
143 end | 143 end |
144 | 144 |
145 function addon:GetDebug(info) | 145 function ItemAuditor:GetDebug(info) |
146 return self.db.char.debug | 146 return self.db.char.debug |
147 end | 147 end |
148 | 148 |
149 function addon:SetDebug(info, input) | 149 function ItemAuditor:SetDebug(info, input) |
150 | 150 |
151 ItemAuditor.db.char.debug = input | 151 ItemAuditor.db.char.debug = input |
152 local value = "off" | 152 local value = "off" |
153 if input then | 153 if input then |
154 value = "on" | 154 value = "on" |