comparison Core.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 4ec321eb0dfe
children 32d53abee666
comparison
equal deleted inserted replaced
62:70dc84df13b3 63:e7d287cc3b02
1 local addonName, addonTable = ...; 1 local ItemAuditor = select(2, ...)
2 _G[addonName] = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceEvent-3.0", "AceBucket-3.0") 2 ItemAuditor = LibStub("AceAddon-3.0"):NewAddon(ItemAuditor, "ItemAuditor", "AceEvent-3.0", "AceBucket-3.0")
3 local addon = _G[addonName]
4 addonTable.ItemAuditor = addon
5 3
6 local WHITE = "|cFFFFFFFF" 4 local WHITE = "|cFFFFFFFF"
7 local RED = "|cFFFF0000" 5 local RED = "|cFFFF0000"
8 local GREEN = "|cFF00FF00" 6 local GREEN = "|cFF00FF00"
9 local YELLOW = "|cFFFFFF00" 7 local YELLOW = "|cFFFFFF00"
10 local ORANGE = "|cFFFF7F00" 8 local ORANGE = "|cFFFF7F00"
11 local TEAL = "|cFF00FF9A" 9 local TEAL = "|cFF00FF9A"
12 local GOLD = "|cFFFFD700" 10 local GOLD = "|cFFFFD700"
13 11
14 function addon:OnInitialize() 12 function ItemAuditor:OnInitialize()
15 local DB_defaults = { 13 local DB_defaults = {
16 char = { 14 char = {
17 ah = 1, 15 ah = 1,
18 use_quick_auctions = false, 16 use_quick_auctions = false,
19 crafting_threshold = 1, 17 crafting_threshold = 1,
23 profile = { 21 profile = {
24 messages = { 22 messages = {
25 cost_updates = true, 23 cost_updates = true,
26 queue_skip = false, 24 queue_skip = false,
27 }, 25 },
28 addon_enabled = true, 26 ItemAuditor_enabled = true,
29 -- This is for development, so I have no plans to turn it into an option. 27 -- This is for development, so I have no plans to turn it into an option.
30 show_debug_frame_on_startup = false, 28 show_debug_frame_on_startup = false,
31 }, 29 },
32 factionrealm = { 30 factionrealm = {
33 item_account = {}, 31 item_account = {},
34 items = {}, 32 items = {},
35 outbound_cod = {}, 33 outbound_cod = {},
36 }, 34 },
37 } 35 }
38 self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true) 36 self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true)
39 addonTable.db= self.db
40 self.items = self.db.factionrealm.items 37 self.items = self.db.factionrealm.items
41 38
42 self:RegisterOptions() 39 self:RegisterOptions()
43 ItemAuditor:RegisterFrame(ItemAuditor_DebugFrame) 40 ItemAuditor:RegisterFrame(ItemAuditor_DebugFrame)
44 41
51 end) 48 end)
52 end 49 end
53 end 50 end
54 51
55 local registeredEvents = {} 52 local registeredEvents = {}
56 local originalRegisterEvent = addon.RegisterEvent 53 local originalRegisterEvent = ItemAuditor.RegisterEvent
57 function addon:RegisterEvent(event, callback, arg) 54 function ItemAuditor:RegisterEvent(event, callback, arg)
58 registeredEvents[event] = true 55 registeredEvents[event] = true
59 if arg ~= nil then 56 if arg ~= nil then
60 return originalRegisterEvent(self, event, callback, arg) 57 return originalRegisterEvent(self, event, callback, arg)
61 elseif callback ~= nil then 58 elseif callback ~= nil then
62 return originalRegisterEvent(self, event, callback) 59 return originalRegisterEvent(self, event, callback)
63 else 60 else
64 return originalRegisterEvent(self, event) 61 return originalRegisterEvent(self, event)
65 end 62 end
66 end 63 end
67 64
68 local originalUnregisterEvent = addon.UnregisterEvent 65 local originalUnregisterEvent = ItemAuditor.UnregisterEvent
69 function addon:UnregisterEvent(event) 66 function ItemAuditor:UnregisterEvent(event)
70 registeredEvents[event] = nil 67 registeredEvents[event] = nil
71 return originalUnregisterEvent(self, event) 68 return originalUnregisterEvent(self, event)
72 end 69 end
73 70
74 function addon:UnregisterAllEvents() 71 function ItemAuditor:UnregisterAllEvents()
75 for event in pairs(registeredEvents) do 72 for event in pairs(registeredEvents) do
76 self:UnregisterEvent(event) 73 self:UnregisterEvent(event)
77 end 74 end
78 end 75 end
79 76
80 local registeredFrames = {} 77 local registeredFrames = {}
81 function addon:RegisterFrame(frame) 78 function ItemAuditor:RegisterFrame(frame)
82 tinsert(registeredFrames, frame) 79 tinsert(registeredFrames, frame)
83 end 80 end
84 81
85 function addon:HideAllFrames() 82 function ItemAuditor:HideAllFrames()
86 for key, frame in pairs(registeredFrames) do 83 for key, frame in pairs(registeredFrames) do
87 if frame then 84 if frame then
88 frame:Hide() 85 frame:Hide()
89 end 86 end
90 end 87 end
91 end 88 end
92 89
93 function addon:ConvertItems() 90 function ItemAuditor:ConvertItems()
94 for itemName, value in pairs(self.db.factionrealm.item_account) do 91 for itemName, value in pairs(self.db.factionrealm.item_account) do
95 local itemID = self:GetItemID(itemName) 92 local itemID = self:GetItemID(itemName)
96 if itemID ~= nil then 93 if itemID ~= nil then
97 self:GetItem('item:' .. itemID) 94 self:GetItem('item:' .. itemID)
98 end 95 end
109 106
110 self:RefreshQAGroups() 107 self:RefreshQAGroups()
111 end 108 end
112 109
113 local printPrefix = "|cFFA3CEFFItemAuditor|r: " 110 local printPrefix = "|cFFA3CEFFItemAuditor|r: "
114 function addon:Print(message, ...) 111 function ItemAuditor:Print(message, ...)
115 message = format(message, ...) 112 message = format(message, ...)
116 self:GetSelectedChatWindow():AddMessage( printPrefix .. tostring(message)) 113 self:GetSelectedChatWindow():AddMessage( printPrefix .. tostring(message))
117 end 114 end
118 115
119 function addon:GetCurrentInventory() 116 function ItemAuditor:GetCurrentInventory()
120 local i = {} 117 local i = {}
121 local bagID 118 local bagID
122 local slotID 119 local slotID
123 120
124 for bagID = 0, NUM_BAG_SLOTS do 121 for bagID = 0, NUM_BAG_SLOTS do
134 131
135 end 132 end
136 return {items = i, money = GetMoney()} 133 return {items = i, money = GetMoney()}
137 end 134 end
138 135
139 function addon:GetInventoryDiff(pastInventory, current) 136 function ItemAuditor:GetInventoryDiff(pastInventory, current)
140 if current == nil then 137 if current == nil then
141 current = self:GetCurrentInventory() 138 current = self:GetCurrentInventory()
142 end 139 end
143 local diff = {} 140 local diff = {}
144 141
170 return {items = diff, money = moneyDiff} 167 return {items = diff, money = moneyDiff}
171 end 168 end
172 169
173 local inboundCOD = {} 170 local inboundCOD = {}
174 local skipMail = {} 171 local skipMail = {}
175 function addon:ScanMail() 172 function ItemAuditor:ScanMail()
176 local results = {} 173 local results = {}
177 local CODPaymentRegex = gsub(COD_PAYMENT, "%%s", "(.*)") 174 local CODPaymentRegex = gsub(COD_PAYMENT, "%%s", "(.*)")
178 175
179 for mailIndex = 1, GetInboxNumItems() or 0 do 176 for mailIndex = 1, GetInboxNumItems() or 0 do
180 local sender, msgSubject, msgMoney, msgCOD, daysLeft, msgItem, _, _, msgText, _, isGM = select(3, GetInboxHeaderInfo(mailIndex)) 177 local sender, msgSubject, msgMoney, msgCOD, daysLeft, msgItem, _, _, msgText, _, isGM = select(3, GetInboxHeaderInfo(mailIndex))
277 end 274 end
278 275
279 return results 276 return results
280 end 277 end
281 278
282 function addon:GetItem(link, viewOnly) 279 function ItemAuditor:GetItem(link, viewOnly)
283 if viewOnly == nil then 280 if viewOnly == nil then
284 viewOnly = false 281 viewOnly = false
285 end 282 end
286 283
287 local itemName = nil 284 local itemName = nil
328 325
329 326
330 return self.items[link] 327 return self.items[link]
331 end 328 end
332 329
333 function addon:RemoveItem(link) 330 function ItemAuditor:RemoveItem(link)
334 self.db.factionrealm.item_account[link] = nil 331 self.db.factionrealm.item_account[link] = nil
335 link = self:GetSafeLink(link) 332 link = self:GetSafeLink(link)
336 if link ~= nil then 333 if link ~= nil then
337 local item = addon:GetItem(link) 334 local item = ItemAuditor:GetItem(link)
338 item.invested = 0 335 item.invested = 0
339 else 336 else
340 self:Debug('Failed to convert link' .. tostring(link)) 337 self:Debug('Failed to convert link' .. tostring(link))
341 end 338 end
342 end 339 end
343 340
344 function addon:SaveValue(link, value, countChange) 341 function ItemAuditor:SaveValue(link, value, countChange)
345 self:Debug("SaveValue(%s, %s, %s)", tostring(link), value, (countChange or 'default')) 342 self:Debug("SaveValue(%s, %s, %s)", tostring(link), value, (countChange or 'default'))
346 countChange = countChange or 0 343 countChange = countChange or 0
347 local item = nil 344 local item = nil
348 local realLink = self:GetSafeLink(link) 345 local realLink = self:GetSafeLink(link)
349 local itemName = nil 346 local itemName = nil
384 end 381 end
385 end 382 end
386 end 383 end
387 384
388 if realLink ~= nil then 385 if realLink ~= nil then
389 addon:UpdateQAThreshold(realLink) 386 ItemAuditor:UpdateQAThreshold(realLink)
390 end 387 end
391 UpdateInvestedData() 388 UpdateInvestedData()
392 end 389 end
393 390
394 391
395 function addon:WatchBags() 392 function ItemAuditor:WatchBags()
396 if self.watch_handle == nil then 393 if self.watch_handle == nil then
397 addon:UpdateCurrentInventory() 394 ItemAuditor:UpdateCurrentInventory()
398 self.watch_handle = self:RegisterBucketEvent({"BAG_UPDATE", "PLAYER_MONEY"}, 0.3, "UpdateAudit") 395 self.watch_handle = self:RegisterBucketEvent({"BAG_UPDATE", "PLAYER_MONEY"}, 0.3, "UpdateAudit")
399 end 396 end
400 end 397 end
401 398
402 function addon:UnwatchBags() 399 function ItemAuditor:UnwatchBags()
403 if self.watch_handle ~= nil then 400 if self.watch_handle ~= nil then
404 self:UnregisterBucket(self.watch_handle) 401 self:UnregisterBucket(self.watch_handle)
405 self.watch_handle = nil 402 self.watch_handle = nil
406 end 403 end
407 end 404 end
408 405
409 406
410 function addon:GetSafeLink(link) 407 function ItemAuditor:GetSafeLink(link)
411 local newLink = nil 408 local newLink = nil
412 409
413 if link and link == string.match(link, '.-:[-0-9]+[:0-9]*') then 410 if link and link == string.match(link, '.-:[-0-9]+[:0-9]*') then
414 newLink = link 411 newLink = link
415 elseif link then 412 elseif link then
423 end 420 end
424 end 421 end
425 return newLink and string.gsub(newLink, ":0:0:0:0:0:0", "") 422 return newLink and string.gsub(newLink, ":0:0:0:0:0:0", "")
426 end 423 end
427 424
428 function addon:GetIDFromLink(link) 425 function ItemAuditor:GetIDFromLink(link)
429 local _, _, _, _, Id = string.find(link, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?") 426 local _, _, _, _, Id = string.find(link, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
430 return tonumber(Id) 427 return tonumber(Id)
431 end 428 end
432 429
433 function addon:GetItemCost(link, countModifier) 430 function ItemAuditor:GetItemCost(link, countModifier)
434 local item = self:GetItem(link, true) 431 local item = self:GetItem(link, true)
435 432
436 if item.invested > 0 then 433 if item.invested > 0 then
437 local count = item.count 434 local count = item.count
438 435