Mercurial > wow > itemauditor
changeset 65:32d53abee666
Converting ItemAuditor modules into true modules instead of a bunch of files that all write to the ItemAuditor table.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Tue, 27 Jul 2010 18:15:38 -0700 |
parents | e92a5adf75bf |
children | b7bc0488f13b |
files | Core.lua Modules/Frames.lua Modules/Options.lua Modules/Utils.lua |
diffstat | 4 files changed, 80 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Tue Jul 27 18:00:00 2010 -0700 +++ b/Core.lua Tue Jul 27 18:15:38 2010 -0700 @@ -1,5 +1,8 @@ local ItemAuditor = select(2, ...) ItemAuditor = LibStub("AceAddon-3.0"):NewAddon(ItemAuditor, "ItemAuditor", "AceEvent-3.0", "AceBucket-3.0") +--@debug@ + _G['ItemAuditor'] = ItemAuditor +--@end-debug@ local WHITE = "|cFFFFFFFF" local RED = "|cFFFF0000" @@ -34,19 +37,17 @@ }, } self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true) - self.items = self.db.factionrealm.items self:RegisterOptions() ItemAuditor:RegisterFrame(ItemAuditor_DebugFrame) - -- /run ItemAuditor.db.profile.show_debug_frame_on_startup = true - if self.db.profile.show_debug_frame_on_startup then + --@debug@ -- ItemAuditor_DebugFrame:Show() -- self:CreateFrame('tab_crafting') self:RegisterEvent("TRADE_SKILL_SHOW", function() ItemAuditor:CreateFrame('tab_crafting') end) - end + --@end-debug@ end local registeredEvents = {} @@ -107,10 +108,20 @@ self:RefreshQAGroups() end +-- Options doesn't exist when this file is created the first time, so getOptions will +-- make one call to :GetModule and return the result and replace itself with a +-- function that simply returns the same object. The permanent solution will probably be +-- to move :Print to a different module. +local function getOptions() + local Options = ItemAuditor:GetModule("Options") + getOptions = function() return Options end + return Options +end + local printPrefix = "|cFFA3CEFFItemAuditor|r: " function ItemAuditor:Print(message, ...) message = format(message, ...) - self:GetSelectedChatWindow():AddMessage( printPrefix .. tostring(message)) + getOptions().GetSelectedChatWindow():AddMessage( printPrefix .. tostring(message)) end function ItemAuditor:GetCurrentInventory() @@ -291,40 +302,40 @@ if self.db.factionrealm.item_account[itemName] ~= nil then - self.items[link] = { + self.db.factionrealm.items[link] = { count = Altoholic:GetItemCount(self:GetIDFromLink(link)), invested = abs(self.db.factionrealm.item_account[itemName] or 0), } self.db.factionrealm.item_account[itemName] = nil end - if viewOnly == false and self.items[link] == nil then + if viewOnly == false and self.db.factionrealm.items[link] == nil then - self.items[link] = { + self.db.factionrealm.items[link] = { count = Altoholic:GetItemCount(self:GetIDFromLink(link)), invested = abs(self.db.factionrealm.item_account[itemName] or 0), } end - if self.items[link] ~= nil then - self.items[link].count = Altoholic:GetItemCount(self:GetIDFromLink(link)) + if self.db.factionrealm.items[link] ~= nil then + self.db.factionrealm.items[link].count = Altoholic:GetItemCount(self:GetIDFromLink(link)) - if self.items[link].invested == nil then - self.items[link].invested = 0 + if self.db.factionrealm.items[link].invested == nil then + self.db.factionrealm.items[link].invested = 0 end end - if viewOnly == true and self.items[link] == nil then + if viewOnly == true and self.db.factionrealm.items[link] == nil then return {count = 0, invested = 0} elseif viewOnly == true then - return {count = self.items[link].count, invested = self.items[link].invested} + return {count = self.db.factionrealm.items[link].count, invested = self.db.factionrealm.items[link].invested} end - return self.items[link] + return self.db.factionrealm.items[link] end function ItemAuditor:RemoveItem(link)
--- a/Modules/Frames.lua Tue Jul 27 18:00:00 2010 -0700 +++ b/Modules/Frames.lua Tue Jul 27 18:15:38 2010 -0700 @@ -5,7 +5,7 @@ local tabs = {} -function ItemAuditor:RegisterTab(text, value, callback) +function Frames.RegisterTab(text, value, callback) tabs[value] = {text=text, callback=callback} end @@ -29,8 +29,7 @@ currentContent = cb(container) end - -function ItemAuditor:CreateFrame(selectedTab) +function Frames.CreateFrame(selectedTab) if not displayFrame then -- Create the frame container @@ -77,8 +76,20 @@ displayFrame:Show() end -function ItemAuditor:UpdateStatusText(message) +function Frames.UpdateStatusText(message) if displayFrame then displayFrame:SetStatusText(message) end -end \ No newline at end of file +end + +function ItemAuditor:UpdateStatusText(message) + return Frames.UpdateStatusText(message) +end + +function ItemAuditor:RegisterTab(text, value, callback) + return Frames.RegisterTab(text, value, callback) +end + +function ItemAuditor:CreateFrame(selectedTab) + Frames.CreateFrame(selectedTab) +end
--- a/Modules/Options.lua Tue Jul 27 18:00:00 2010 -0700 +++ b/Modules/Options.lua Tue Jul 27 18:15:38 2010 -0700 @@ -4,6 +4,7 @@ local currentFaction = UnitFactionGroup("player") local AHFactions = { currentFaction, 'Neutral' } +-- TODO: Convert this to a text field. local craftingThresholds = {5000, 10000, 50000} local craftingThresholdsDisplay = {} @@ -15,7 +16,7 @@ end local windowIndex = nil -function ItemAuditor:GetChatWindowList() +function Options.GetChatWindowList() local windows = {} for i=1, NUM_CHAT_WINDOWS do local name, _, _, _, _, _, shown, locked, docked = GetChatWindowInfo(i) @@ -26,13 +27,13 @@ return windows end -function ItemAuditor:GetChatWindowIndex() - local cf = self.db.char.output_chat_frame +function Options:GetChatWindowIndex() + local cf = ItemAuditor.db.char.output_chat_frame if not windowIndex then for i=1, NUM_CHAT_WINDOWS do local name, _, _, _, _, _, shown, locked, docked = GetChatWindowInfo(i) if name ~= "" and cf ~= nil and cf == name then - self:SetChatWindow(nil, i) + Options.SetChatWindow(nil, i) end end end @@ -42,17 +43,17 @@ local selectedWindow = nil -function ItemAuditor:SetChatWindow(info, index) +function Options.SetChatWindow(info, index) windowIndex = index local name = GetChatWindowInfo(windowIndex) - self.db.char.output_chat_frame = name + ItemAuditor.db.char.output_chat_frame = name selectedWindow = nil end -function ItemAuditor:GetSelectedChatWindow() +function Options.GetSelectedChatWindow() if not selectedWindow then - local index = self:GetChatWindowIndex() + local index = Options.GetChatWindowIndex() if index then selectedWindow = _G["ChatFrame"..index] end @@ -112,9 +113,9 @@ type = "select", name = "Output", desc = "", - values = 'GetChatWindowList', - get = 'GetChatWindowIndex', - set = 'SetChatWindow', + values = Options.GetChatWindowList, + get = Options.GetChatWindowIndex, + set = Options.SetChatWindow, }, }, },
--- a/Modules/Utils.lua Tue Jul 27 18:00:00 2010 -0700 +++ b/Modules/Utils.lua Tue Jul 27 18:15:38 2010 -0700 @@ -1,7 +1,7 @@ local ItemAuditor = select(2, ...) local Utils = ItemAuditor:NewModule("Utils") -function ItemAuditor:FormatMoney(copper, color, textOnly) +function Utils.FormatMoney(copper, color, textOnly) color = color or "|cFFFFFFFF" local prefix = "" if copper < 0 then @@ -40,7 +40,7 @@ end -- Copied from QuickAuctions -function ItemAuditor.validateMoney(value) +function Utils.validateMoney(value) local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) @@ -54,30 +54,18 @@ end -- Copied from QuickAuctions -function ItemAuditor.parseMoney(value) +function Utils.parseMoney(value) local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) -- Convert it all into copper return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) - end --- This is only here to make sure this doesn't blow up if ReplaceItemCache is never called -local item_db = {} -function ItemAuditor:ReplaceItemCache(new_cache) - item_db = new_cache -end - --- This will be reset every session local tmp_item_cache = {} -function ItemAuditor:GetItemID(itemName) - if item_db[itemName] ~= nil then - return item_db[itemName] - end - +function Utils.GetItemID(itemName) if tmp_item_cache[itemName] == nil then local _, itemLink = GetItemInfo (itemName); if itemLink ~= nil then @@ -100,6 +88,7 @@ return tmp_item_cache[itemName] end + function ItemAuditor:GetLinkFromName(itemName) local itemID = self:GetItemID(itemName) local itemLink @@ -110,11 +99,7 @@ return itemLink end -function ItemAuditor:SaveItemID(itemName, id) - item_db[itemName] = tonumber(id) -end - -ItemAuditor.SubjectPatterns = { +local SubjectPatterns = { AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"), AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"), AHOutbid = gsub(AUCTION_OUTBID_MAIL_SUBJECT, "%%s", ".*"), @@ -123,9 +108,9 @@ CODPayment = gsub(COD_PAYMENT, "%%s", "(.*)"), } -function ItemAuditor:GetMailType(msgSubject) +function Utils.GetMailType(msgSubject) if msgSubject then - for k, v in pairs(self.SubjectPatterns) do + for k, v in pairs(SubjectPatterns) do if msgSubject:find(v) then return k end end end @@ -155,3 +140,21 @@ end self:Print("Debugging is now: " .. value) end + +-- TODO: Once everything points to the correct Utils method, all of these should be removed + +function ItemAuditor:FormatMoney(copper, color, textOnly) + return Utils.FormatMoney(copper, color, textOnly) +end + + +function ItemAuditor:GetMailType(msgSubject) + return Utils.GetMailType(msgSubject) +end + +function ItemAuditor:GetItemID(itemName) + return Utils.GetItemID(itemName) +end + +ItemAuditor.parseMoney = Utils.parseMoney +ItemAuditor.validateMoney = Utils.validateMoney \ No newline at end of file