Zerotorescue@11: -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("Inventorium") Zerotorescue@17: local addon = select(2, ...); Zerotorescue@17: addon = LibStub("AceAddon-3.0"):NewAddon(addon, "Inventorium", "AceEvent-3.0"); Zerotorescue@1: Zerotorescue@122: local _G = _G; Zerotorescue@122: local sformat, ssplit, slower, strim, smatch = _G.string.format, _G.string.split, _G.string.lower, _G.string.trim, _G.string.match; Zerotorescue@128: local floor, print, pairs, tonumber = _G.floor, _G.print, _G.pairs, _G.tonumber; Zerotorescue@122: Zerotorescue@61: --@debug@ Zerotorescue@61: local addonRevision = 1; Zerotorescue@61: --@end-debug@ Zerotorescue@61: --[===[@non-debug@ Zerotorescue@61: local addonRevision = @project-revision@; Zerotorescue@61: --@end-non-debug@]===] Zerotorescue@61: Zerotorescue@62: -- All modules must be able to retrieve our supported addons database, thus keep it a part of the addon object rather than local Zerotorescue@13: addon.supportedAddons = {}; Zerotorescue@13: addon.supportedAddons.auctionPricing = {}; Zerotorescue@13: addon.supportedAddons.itemCount = {}; Zerotorescue@13: addon.supportedAddons.crafting = {}; Zerotorescue@0: Zerotorescue@120: addon.Locations = { Zerotorescue@120: ["Bag"] = "Bag", Zerotorescue@120: ["Bank"] = "Bank", Zerotorescue@120: ["Guild"] = "Guild", Zerotorescue@120: ["Mailbox"] = "Mailbox", Zerotorescue@120: ["Merchant"] = "Merchant", Zerotorescue@120: }; Zerotorescue@120: Zerotorescue@0: function addon:OnInitialize() Zerotorescue@0: -- SAVED VARIABLES Zerotorescue@0: Zerotorescue@0: local defaults = { Zerotorescue@0: global = { Zerotorescue@61: version = nil, Zerotorescue@61: }, Zerotorescue@61: profile = { Zerotorescue@0: defaults = { Zerotorescue@157: -- General Zerotorescue@13: auctionPricingAddon = "Auctioneer", Zerotorescue@13: itemCountAddon = "Altoholic", Zerotorescue@13: craftingAddon = "AdvancedTradeSkillWindow", Zerotorescue@157: trackAtCharacters = { }, Zerotorescue@157: localItemData = { Zerotorescue@157: ["Bag"] = true, Zerotorescue@157: ["Auction House"] = true, Zerotorescue@157: }, Zerotorescue@157: Zerotorescue@157: -- Minimumm stock Zerotorescue@61: minLocalStock = 20, Zerotorescue@57: alertBelowLocalMinimum = true, Zerotorescue@82: autoRefill = true, Zerotorescue@101: autoRefillSkipConfirm = false, Zerotorescue@61: minGlobalStock = 60, Zerotorescue@61: alertBelowGlobalMinimum = true, Zerotorescue@157: Zerotorescue@157: -- Queueing Zerotorescue@0: restockTarget = 60, Zerotorescue@0: minCraftingQueue = 0.05, Zerotorescue@0: bonusQueue = 0.1, Zerotorescue@0: priceThreshold = 0, Zerotorescue@157: Zerotorescue@157: -- Summary Zerotorescue@157: summaryThresholdShow = 10, Zerotorescue@13: summaryHidePriceThreshold = false, Zerotorescue@157: Zerotorescue@157: -- Global (can't be overridden) Zerotorescue@106: hideHelp = false, Zerotorescue@13: summary = { Zerotorescue@13: speed = 5, Zerotorescue@74: width = 700, Zerotorescue@13: height = 600, Zerotorescue@13: }, Zerotorescue@0: colors = { Zerotorescue@17: red = 0, Zerotorescue@17: orange = 0.3, Zerotorescue@17: yellow = 0.6, Zerotorescue@17: green = 0.95, Zerotorescue@0: }, Zerotorescue@157: itemCountGuildsExcluded = { }, Zerotorescue@0: }, Zerotorescue@61: groups = { Zerotorescue@140: -- items = {}, Zerotorescue@140: -- isVirtual = nil, Zerotorescue@61: }, Zerotorescue@0: }, Zerotorescue@0: factionrealm = { Zerotorescue@40: characters = { Zerotorescue@40: }, Zerotorescue@0: }, Zerotorescue@0: }; Zerotorescue@0: Zerotorescue@0: -- Register our saved variables database Zerotorescue@11: self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true); Zerotorescue@61: Zerotorescue@62: -- SLASH COMMANDS Zerotorescue@62: Zerotorescue@62: -- Disable the AddonLoader slash commands Zerotorescue@62: SLASH_INVENTORIUM1 = nil; Zerotorescue@62: SLASH_IM1 = nil; Zerotorescue@62: Zerotorescue@62: -- Register our own slash commands Zerotorescue@62: SLASH_INVENTORIUM1 = "/inventorium"; Zerotorescue@62: SLASH_INVENTORIUM2 = "/im"; Zerotorescue@62: SlashCmdList["INVENTORIUM"] = function(msg) Zerotorescue@62: addon:CommandHandler(msg); Zerotorescue@62: end; Zerotorescue@62: Zerotorescue@62: -- Debug command handling Zerotorescue@62: self:RegisterSlash(function(this) Zerotorescue@62: this.debugChannel = false; Zerotorescue@62: for i = 1, NUM_CHAT_WINDOWS do Zerotorescue@62: local name = GetChatWindowInfo(i); Zerotorescue@62: Zerotorescue@128: if string.upper(name) == "DEBUG" then Zerotorescue@128: addon:Print("A debug channel already exists, removing the old one... (" .. i .. ")"); Zerotorescue@128: FCF_Close(_G["ChatFrame" .. i]); Zerotorescue@62: end Zerotorescue@62: end Zerotorescue@62: Zerotorescue@62: if not this.debugChannel then Zerotorescue@62: -- Create a new debug channel Zerotorescue@62: local chatFrame = FCF_OpenNewWindow('Debug'); Zerotorescue@62: ChatFrame_RemoveAllMessageGroups(chatFrame); Zerotorescue@62: this.debugChannel = chatFrame; Zerotorescue@62: Zerotorescue@98: addon:Print("New debug channel created."); Zerotorescue@62: end Zerotorescue@62: end, { "d", "debug" }); Zerotorescue@62: Zerotorescue@62: -- Remember this character is on this account Zerotorescue@62: local playerName = UnitName("player"); Zerotorescue@62: if not self.db.factionrealm.characters[playerName] then Zerotorescue@62: self.db.factionrealm.characters[playerName] = true; Zerotorescue@62: Zerotorescue@62: -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports. Zerotorescue@62: self.db.profile.defaults.trackAtCharacters[playerName] = true; Zerotorescue@62: end Zerotorescue@66: Zerotorescue@66: self:UpdateDatabase(); Zerotorescue@62: end Zerotorescue@62: Zerotorescue@65: Zerotorescue@65: Zerotorescue@65: Zerotorescue@65: Zerotorescue@65: -- Database patching after new revisions Zerotorescue@65: Zerotorescue@62: function addon:UpdateDatabase() Zerotorescue@61: if not self.db.global.version or self.db.global.version < addonRevision then Zerotorescue@61: -- Is our database outdated? Then patch it. Zerotorescue@61: Zerotorescue@61: if not self.db.global.version then Zerotorescue@61: -- Old version was before version was saved, many changes were done in that revision Zerotorescue@61: Zerotorescue@98: addon:Print("Updating Inventorium database from version " .. (self.db.global.version or "Unknown") .. " to version " .. addonRevision .. "..."); Zerotorescue@61: Zerotorescue@61: if self.db.global and self.db.global.defaults then Zerotorescue@98: addon:Print("Moving all global data into your current profile..."); Zerotorescue@61: Zerotorescue@61: -- All data mustn't be global but profile-based Zerotorescue@61: self.db.profile.defaults = CopyTable(self.db.global.defaults); Zerotorescue@61: self.db.profile.groups = CopyTable(self.db.global.groups); Zerotorescue@61: Zerotorescue@61: self.db.global.defaults = nil; Zerotorescue@61: self.db.global.groups = nil; Zerotorescue@61: Zerotorescue@62: self.CommandHandler = function() Zerotorescue@62: message("You must /reload once to finalize the Inventorium database updates. This will only be required once during the BETA."); Zerotorescue@61: end; Zerotorescue@62: self:CommandHandler(); Zerotorescue@61: end Zerotorescue@61: Zerotorescue@61: if self.db.profile.defaults.minimumStock then Zerotorescue@98: addon:Print("Copying the minimum stock value into the minimum global stock..."); Zerotorescue@61: Zerotorescue@61: -- We added another stock option and renamed the old to be more obvious about what it means Zerotorescue@61: self.db.profile.defaults.minGlobalStock = self.db.profile.defaults.minimumStock; Zerotorescue@61: self.db.profile.defaults.minimumStock = nil; Zerotorescue@61: end Zerotorescue@61: Zerotorescue@61: if self.db.profile.defaults.minimumLocalStock then Zerotorescue@98: addon:Print("Renaming the minimum local stock property..."); Zerotorescue@61: Zerotorescue@61: -- We added another stock option and then renamed it Zerotorescue@61: self.db.profile.defaults.minLocalStock = self.db.profile.defaults.minimumLocalStock; Zerotorescue@61: self.db.profile.defaults.minimumLocalStock = nil; Zerotorescue@61: end Zerotorescue@61: Zerotorescue@61: if self.db.profile.defaults.alertBelowMinimum then Zerotorescue@98: addon:Print("Copying the alert below minimum value into the alert below global minimum value..."); Zerotorescue@61: Zerotorescue@61: -- We added another stock option and then renamed it Zerotorescue@61: self.db.profile.defaults.alertBelowGlobalMinimum = self.db.profile.defaults.alertBelowMinimum; Zerotorescue@61: self.db.profile.defaults.alertBelowMinimum = nil; Zerotorescue@61: end Zerotorescue@61: Zerotorescue@61: -- Go through all groups to see if there's one with the above two renamed variables Zerotorescue@61: for groupName, values in pairs(self.db.profile.groups) do Zerotorescue@61: if values.minimumStock then Zerotorescue@61: values.minGlobalStock = values.minimumStock; Zerotorescue@61: values.minimumStock = nil; Zerotorescue@61: end Zerotorescue@61: end Zerotorescue@61: end Zerotorescue@61: Zerotorescue@61: -- Remember the version of our database Zerotorescue@61: self.db.global.version = addonRevision; Zerotorescue@61: end Zerotorescue@46: end Zerotorescue@46: Zerotorescue@62: function addon:GetOptionByKey(groupName, optionName, noDefault) Zerotorescue@62: if groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName][optionName] ~= nil then Zerotorescue@62: -- If this option exists within the settings of this group Zerotorescue@62: Zerotorescue@62: return addon.db.profile.groups[groupName][optionName]; Zerotorescue@62: elseif groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName].virtualGroup ~= "" and not noDefault then Zerotorescue@62: -- If a virtual group was selected Zerotorescue@62: Zerotorescue@62: return self:GetOptionByKey(addon.db.profile.groups[groupName].virtualGroup, optionName, noDefault); Zerotorescue@62: elseif addon.db.profile.defaults[optionName] and not noDefault then Zerotorescue@62: return addon.db.profile.defaults[optionName]; Zerotorescue@62: else Zerotorescue@62: return nil; Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@35: function addon:GetItemCountAddon(group) Zerotorescue@35: local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon"); Zerotorescue@35: Zerotorescue@35: if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then Zerotorescue@35: -- Try to use the default item count addon Zerotorescue@35: Zerotorescue@157: if self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState then Zerotorescue@157: self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded); Zerotorescue@157: end Zerotorescue@157: Zerotorescue@35: return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon; Zerotorescue@35: else Zerotorescue@35: -- Default not available, get the first one then Zerotorescue@35: Zerotorescue@35: for name, value in pairs(self.supportedAddons.itemCount) do Zerotorescue@35: if value.IsEnabled() then Zerotorescue@157: if value.SetGuildState then Zerotorescue@157: value.SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded); Zerotorescue@157: end Zerotorescue@157: Zerotorescue@35: return value, name; Zerotorescue@35: end Zerotorescue@35: end Zerotorescue@35: end Zerotorescue@35: Zerotorescue@35: return; Zerotorescue@35: end Zerotorescue@35: Zerotorescue@23: function addon:GetItemCount(itemId, group) Zerotorescue@13: itemId = tonumber(itemId); Zerotorescue@13: Zerotorescue@13: if not itemId then return; end Zerotorescue@13: Zerotorescue@35: local itemCountAddon = self:GetItemCountAddon(group); Zerotorescue@23: Zerotorescue@35: return (itemCountAddon and itemCountAddon.GetTotalCount(itemId)) or -1; Zerotorescue@0: end Zerotorescue@0: Zerotorescue@50: function addon:GetLocalItemCount(itemId, group) Zerotorescue@50: itemId = tonumber(itemId); Zerotorescue@50: Zerotorescue@50: if not itemId then return; end Zerotorescue@50: Zerotorescue@50: local itemCountAddon = self:GetItemCountAddon(group); Zerotorescue@50: Zerotorescue@50: local currentItemCount; Zerotorescue@50: Zerotorescue@50: if itemCountAddon and itemCountAddon.GetCharacterCount then Zerotorescue@50: local bag, bank, auctionHouse, mail = itemCountAddon.GetCharacterCount(itemId); Zerotorescue@50: Zerotorescue@50: local selectedLocalItemCountSources = self:GetOptionByKey(group, "localItemData"); Zerotorescue@50: Zerotorescue@50: currentItemCount = 0; Zerotorescue@50: if selectedLocalItemCountSources["Bag"] then Zerotorescue@50: currentItemCount = currentItemCount + bag; Zerotorescue@50: end Zerotorescue@50: if selectedLocalItemCountSources["Bank"] then Zerotorescue@50: currentItemCount = currentItemCount + bank; Zerotorescue@50: end Zerotorescue@50: if selectedLocalItemCountSources["Auction House"] then Zerotorescue@50: currentItemCount = currentItemCount + auctionHouse; Zerotorescue@50: end Zerotorescue@50: if selectedLocalItemCountSources["Mailbox"] then Zerotorescue@50: currentItemCount = currentItemCount + mail; Zerotorescue@50: end Zerotorescue@50: end Zerotorescue@50: Zerotorescue@50: return currentItemCount or -1; Zerotorescue@50: end Zerotorescue@50: Zerotorescue@23: function addon:GetAuctionValue(itemLink, group) Zerotorescue@23: if not itemLink then return -5; end Zerotorescue@13: Zerotorescue@23: local selectedExternalAddon = self:GetOptionByKey(group, "auctionPricingAddon"); Zerotorescue@23: Zerotorescue@23: if self.supportedAddons.auctionPricing[selectedExternalAddon] and self.supportedAddons.auctionPricing[selectedExternalAddon].IsEnabled() then Zerotorescue@13: -- Try to use the default auction pricing addon Zerotorescue@1: Zerotorescue@23: return self.supportedAddons.auctionPricing[selectedExternalAddon].GetValue(itemLink); Zerotorescue@13: else Zerotorescue@13: -- Default not available, get the first one then Zerotorescue@1: Zerotorescue@13: for name, value in pairs(self.supportedAddons.auctionPricing) do Zerotorescue@13: if value.IsEnabled() then Zerotorescue@13: return value.GetValue(itemLink); Zerotorescue@13: end Zerotorescue@1: end Zerotorescue@1: end Zerotorescue@7: Zerotorescue@7: return -2; Zerotorescue@1: end Zerotorescue@1: Zerotorescue@65: Zerotorescue@65: Zerotorescue@65: Zerotorescue@65: Zerotorescue@62: -- Slash commands Zerotorescue@62: Zerotorescue@62: local slashArgs = {}; Zerotorescue@62: local slashError = "Wrong argument, the following arguments are available:"; Zerotorescue@62: Zerotorescue@62: function addon:CommandHandler(message) Zerotorescue@122: local cmd, arg = ssplit(" ", (message or ""), 2); Zerotorescue@122: cmd = slower(cmd); Zerotorescue@62: Zerotorescue@62: if slashArgs[cmd] then Zerotorescue@62: -- Pass a reference to the addon (to be used as "self") and the provided arg Zerotorescue@62: slashArgs[cmd](addon, arg); Zerotorescue@62: else Zerotorescue@98: addon:Print(slashError); Zerotorescue@62: end Zerotorescue@62: end Zerotorescue@62: Zerotorescue@62: function addon:RegisterSlash(func, args, description) Zerotorescue@62: for _, arg in pairs(args) do Zerotorescue@62: slashArgs[arg] = func; Zerotorescue@62: end Zerotorescue@62: Zerotorescue@62: if description then Zerotorescue@62: slashError = slashError .. "\n" .. description; Zerotorescue@62: end Zerotorescue@62: end Zerotorescue@62: Zerotorescue@65: Zerotorescue@65: Zerotorescue@65: Zerotorescue@65: Zerotorescue@106: function addon:ColorCode(num, required) Zerotorescue@106: local percentage = ( num / required ); Zerotorescue@106: Zerotorescue@106: if percentage >= addon.db.profile.defaults.colors.green then Zerotorescue@106: return sformat("|cff00ff00%d|r", num); Zerotorescue@106: elseif percentage >= addon.db.profile.defaults.colors.yellow then Zerotorescue@106: return sformat("|cffffff00%d|r", num); Zerotorescue@106: elseif percentage >= addon.db.profile.defaults.colors.orange then Zerotorescue@106: return sformat("|cffff9933%d|r", num); Zerotorescue@106: elseif percentage >= addon.db.profile.defaults.colors.red then Zerotorescue@106: return sformat("|cffff0000%d|r", num); Zerotorescue@106: else Zerotorescue@106: return num; Zerotorescue@106: end Zerotorescue@106: end Zerotorescue@106: Zerotorescue@106: function addon:DisplayItemCount(value, minimumStock) Zerotorescue@106: if value == -1 then Zerotorescue@106: return "|cffffff00Unknown|r"; Zerotorescue@106: elseif value == -3 then Zerotorescue@106: return "|cffffff00Unknown|r"; Zerotorescue@106: else Zerotorescue@106: return sformat("%s / %d", self:ColorCode(value, minimumStock), minimumStock); Zerotorescue@106: end Zerotorescue@106: end Zerotorescue@106: Zerotorescue@62: -- Readable money Zerotorescue@62: Zerotorescue@62: local goldText = "%s%d|cffffd700g|r "; Zerotorescue@62: local silverText = "%s%d|cffc7c7cfs|r "; Zerotorescue@62: local copperText = "%s%d|cffeda55fc|r"; Zerotorescue@62: Zerotorescue@62: function addon:ReadableMoney(copper, clean) Zerotorescue@62: local text = ""; Zerotorescue@62: Zerotorescue@128: local gold = floor( copper / COPPER_PER_GOLD ); Zerotorescue@62: if gold > 0 then Zerotorescue@106: text = sformat(goldText, text, gold); Zerotorescue@62: end Zerotorescue@62: Zerotorescue@62: if not clean or (not gold or gold < 10) then Zerotorescue@128: local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER ); Zerotorescue@62: if silver > 0 then Zerotorescue@106: text = sformat(silverText, text, silver); Zerotorescue@62: end Zerotorescue@62: Zerotorescue@62: if not clean or (not gold or gold < 1) then Zerotorescue@128: local copper = floor( copper % COPPER_PER_SILVER ); Zerotorescue@62: if copper > 0 or text == "" then Zerotorescue@106: text = sformat(copperText, text, copper); Zerotorescue@62: end Zerotorescue@62: end Zerotorescue@62: end Zerotorescue@62: Zerotorescue@62: Zerotorescue@122: return strim(text); Zerotorescue@62: end Zerotorescue@62: Zerotorescue@62: function addon:ReadableMoneyToCopper(value) Zerotorescue@62: -- If a player enters a value it will be filled without color codes Zerotorescue@62: -- If it is retrieved from the database, it will be colored coded Zerotorescue@62: -- Thus we look for both Zerotorescue@122: local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g")); Zerotorescue@122: local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s")); Zerotorescue@122: local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c")); Zerotorescue@62: Zerotorescue@62: return ( (gold or 0) * COPPER_PER_GOLD ) + ( (silver or 0) * COPPER_PER_SILVER ) + (copper or 0); Zerotorescue@62: end Zerotorescue@62: Zerotorescue@62: function addon:ValidateReadableMoney(info, value) Zerotorescue@62: -- If a player enters a value it will be filled without color codes Zerotorescue@62: -- If it is retrieved from the database, it will be colored coded Zerotorescue@62: -- Thus we look for both Zerotorescue@122: local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g")); Zerotorescue@122: local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s")); Zerotorescue@122: local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c")); Zerotorescue@62: Zerotorescue@62: if not gold and not silver and not copper then Zerotorescue@62: return "The provided amount of money is invalid. Please provide the amount of money as #g#s#c, e.g. 591617g24s43c."; Zerotorescue@62: else Zerotorescue@62: return true; Zerotorescue@62: end Zerotorescue@62: end Zerotorescue@62: Zerotorescue@0: Zerotorescue@0: Zerotorescue@65: Zerotorescue@65: Zerotorescue@13: -- Public Zerotorescue@13: Zerotorescue@36: function IMRegisterPricingAddon(name, get, enabled, onSelect) Zerotorescue@13: addon.supportedAddons.auctionPricing[name] = { Zerotorescue@156: ["GetValue"] = get, Zerotorescue@156: ["IsEnabled"] = enabled, Zerotorescue@156: ["OnSelect"] = onSelect, Zerotorescue@13: }; Zerotorescue@13: end Zerotorescue@13: Zerotorescue@156: function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled, onSelect, getGuildNames, setGuildState) Zerotorescue@13: addon.supportedAddons.itemCount[name] = { Zerotorescue@156: ["GetTotalCount"] = getTotal, Zerotorescue@156: ["GetCharacterCount"] = getCharacter, Zerotorescue@156: ["IsEnabled"] = enabled, Zerotorescue@156: ["OnSelect"] = onSelect, Zerotorescue@156: ["GetGuildNames"] = getGuildNames, Zerotorescue@156: ["SetGuildState"] = setGuildState, Zerotorescue@13: }; Zerotorescue@13: end Zerotorescue@13: Zerotorescue@50: function IMRegisterCraftingAddon(name, queue, enabled, onSelect) Zerotorescue@13: addon.supportedAddons.crafting[name] = { Zerotorescue@156: ["Queue"] = queue, Zerotorescue@156: ["IsEnabled"] = enabled, Zerotorescue@156: ["OnSelect"] = onSelect, Zerotorescue@13: }; Zerotorescue@13: end Zerotorescue@13: Zerotorescue@62: -- We need a global command handler for our chat-links Zerotorescue@62: function InventoriumCommandHandler(msg) Zerotorescue@62: addon:CommandHandler(msg); Zerotorescue@62: end Zerotorescue@62: Zerotorescue@13: Zerotorescue@13: Zerotorescue@65: Zerotorescue@65: Zerotorescue@76: -- General Zerotorescue@76: Zerotorescue@76: addon.Colors = { Zerotorescue@157: ["Red"] = { 1, 0, 0 }, Zerotorescue@157: ["Orange"] = { 1, .46, .1 }, Zerotorescue@157: ["Green"] = { 0, 1, 0 }, Zerotorescue@157: ["Blue"] = { 0, 0, 1 }, Zerotorescue@157: ["Yellow"] = { 1, 1, 0 }, Zerotorescue@157: ["Cyan"] = { 0, 1, 1 }, Zerotorescue@76: }; -- easy to extend if more colors are needed Zerotorescue@76: function addon:Print(text, color) Zerotorescue@76: local red, green, blue; Zerotorescue@76: Zerotorescue@76: if color then Zerotorescue@76: red, green, blue = color[1], color[2], color[3]; Zerotorescue@76: end Zerotorescue@76: Zerotorescue@76: DEFAULT_CHAT_FRAME:AddMessage(text or "", red, green, blue, nil, 5); Zerotorescue@76: end Zerotorescue@76: Zerotorescue@95: function addon:GetItemId(itemLink) Zerotorescue@84: itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part Zerotorescue@84: itemLink = itemLink and tonumber(itemLink); Zerotorescue@84: Zerotorescue@84: return itemLink; Zerotorescue@84: end Zerotorescue@84: Zerotorescue@13: -- Debug Zerotorescue@0: Zerotorescue@89: function addon:Debug(t, ...) Zerotorescue@0: if not self.debugChannel and self.debugChannel ~= false then Zerotorescue@0: -- We want to check just once, so if you add a debug channel later just do a /reload (registering an event for this is wasted resources) Zerotorescue@0: self.debugChannel = false; Zerotorescue@0: Zerotorescue@0: for i = 1, NUM_CHAT_WINDOWS do Zerotorescue@0: local name = GetChatWindowInfo(i); Zerotorescue@0: Zerotorescue@0: if name:upper() == "DEBUG" then Zerotorescue@0: self.debugChannel = _G["ChatFrame" .. i]; Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: if self.debugChannel then Zerotorescue@110: self.debugChannel:AddMessage("|cffffff00Inventorium|r:" .. sformat(t, ...)); Zerotorescue@0: end Zerotorescue@0: end