annotate Core.lua @ 225:2e4e52a589e5

Added onQueueStart and onQueueEnd events to crafting addon registering. GnomeWorks queue frame should automatically be closed before adding items to the queue and opened afterwards to speed this process up.
author Zerotorescue
date Mon, 07 Feb 2011 15:06:41 +0100
parents c04257b42b03
children
rev   line source
Zerotorescue@11 1 -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("Inventorium")
Zerotorescue@17 2 local addon = select(2, ...);
Zerotorescue@17 3 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "Inventorium", "AceEvent-3.0");
Zerotorescue@1 4
Zerotorescue@122 5 local _G = _G;
Zerotorescue@122 6 local sformat, ssplit, slower, strim, smatch = _G.string.format, _G.string.split, _G.string.lower, _G.string.trim, _G.string.match;
Zerotorescue@128 7 local floor, print, pairs, tonumber = _G.floor, _G.print, _G.pairs, _G.tonumber;
Zerotorescue@122 8
Zerotorescue@61 9 --@debug@
Zerotorescue@180 10 local addonRevision = 1; -- used to update the database whenever required
Zerotorescue@61 11 --@end-debug@
Zerotorescue@61 12 --[===[@non-debug@
Zerotorescue@61 13 local addonRevision = @project-revision@;
Zerotorescue@61 14 --@end-non-debug@]===]
Zerotorescue@61 15
Zerotorescue@62 16 -- 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 17 addon.supportedAddons = {};
Zerotorescue@13 18 addon.supportedAddons.auctionPricing = {};
Zerotorescue@13 19 addon.supportedAddons.itemCount = {};
Zerotorescue@13 20 addon.supportedAddons.crafting = {};
Zerotorescue@0 21
Zerotorescue@120 22 addon.Locations = {
Zerotorescue@120 23 ["Bag"] = "Bag",
Zerotorescue@120 24 ["Bank"] = "Bank",
Zerotorescue@120 25 ["Guild"] = "Guild",
Zerotorescue@120 26 ["Mailbox"] = "Mailbox",
Zerotorescue@120 27 ["Merchant"] = "Merchant",
Zerotorescue@120 28 };
Zerotorescue@120 29
Zerotorescue@0 30 function addon:OnInitialize()
Zerotorescue@0 31 -- SAVED VARIABLES
Zerotorescue@0 32
Zerotorescue@0 33 local defaults = {
Zerotorescue@0 34 global = {
Zerotorescue@61 35 version = nil,
Zerotorescue@61 36 },
Zerotorescue@61 37 profile = {
Zerotorescue@0 38 defaults = {
Zerotorescue@157 39 -- General
Zerotorescue@13 40 auctionPricingAddon = "Auctioneer",
Zerotorescue@192 41 itemCountAddon = "DataStore (with guilds)",
Zerotorescue@13 42 craftingAddon = "AdvancedTradeSkillWindow",
Zerotorescue@157 43 trackAtCharacters = { },
Zerotorescue@176 44 dontAlertAtCharacters = { },
Zerotorescue@157 45 localItemData = {
Zerotorescue@157 46 ["Bag"] = true,
Zerotorescue@157 47 ["Auction House"] = true,
Zerotorescue@157 48 },
Zerotorescue@157 49
Zerotorescue@157 50 -- Minimumm stock
Zerotorescue@61 51 minLocalStock = 20,
Zerotorescue@57 52 alertBelowLocalMinimum = true,
Zerotorescue@82 53 autoRefill = true,
Zerotorescue@101 54 autoRefillSkipConfirm = false,
Zerotorescue@193 55 minGlobalStock = 40,
Zerotorescue@61 56 alertBelowGlobalMinimum = true,
Zerotorescue@157 57
Zerotorescue@157 58 -- Queueing
Zerotorescue@193 59 restockTarget = 40,
Zerotorescue@0 60 minCraftingQueue = 0.05,
Zerotorescue@220 61 bonusQueue = 0.1,
Zerotorescue@0 62 priceThreshold = 0,
Zerotorescue@157 63
Zerotorescue@157 64 -- Summary
Zerotorescue@220 65 summaryThresholdShow = 100, -- 10.000%
Zerotorescue@13 66 summaryHidePriceThreshold = false,
Zerotorescue@157 67
Zerotorescue@157 68 -- Global (can't be overridden)
Zerotorescue@210 69 minimapIcon = true,
Zerotorescue@106 70 hideHelp = false,
Zerotorescue@176 71 scanInterval = "0.1", -- string because the associated select requires it to be
Zerotorescue@13 72 summary = {
Zerotorescue@193 73 speed = 20,
Zerotorescue@74 74 width = 700,
Zerotorescue@13 75 height = 600,
Zerotorescue@13 76 },
Zerotorescue@0 77 colors = {
Zerotorescue@17 78 red = 0,
Zerotorescue@17 79 orange = 0.3,
Zerotorescue@17 80 yellow = 0.6,
Zerotorescue@17 81 green = 0.95,
Zerotorescue@0 82 },
Zerotorescue@157 83 itemCountGuildsExcluded = { },
Zerotorescue@0 84 },
Zerotorescue@61 85 groups = {
Zerotorescue@140 86 -- items = {},
Zerotorescue@140 87 -- isVirtual = nil,
Zerotorescue@61 88 },
Zerotorescue@0 89 },
Zerotorescue@0 90 factionrealm = {
Zerotorescue@40 91 characters = {
Zerotorescue@40 92 },
Zerotorescue@0 93 },
Zerotorescue@0 94 };
Zerotorescue@0 95
Zerotorescue@0 96 -- Register our saved variables database
Zerotorescue@11 97 self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true);
Zerotorescue@61 98
Zerotorescue@62 99 -- SLASH COMMANDS
Zerotorescue@62 100
Zerotorescue@62 101 -- Disable the AddonLoader slash commands
Zerotorescue@62 102 SLASH_INVENTORIUM1 = nil;
Zerotorescue@62 103 SLASH_IM1 = nil;
Zerotorescue@62 104
Zerotorescue@62 105 -- Register our own slash commands
Zerotorescue@62 106 SLASH_INVENTORIUM1 = "/inventorium";
Zerotorescue@62 107 SLASH_INVENTORIUM2 = "/im";
Zerotorescue@62 108 SlashCmdList["INVENTORIUM"] = function(msg)
Zerotorescue@62 109 addon:CommandHandler(msg);
Zerotorescue@62 110 end;
Zerotorescue@62 111
Zerotorescue@62 112 -- Debug command handling
Zerotorescue@62 113 self:RegisterSlash(function(this)
Zerotorescue@62 114 this.debugChannel = false;
Zerotorescue@62 115 for i = 1, NUM_CHAT_WINDOWS do
Zerotorescue@62 116 local name = GetChatWindowInfo(i);
Zerotorescue@62 117
Zerotorescue@176 118 if string.upper(name) == "IMDEBUG" then
Zerotorescue@128 119 addon:Print("A debug channel already exists, removing the old one... (" .. i .. ")");
Zerotorescue@128 120 FCF_Close(_G["ChatFrame" .. i]);
Zerotorescue@62 121 end
Zerotorescue@62 122 end
Zerotorescue@62 123
Zerotorescue@62 124 if not this.debugChannel then
Zerotorescue@62 125 -- Create a new debug channel
Zerotorescue@176 126 local chatFrame = FCF_OpenNewWindow('IMDebug');
Zerotorescue@62 127 ChatFrame_RemoveAllMessageGroups(chatFrame);
Zerotorescue@62 128 this.debugChannel = chatFrame;
Zerotorescue@62 129
Zerotorescue@98 130 addon:Print("New debug channel created.");
Zerotorescue@62 131 end
Zerotorescue@176 132 end, { "d", "debug", "imdebug" });
Zerotorescue@62 133
Zerotorescue@62 134 -- Remember this character is on this account
Zerotorescue@62 135 local playerName = UnitName("player");
Zerotorescue@62 136 if not self.db.factionrealm.characters[playerName] then
Zerotorescue@62 137 self.db.factionrealm.characters[playerName] = true;
Zerotorescue@62 138
Zerotorescue@62 139 -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports.
Zerotorescue@62 140 self.db.profile.defaults.trackAtCharacters[playerName] = true;
Zerotorescue@62 141 end
Zerotorescue@66 142
Zerotorescue@66 143 self:UpdateDatabase();
Zerotorescue@62 144 end
Zerotorescue@62 145
Zerotorescue@65 146
Zerotorescue@65 147
Zerotorescue@65 148
Zerotorescue@65 149
Zerotorescue@65 150 -- Database patching after new revisions
Zerotorescue@65 151
Zerotorescue@62 152 function addon:UpdateDatabase()
Zerotorescue@61 153 if not self.db.global.version or self.db.global.version < addonRevision then
Zerotorescue@61 154 -- Is our database outdated? Then patch it.
Zerotorescue@61 155
Zerotorescue@217 156 --[[if self.db.global.version < 1337 then
Zerotorescue@217 157 end]]
Zerotorescue@61 158
Zerotorescue@61 159 -- Remember the version of our database
Zerotorescue@61 160 self.db.global.version = addonRevision;
Zerotorescue@61 161 end
Zerotorescue@46 162 end
Zerotorescue@46 163
Zerotorescue@62 164 function addon:GetOptionByKey(groupName, optionName, noDefault)
Zerotorescue@62 165 if groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName][optionName] ~= nil then
Zerotorescue@62 166 -- If this option exists within the settings of this group
Zerotorescue@62 167
Zerotorescue@62 168 return addon.db.profile.groups[groupName][optionName];
Zerotorescue@62 169 elseif groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName].virtualGroup ~= "" and not noDefault then
Zerotorescue@62 170 -- If a virtual group was selected
Zerotorescue@62 171
Zerotorescue@62 172 return self:GetOptionByKey(addon.db.profile.groups[groupName].virtualGroup, optionName, noDefault);
Zerotorescue@62 173 elseif addon.db.profile.defaults[optionName] and not noDefault then
Zerotorescue@62 174 return addon.db.profile.defaults[optionName];
Zerotorescue@62 175 else
Zerotorescue@62 176 return nil;
Zerotorescue@0 177 end
Zerotorescue@0 178 end
Zerotorescue@0 179
Zerotorescue@215 180 local autoSelectedItemCountAddon;
Zerotorescue@35 181 function addon:GetItemCountAddon(group)
Zerotorescue@35 182 local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
Zerotorescue@35 183
Zerotorescue@35 184 if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then
Zerotorescue@35 185 -- Try to use the default item count addon
Zerotorescue@35 186
Zerotorescue@157 187 if self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState then
Zerotorescue@157 188 self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
Zerotorescue@157 189 end
Zerotorescue@157 190
Zerotorescue@35 191 return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon;
Zerotorescue@215 192 elseif self.supportedAddons.itemCount[autoSelectedItemCountAddon] and self.supportedAddons.itemCount[autoSelectedItemCountAddon].IsEnabled() then
Zerotorescue@215 193 -- Use previously automatically selected addon
Zerotorescue@215 194
Zerotorescue@215 195 if self.supportedAddons.itemCount[autoSelectedItemCountAddon].SetGuildState then
Zerotorescue@215 196 self.supportedAddons.itemCount[autoSelectedItemCountAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
Zerotorescue@215 197 end
Zerotorescue@215 198
Zerotorescue@215 199 return self.supportedAddons.itemCount[autoSelectedItemCountAddon], autoSelectedItemCountAddon;
Zerotorescue@35 200 else
Zerotorescue@35 201 -- Default not available, get the first one then
Zerotorescue@35 202
Zerotorescue@215 203 -- We are finding the best match, quality is used to compare everything
Zerotorescue@215 204 local altName, altValue, altQuality;
Zerotorescue@215 205
Zerotorescue@35 206 for name, value in pairs(self.supportedAddons.itemCount) do
Zerotorescue@35 207 if value.IsEnabled() then
Zerotorescue@215 208 -- Quality is based on functionality supported; TotalCount, LocalCount & GuildSelect = 3; TotalCount & LocalCount = 2, TotalCount = 1
Zerotorescue@215 209 local quality = ((value.GetTotalCount and value.GetCharacterCount and value.SetGuildState and 3) or (value.GetTotalCount and value.GetCharacterCount and 2) or (value.GetTotalCount and 1) or 0);
Zerotorescue@215 210
Zerotorescue@215 211 if quality == 3 then
Zerotorescue@215 212 -- Best quality means instant return
Zerotorescue@215 213
Zerotorescue@215 214 -- Remember this was auto selected so we don't loop again
Zerotorescue@215 215 autoSelectedItemCountAddon = name;
Zerotorescue@215 216
Zerotorescue@215 217 return value, name;
Zerotorescue@215 218 elseif not altQuality or quality > altQuality then
Zerotorescue@215 219 -- Compare quality; improvement? = overwrite
Zerotorescue@215 220 altName = name;
Zerotorescue@215 221 altValue = value;
Zerotorescue@215 222 altQuality = quality;
Zerotorescue@157 223 end
Zerotorescue@35 224 end
Zerotorescue@35 225 end
Zerotorescue@215 226
Zerotorescue@215 227 if altName and altValue and altQuality then
Zerotorescue@215 228 -- Remember this was auto selected so we don't loop again
Zerotorescue@215 229 autoSelectedItemCountAddon = altName;
Zerotorescue@215 230
Zerotorescue@215 231 return altValue, altName;
Zerotorescue@215 232 end
Zerotorescue@35 233 end
Zerotorescue@35 234
Zerotorescue@35 235 return;
Zerotorescue@35 236 end
Zerotorescue@35 237
Zerotorescue@23 238 function addon:GetItemCount(itemId, group)
Zerotorescue@13 239 itemId = tonumber(itemId);
Zerotorescue@13 240
Zerotorescue@13 241 if not itemId then return; end
Zerotorescue@13 242
Zerotorescue@35 243 local itemCountAddon = self:GetItemCountAddon(group);
Zerotorescue@23 244
Zerotorescue@215 245 return (itemCountAddon and itemCountAddon.GetTotalCount and itemCountAddon.GetTotalCount(itemId)) or -1;
Zerotorescue@0 246 end
Zerotorescue@0 247
Zerotorescue@50 248 function addon:GetLocalItemCount(itemId, group)
Zerotorescue@50 249 itemId = tonumber(itemId);
Zerotorescue@50 250
Zerotorescue@50 251 if not itemId then return; end
Zerotorescue@50 252
Zerotorescue@50 253 local itemCountAddon = self:GetItemCountAddon(group);
Zerotorescue@50 254
Zerotorescue@50 255 local currentItemCount;
Zerotorescue@50 256
Zerotorescue@50 257 if itemCountAddon and itemCountAddon.GetCharacterCount then
Zerotorescue@50 258 local bag, bank, auctionHouse, mail = itemCountAddon.GetCharacterCount(itemId);
Zerotorescue@50 259
Zerotorescue@50 260 local selectedLocalItemCountSources = self:GetOptionByKey(group, "localItemData");
Zerotorescue@50 261
Zerotorescue@50 262 currentItemCount = 0;
Zerotorescue@50 263 if selectedLocalItemCountSources["Bag"] then
Zerotorescue@50 264 currentItemCount = currentItemCount + bag;
Zerotorescue@50 265 end
Zerotorescue@50 266 if selectedLocalItemCountSources["Bank"] then
Zerotorescue@50 267 currentItemCount = currentItemCount + bank;
Zerotorescue@50 268 end
Zerotorescue@50 269 if selectedLocalItemCountSources["Auction House"] then
Zerotorescue@50 270 currentItemCount = currentItemCount + auctionHouse;
Zerotorescue@50 271 end
Zerotorescue@50 272 if selectedLocalItemCountSources["Mailbox"] then
Zerotorescue@50 273 currentItemCount = currentItemCount + mail;
Zerotorescue@50 274 end
Zerotorescue@50 275 end
Zerotorescue@50 276
Zerotorescue@50 277 return currentItemCount or -1;
Zerotorescue@50 278 end
Zerotorescue@50 279
Zerotorescue@23 280 function addon:GetAuctionValue(itemLink, group)
Zerotorescue@23 281 if not itemLink then return -5; end
Zerotorescue@13 282
Zerotorescue@23 283 local selectedExternalAddon = self:GetOptionByKey(group, "auctionPricingAddon");
Zerotorescue@23 284
Zerotorescue@23 285 if self.supportedAddons.auctionPricing[selectedExternalAddon] and self.supportedAddons.auctionPricing[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 286 -- Try to use the default auction pricing addon
Zerotorescue@1 287
Zerotorescue@23 288 return self.supportedAddons.auctionPricing[selectedExternalAddon].GetValue(itemLink);
Zerotorescue@13 289 else
Zerotorescue@13 290 -- Default not available, get the first one then
Zerotorescue@1 291
Zerotorescue@13 292 for name, value in pairs(self.supportedAddons.auctionPricing) do
Zerotorescue@13 293 if value.IsEnabled() then
Zerotorescue@13 294 return value.GetValue(itemLink);
Zerotorescue@13 295 end
Zerotorescue@1 296 end
Zerotorescue@1 297 end
Zerotorescue@7 298
Zerotorescue@7 299 return -2;
Zerotorescue@1 300 end
Zerotorescue@1 301
Zerotorescue@65 302
Zerotorescue@65 303
Zerotorescue@65 304
Zerotorescue@65 305
Zerotorescue@62 306 -- Slash commands
Zerotorescue@62 307
Zerotorescue@62 308 local slashArgs = {};
Zerotorescue@62 309 local slashError = "Wrong argument, the following arguments are available:";
Zerotorescue@62 310
Zerotorescue@62 311 function addon:CommandHandler(message)
Zerotorescue@122 312 local cmd, arg = ssplit(" ", (message or ""), 2);
Zerotorescue@122 313 cmd = slower(cmd);
Zerotorescue@62 314
Zerotorescue@62 315 if slashArgs[cmd] then
Zerotorescue@62 316 -- Pass a reference to the addon (to be used as "self") and the provided arg
Zerotorescue@62 317 slashArgs[cmd](addon, arg);
Zerotorescue@62 318 else
Zerotorescue@98 319 addon:Print(slashError);
Zerotorescue@62 320 end
Zerotorescue@62 321 end
Zerotorescue@62 322
Zerotorescue@62 323 function addon:RegisterSlash(func, args, description)
Zerotorescue@62 324 for _, arg in pairs(args) do
Zerotorescue@62 325 slashArgs[arg] = func;
Zerotorescue@62 326 end
Zerotorescue@62 327
Zerotorescue@62 328 if description then
Zerotorescue@62 329 slashError = slashError .. "\n" .. description;
Zerotorescue@62 330 end
Zerotorescue@62 331 end
Zerotorescue@62 332
Zerotorescue@65 333
Zerotorescue@65 334
Zerotorescue@65 335
Zerotorescue@65 336
Zerotorescue@106 337 function addon:ColorCode(num, required)
Zerotorescue@106 338 local percentage = ( num / required );
Zerotorescue@106 339
Zerotorescue@106 340 if percentage >= addon.db.profile.defaults.colors.green then
Zerotorescue@106 341 return sformat("|cff00ff00%d|r", num);
Zerotorescue@106 342 elseif percentage >= addon.db.profile.defaults.colors.yellow then
Zerotorescue@106 343 return sformat("|cffffff00%d|r", num);
Zerotorescue@106 344 elseif percentage >= addon.db.profile.defaults.colors.orange then
Zerotorescue@106 345 return sformat("|cffff9933%d|r", num);
Zerotorescue@106 346 elseif percentage >= addon.db.profile.defaults.colors.red then
Zerotorescue@106 347 return sformat("|cffff0000%d|r", num);
Zerotorescue@106 348 else
Zerotorescue@106 349 return num;
Zerotorescue@106 350 end
Zerotorescue@106 351 end
Zerotorescue@106 352
Zerotorescue@106 353 function addon:DisplayItemCount(value, minimumStock)
Zerotorescue@106 354 if value == -1 then
Zerotorescue@106 355 return "|cffffff00Unknown|r";
Zerotorescue@188 356 elseif value == -2 then
Zerotorescue@188 357 return "|cffffff00-|r";
Zerotorescue@106 358 elseif value == -3 then
Zerotorescue@106 359 return "|cffffff00Unknown|r";
Zerotorescue@106 360 else
Zerotorescue@106 361 return sformat("%s / %d", self:ColorCode(value, minimumStock), minimumStock);
Zerotorescue@106 362 end
Zerotorescue@106 363 end
Zerotorescue@106 364
Zerotorescue@62 365 -- Readable money
Zerotorescue@62 366
Zerotorescue@62 367 local goldText = "%s%d|cffffd700g|r ";
Zerotorescue@62 368 local silverText = "%s%d|cffc7c7cfs|r ";
Zerotorescue@62 369 local copperText = "%s%d|cffeda55fc|r";
Zerotorescue@62 370
Zerotorescue@62 371 function addon:ReadableMoney(copper, clean)
Zerotorescue@62 372 local text = "";
Zerotorescue@62 373
Zerotorescue@128 374 local gold = floor( copper / COPPER_PER_GOLD );
Zerotorescue@62 375 if gold > 0 then
Zerotorescue@106 376 text = sformat(goldText, text, gold);
Zerotorescue@62 377 end
Zerotorescue@62 378
Zerotorescue@62 379 if not clean or (not gold or gold < 10) then
Zerotorescue@128 380 local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
Zerotorescue@62 381 if silver > 0 then
Zerotorescue@106 382 text = sformat(silverText, text, silver);
Zerotorescue@62 383 end
Zerotorescue@62 384
Zerotorescue@62 385 if not clean or (not gold or gold < 1) then
Zerotorescue@128 386 local copper = floor( copper % COPPER_PER_SILVER );
Zerotorescue@62 387 if copper > 0 or text == "" then
Zerotorescue@106 388 text = sformat(copperText, text, copper);
Zerotorescue@62 389 end
Zerotorescue@62 390 end
Zerotorescue@62 391 end
Zerotorescue@62 392
Zerotorescue@62 393
Zerotorescue@122 394 return strim(text);
Zerotorescue@62 395 end
Zerotorescue@62 396
Zerotorescue@62 397 function addon:ReadableMoneyToCopper(value)
Zerotorescue@62 398 -- If a player enters a value it will be filled without color codes
Zerotorescue@62 399 -- If it is retrieved from the database, it will be colored coded
Zerotorescue@62 400 -- Thus we look for both
Zerotorescue@122 401 local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g"));
Zerotorescue@122 402 local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s"));
Zerotorescue@122 403 local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c"));
Zerotorescue@62 404
Zerotorescue@62 405 return ( (gold or 0) * COPPER_PER_GOLD ) + ( (silver or 0) * COPPER_PER_SILVER ) + (copper or 0);
Zerotorescue@62 406 end
Zerotorescue@62 407
Zerotorescue@62 408 function addon:ValidateReadableMoney(info, value)
Zerotorescue@62 409 -- If a player enters a value it will be filled without color codes
Zerotorescue@62 410 -- If it is retrieved from the database, it will be colored coded
Zerotorescue@62 411 -- Thus we look for both
Zerotorescue@122 412 local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g"));
Zerotorescue@122 413 local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s"));
Zerotorescue@122 414 local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c"));
Zerotorescue@62 415
Zerotorescue@62 416 if not gold and not silver and not copper then
Zerotorescue@62 417 return "The provided amount of money is invalid. Please provide the amount of money as #g#s#c, e.g. 591617g24s43c.";
Zerotorescue@62 418 else
Zerotorescue@62 419 return true;
Zerotorescue@62 420 end
Zerotorescue@62 421 end
Zerotorescue@62 422
Zerotorescue@0 423
Zerotorescue@0 424
Zerotorescue@65 425
Zerotorescue@65 426
Zerotorescue@13 427 -- Public
Zerotorescue@13 428
Zerotorescue@36 429 function IMRegisterPricingAddon(name, get, enabled, onSelect)
Zerotorescue@13 430 addon.supportedAddons.auctionPricing[name] = {
Zerotorescue@156 431 ["GetValue"] = get,
Zerotorescue@156 432 ["IsEnabled"] = enabled,
Zerotorescue@156 433 ["OnSelect"] = onSelect,
Zerotorescue@13 434 };
Zerotorescue@13 435 end
Zerotorescue@13 436
Zerotorescue@156 437 function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled, onSelect, getGuildNames, setGuildState)
Zerotorescue@13 438 addon.supportedAddons.itemCount[name] = {
Zerotorescue@156 439 ["GetTotalCount"] = getTotal,
Zerotorescue@156 440 ["GetCharacterCount"] = getCharacter,
Zerotorescue@156 441 ["IsEnabled"] = enabled,
Zerotorescue@156 442 ["OnSelect"] = onSelect,
Zerotorescue@156 443 ["GetGuildNames"] = getGuildNames,
Zerotorescue@156 444 ["SetGuildState"] = setGuildState,
Zerotorescue@13 445 };
Zerotorescue@13 446 end
Zerotorescue@13 447
Zerotorescue@225 448 function IMRegisterCraftingAddon(name, queue, enabled, onSelect, onQueueStart, onQueueEnd)
Zerotorescue@13 449 addon.supportedAddons.crafting[name] = {
Zerotorescue@156 450 ["Queue"] = queue,
Zerotorescue@156 451 ["IsEnabled"] = enabled,
Zerotorescue@156 452 ["OnSelect"] = onSelect,
Zerotorescue@225 453 ["OnQueueStart"] = onQueueStart,
Zerotorescue@225 454 ["OnQueueEnd"] = onQueueEnd,
Zerotorescue@13 455 };
Zerotorescue@13 456 end
Zerotorescue@13 457
Zerotorescue@62 458 -- We need a global command handler for our chat-links
Zerotorescue@62 459 function InventoriumCommandHandler(msg)
Zerotorescue@62 460 addon:CommandHandler(msg);
Zerotorescue@62 461 end
Zerotorescue@62 462
Zerotorescue@13 463
Zerotorescue@13 464
Zerotorescue@65 465
Zerotorescue@65 466
Zerotorescue@76 467 -- General
Zerotorescue@76 468
Zerotorescue@76 469 addon.Colors = {
Zerotorescue@157 470 ["Red"] = { 1, 0, 0 },
Zerotorescue@157 471 ["Orange"] = { 1, .46, .1 },
Zerotorescue@157 472 ["Green"] = { 0, 1, 0 },
Zerotorescue@157 473 ["Blue"] = { 0, 0, 1 },
Zerotorescue@157 474 ["Yellow"] = { 1, 1, 0 },
Zerotorescue@157 475 ["Cyan"] = { 0, 1, 1 },
Zerotorescue@76 476 }; -- easy to extend if more colors are needed
Zerotorescue@76 477 function addon:Print(text, color)
Zerotorescue@76 478 local red, green, blue;
Zerotorescue@76 479
Zerotorescue@76 480 if color then
Zerotorescue@76 481 red, green, blue = color[1], color[2], color[3];
Zerotorescue@76 482 end
Zerotorescue@76 483
Zerotorescue@76 484 DEFAULT_CHAT_FRAME:AddMessage(text or "", red, green, blue, nil, 5);
Zerotorescue@76 485 end
Zerotorescue@76 486
Zerotorescue@95 487 function addon:GetItemId(itemLink)
Zerotorescue@84 488 itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part
Zerotorescue@84 489 itemLink = itemLink and tonumber(itemLink);
Zerotorescue@84 490
Zerotorescue@84 491 return itemLink;
Zerotorescue@84 492 end
Zerotorescue@84 493
Zerotorescue@13 494 -- Debug
Zerotorescue@0 495
Zerotorescue@176 496 local function ReadableTable(t, includeKeys, jumps)
Zerotorescue@176 497 local tabs = "";
Zerotorescue@176 498 for i = 1, (jumps or 0) do
Zerotorescue@176 499 tabs = tabs .. " ";
Zerotorescue@176 500 end
Zerotorescue@176 501
Zerotorescue@176 502 local temp = "{\n";
Zerotorescue@176 503
Zerotorescue@169 504 for i, v in pairs(t) do
Zerotorescue@169 505 if type(v) == "table" then
Zerotorescue@176 506 if includeKeys then
Zerotorescue@188 507 local key = (type(i) == "number" and tostring(i)) or sformat("\"%s\"", tostring(i));
Zerotorescue@176 508
Zerotorescue@188 509 temp = sformat("%s%s [%s] => %s,\n", temp, tabs, key, ReadableTable(v, includeKeys, (jumps or 0) + 1));
Zerotorescue@176 510 else
Zerotorescue@188 511 temp = sformat("%s%s %s,\n", temp, tabs, ReadableTable(v, includeKeys, (jumps or 0) + 1));
Zerotorescue@176 512 end
Zerotorescue@169 513 else
Zerotorescue@176 514 if includeKeys then
Zerotorescue@188 515 local key = (type(i) == "number" and tostring(i)) or sformat("\"%s\"", tostring(i));
Zerotorescue@188 516 local value = (type(v) == "number" and tostring(v)) or sformat("\"%s\"", tostring(v));
Zerotorescue@176 517
Zerotorescue@188 518 temp = sformat("%s%s [%s] => %s,\n", temp, tabs, key, value);
Zerotorescue@176 519 else
Zerotorescue@188 520 local value = (type(v) == "number" and tostring(v)) or sformat("\"%s\"", tostring(v));
Zerotorescue@176 521
Zerotorescue@188 522 temp = sformat("%s%s %s,\n", temp, tabs, value);
Zerotorescue@176 523 end
Zerotorescue@169 524 end
Zerotorescue@169 525 end
Zerotorescue@176 526 temp = temp .. tabs .. "}";
Zerotorescue@176 527
Zerotorescue@169 528 return temp;
Zerotorescue@169 529 end
Zerotorescue@169 530
Zerotorescue@89 531 function addon:Debug(t, ...)
Zerotorescue@0 532 if not self.debugChannel and self.debugChannel ~= false then
Zerotorescue@0 533 -- 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 534 self.debugChannel = false;
Zerotorescue@0 535
Zerotorescue@0 536 for i = 1, NUM_CHAT_WINDOWS do
Zerotorescue@0 537 local name = GetChatWindowInfo(i);
Zerotorescue@0 538
Zerotorescue@176 539 if name:upper() == "IMDEBUG" then
Zerotorescue@0 540 self.debugChannel = _G["ChatFrame" .. i];
Zerotorescue@0 541 end
Zerotorescue@0 542 end
Zerotorescue@0 543 end
Zerotorescue@0 544
Zerotorescue@0 545 if self.debugChannel then
Zerotorescue@169 546 if type(t) == "table" then
Zerotorescue@176 547 t = ReadableTable(t, true);
Zerotorescue@169 548 end
Zerotorescue@169 549
Zerotorescue@110 550 self.debugChannel:AddMessage("|cffffff00Inventorium|r:" .. sformat(t, ...));
Zerotorescue@0 551 end
Zerotorescue@0 552 end