annotate Core.lua @ 120:00cf4fc1697f

addon.Locations table is used at multiple modules, definition moved to Core.lua.
author Zerotorescue
date Sat, 15 Jan 2011 17:09:08 +0100
parents 67bd5057ecb7
children 6724bc8eface
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@61 5 --@debug@
Zerotorescue@61 6 local addonRevision = 1;
Zerotorescue@61 7 --@end-debug@
Zerotorescue@61 8 --[===[@non-debug@
Zerotorescue@61 9 local addonRevision = @project-revision@;
Zerotorescue@61 10 --@end-non-debug@]===]
Zerotorescue@61 11
Zerotorescue@62 12 local _G = _G;
Zerotorescue@106 13 local sformat, print, pairs, tonumber = _G.string.format, _G.print, _G.pairs, _G.tonumber;
Zerotorescue@13 14
Zerotorescue@62 15 -- 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 16 addon.supportedAddons = {};
Zerotorescue@13 17 addon.supportedAddons.auctionPricing = {};
Zerotorescue@13 18 addon.supportedAddons.itemCount = {};
Zerotorescue@13 19 addon.supportedAddons.crafting = {};
Zerotorescue@0 20
Zerotorescue@120 21 addon.Locations = {
Zerotorescue@120 22 ["Bag"] = "Bag",
Zerotorescue@120 23 ["Bank"] = "Bank",
Zerotorescue@120 24 ["Guild"] = "Guild",
Zerotorescue@120 25 ["Mailbox"] = "Mailbox",
Zerotorescue@120 26 ["Merchant"] = "Merchant",
Zerotorescue@120 27 };
Zerotorescue@120 28
Zerotorescue@0 29 function addon:OnInitialize()
Zerotorescue@0 30 -- SAVED VARIABLES
Zerotorescue@0 31
Zerotorescue@0 32 local defaults = {
Zerotorescue@0 33 global = {
Zerotorescue@61 34 version = nil,
Zerotorescue@61 35 },
Zerotorescue@61 36 profile = {
Zerotorescue@0 37 defaults = {
Zerotorescue@13 38 auctionPricingAddon = "Auctioneer",
Zerotorescue@13 39 itemCountAddon = "Altoholic",
Zerotorescue@13 40 craftingAddon = "AdvancedTradeSkillWindow",
Zerotorescue@61 41 minLocalStock = 20,
Zerotorescue@57 42 alertBelowLocalMinimum = true,
Zerotorescue@82 43 autoRefill = true,
Zerotorescue@101 44 autoRefillSkipConfirm = false,
Zerotorescue@61 45 minGlobalStock = 60,
Zerotorescue@61 46 alertBelowGlobalMinimum = true,
Zerotorescue@0 47 summaryThresholdShow = 10,
Zerotorescue@0 48 restockTarget = 60,
Zerotorescue@0 49 minCraftingQueue = 0.05,
Zerotorescue@0 50 bonusQueue = 0.1,
Zerotorescue@0 51 priceThreshold = 0,
Zerotorescue@13 52 summaryHidePriceThreshold = false,
Zerotorescue@106 53 hideHelp = false,
Zerotorescue@40 54 trackAtCharacters = {
Zerotorescue@40 55 },
Zerotorescue@31 56 localItemData = {
Zerotorescue@31 57 ["Bag"] = true,
Zerotorescue@31 58 ["Auction House"] = true,
Zerotorescue@31 59 },
Zerotorescue@13 60 summary = {
Zerotorescue@13 61 speed = 5,
Zerotorescue@74 62 width = 700,
Zerotorescue@13 63 height = 600,
Zerotorescue@13 64 },
Zerotorescue@0 65 colors = {
Zerotorescue@17 66 red = 0,
Zerotorescue@17 67 orange = 0.3,
Zerotorescue@17 68 yellow = 0.6,
Zerotorescue@17 69 green = 0.95,
Zerotorescue@0 70 },
Zerotorescue@0 71 },
Zerotorescue@61 72 groups = {
Zerotorescue@61 73 },
Zerotorescue@0 74 },
Zerotorescue@0 75 factionrealm = {
Zerotorescue@40 76 characters = {
Zerotorescue@40 77 },
Zerotorescue@0 78 },
Zerotorescue@0 79 };
Zerotorescue@0 80
Zerotorescue@0 81 -- Register our saved variables database
Zerotorescue@11 82 self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true);
Zerotorescue@61 83
Zerotorescue@62 84 -- SLASH COMMANDS
Zerotorescue@62 85
Zerotorescue@62 86 -- Disable the AddonLoader slash commands
Zerotorescue@62 87 SLASH_INVENTORIUM1 = nil;
Zerotorescue@62 88 SLASH_IM1 = nil;
Zerotorescue@62 89
Zerotorescue@62 90 -- Register our own slash commands
Zerotorescue@62 91 SLASH_INVENTORIUM1 = "/inventorium";
Zerotorescue@62 92 SLASH_INVENTORIUM2 = "/im";
Zerotorescue@62 93 SlashCmdList["INVENTORIUM"] = function(msg)
Zerotorescue@62 94 addon:CommandHandler(msg);
Zerotorescue@62 95 end;
Zerotorescue@62 96
Zerotorescue@62 97 -- Debug command handling
Zerotorescue@62 98 self:RegisterSlash(function(this)
Zerotorescue@62 99 this.debugChannel = false;
Zerotorescue@62 100 for i = 1, NUM_CHAT_WINDOWS do
Zerotorescue@62 101 local name = GetChatWindowInfo(i);
Zerotorescue@62 102
Zerotorescue@62 103 if name:upper() == "DEBUG" then
Zerotorescue@62 104 this.debugChannel = _G["ChatFrame" .. i];
Zerotorescue@62 105
Zerotorescue@98 106 addon:Print("A debug channel already exists, used the old one. (" .. i .. ")");
Zerotorescue@62 107 return;
Zerotorescue@62 108 end
Zerotorescue@62 109 end
Zerotorescue@62 110
Zerotorescue@62 111 if not this.debugChannel then
Zerotorescue@62 112 -- Create a new debug channel
Zerotorescue@62 113 local chatFrame = FCF_OpenNewWindow('Debug');
Zerotorescue@62 114 ChatFrame_RemoveAllMessageGroups(chatFrame);
Zerotorescue@62 115 this.debugChannel = chatFrame;
Zerotorescue@62 116
Zerotorescue@98 117 addon:Print("New debug channel created.");
Zerotorescue@62 118 end
Zerotorescue@62 119 end, { "d", "debug" });
Zerotorescue@62 120
Zerotorescue@62 121 -- Remember this character is on this account
Zerotorescue@62 122 local playerName = UnitName("player");
Zerotorescue@62 123 if not self.db.factionrealm.characters[playerName] then
Zerotorescue@62 124 self.db.factionrealm.characters[playerName] = true;
Zerotorescue@62 125
Zerotorescue@62 126 -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports.
Zerotorescue@62 127 self.db.profile.defaults.trackAtCharacters[playerName] = true;
Zerotorescue@62 128 end
Zerotorescue@66 129
Zerotorescue@66 130 self:UpdateDatabase();
Zerotorescue@62 131 end
Zerotorescue@62 132
Zerotorescue@65 133
Zerotorescue@65 134
Zerotorescue@65 135
Zerotorescue@65 136
Zerotorescue@65 137 -- Database patching after new revisions
Zerotorescue@65 138
Zerotorescue@62 139 function addon:UpdateDatabase()
Zerotorescue@61 140 if not self.db.global.version or self.db.global.version < addonRevision then
Zerotorescue@61 141 -- Is our database outdated? Then patch it.
Zerotorescue@61 142
Zerotorescue@61 143 if not self.db.global.version then
Zerotorescue@61 144 -- Old version was before version was saved, many changes were done in that revision
Zerotorescue@61 145
Zerotorescue@98 146 addon:Print("Updating Inventorium database from version " .. (self.db.global.version or "Unknown") .. " to version " .. addonRevision .. "...");
Zerotorescue@61 147
Zerotorescue@61 148 if self.db.global and self.db.global.defaults then
Zerotorescue@98 149 addon:Print("Moving all global data into your current profile...");
Zerotorescue@61 150
Zerotorescue@61 151 -- All data mustn't be global but profile-based
Zerotorescue@61 152 self.db.profile.defaults = CopyTable(self.db.global.defaults);
Zerotorescue@61 153 self.db.profile.groups = CopyTable(self.db.global.groups);
Zerotorescue@61 154
Zerotorescue@61 155 self.db.global.defaults = nil;
Zerotorescue@61 156 self.db.global.groups = nil;
Zerotorescue@61 157
Zerotorescue@62 158 self.CommandHandler = function()
Zerotorescue@62 159 message("You must /reload once to finalize the Inventorium database updates. This will only be required once during the BETA.");
Zerotorescue@61 160 end;
Zerotorescue@62 161 self:CommandHandler();
Zerotorescue@61 162 end
Zerotorescue@61 163
Zerotorescue@61 164 if self.db.profile.defaults.minimumStock then
Zerotorescue@98 165 addon:Print("Copying the minimum stock value into the minimum global stock...");
Zerotorescue@61 166
Zerotorescue@61 167 -- We added another stock option and renamed the old to be more obvious about what it means
Zerotorescue@61 168 self.db.profile.defaults.minGlobalStock = self.db.profile.defaults.minimumStock;
Zerotorescue@61 169 self.db.profile.defaults.minimumStock = nil;
Zerotorescue@61 170 end
Zerotorescue@61 171
Zerotorescue@61 172 if self.db.profile.defaults.minimumLocalStock then
Zerotorescue@98 173 addon:Print("Renaming the minimum local stock property...");
Zerotorescue@61 174
Zerotorescue@61 175 -- We added another stock option and then renamed it
Zerotorescue@61 176 self.db.profile.defaults.minLocalStock = self.db.profile.defaults.minimumLocalStock;
Zerotorescue@61 177 self.db.profile.defaults.minimumLocalStock = nil;
Zerotorescue@61 178 end
Zerotorescue@61 179
Zerotorescue@61 180 if self.db.profile.defaults.alertBelowMinimum then
Zerotorescue@98 181 addon:Print("Copying the alert below minimum value into the alert below global minimum value...");
Zerotorescue@61 182
Zerotorescue@61 183 -- We added another stock option and then renamed it
Zerotorescue@61 184 self.db.profile.defaults.alertBelowGlobalMinimum = self.db.profile.defaults.alertBelowMinimum;
Zerotorescue@61 185 self.db.profile.defaults.alertBelowMinimum = nil;
Zerotorescue@61 186 end
Zerotorescue@61 187
Zerotorescue@61 188 -- Go through all groups to see if there's one with the above two renamed variables
Zerotorescue@61 189 for groupName, values in pairs(self.db.profile.groups) do
Zerotorescue@61 190 if values.minimumStock then
Zerotorescue@61 191 values.minGlobalStock = values.minimumStock;
Zerotorescue@61 192 values.minimumStock = nil;
Zerotorescue@61 193 end
Zerotorescue@61 194 end
Zerotorescue@61 195 end
Zerotorescue@61 196
Zerotorescue@61 197 -- Remember the version of our database
Zerotorescue@61 198 self.db.global.version = addonRevision;
Zerotorescue@61 199 end
Zerotorescue@46 200 end
Zerotorescue@46 201
Zerotorescue@62 202 function addon:GetOptionByKey(groupName, optionName, noDefault)
Zerotorescue@62 203 if groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName][optionName] ~= nil then
Zerotorescue@62 204 -- If this option exists within the settings of this group
Zerotorescue@62 205
Zerotorescue@62 206 return addon.db.profile.groups[groupName][optionName];
Zerotorescue@62 207 elseif groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName].virtualGroup ~= "" and not noDefault then
Zerotorescue@62 208 -- If a virtual group was selected
Zerotorescue@62 209
Zerotorescue@62 210 return self:GetOptionByKey(addon.db.profile.groups[groupName].virtualGroup, optionName, noDefault);
Zerotorescue@62 211 elseif addon.db.profile.defaults[optionName] and not noDefault then
Zerotorescue@62 212 return addon.db.profile.defaults[optionName];
Zerotorescue@62 213 else
Zerotorescue@62 214 return nil;
Zerotorescue@0 215 end
Zerotorescue@0 216 end
Zerotorescue@0 217
Zerotorescue@35 218 function addon:GetItemCountAddon(group)
Zerotorescue@35 219 local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
Zerotorescue@35 220
Zerotorescue@35 221 if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then
Zerotorescue@35 222 -- Try to use the default item count addon
Zerotorescue@35 223
Zerotorescue@35 224 return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon;
Zerotorescue@35 225 else
Zerotorescue@35 226 -- Default not available, get the first one then
Zerotorescue@35 227
Zerotorescue@35 228 for name, value in pairs(self.supportedAddons.itemCount) do
Zerotorescue@35 229 if value.IsEnabled() then
Zerotorescue@35 230 return value, name;
Zerotorescue@35 231 end
Zerotorescue@35 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@35 245 return (itemCountAddon 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@62 312 local cmd, arg = string.split(" ", (message or ""), 2);
Zerotorescue@62 313 cmd = string.lower(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@106 356 elseif value == -3 then
Zerotorescue@106 357 return "|cffffff00Unknown|r";
Zerotorescue@106 358 else
Zerotorescue@106 359 return sformat("%s / %d", self:ColorCode(value, minimumStock), minimumStock);
Zerotorescue@106 360 end
Zerotorescue@106 361 end
Zerotorescue@106 362
Zerotorescue@62 363 -- Readable money
Zerotorescue@62 364
Zerotorescue@62 365 local goldText = "%s%d|cffffd700g|r ";
Zerotorescue@62 366 local silverText = "%s%d|cffc7c7cfs|r ";
Zerotorescue@62 367 local copperText = "%s%d|cffeda55fc|r";
Zerotorescue@62 368
Zerotorescue@62 369 function addon:ReadableMoney(copper, clean)
Zerotorescue@62 370 local text = "";
Zerotorescue@62 371
Zerotorescue@62 372 local gold = floor( copper / COPPER_PER_GOLD );
Zerotorescue@62 373 if gold > 0 then
Zerotorescue@106 374 text = sformat(goldText, text, gold);
Zerotorescue@62 375 end
Zerotorescue@62 376
Zerotorescue@62 377 if not clean or (not gold or gold < 10) then
Zerotorescue@62 378 local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
Zerotorescue@62 379 if silver > 0 then
Zerotorescue@106 380 text = sformat(silverText, text, silver);
Zerotorescue@62 381 end
Zerotorescue@62 382
Zerotorescue@62 383 if not clean or (not gold or gold < 1) then
Zerotorescue@62 384 local copper = floor( copper % COPPER_PER_SILVER );
Zerotorescue@62 385 if copper > 0 or text == "" then
Zerotorescue@106 386 text = sformat(copperText, text, copper);
Zerotorescue@62 387 end
Zerotorescue@62 388 end
Zerotorescue@62 389 end
Zerotorescue@62 390
Zerotorescue@62 391
Zerotorescue@62 392 return string.trim(text);
Zerotorescue@62 393 end
Zerotorescue@62 394
Zerotorescue@62 395 function addon:ReadableMoneyToCopper(value)
Zerotorescue@62 396 -- If a player enters a value it will be filled without color codes
Zerotorescue@62 397 -- If it is retrieved from the database, it will be colored coded
Zerotorescue@62 398 -- Thus we look for both
Zerotorescue@62 399 local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
Zerotorescue@62 400 local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
Zerotorescue@62 401 local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
Zerotorescue@62 402
Zerotorescue@62 403 return ( (gold or 0) * COPPER_PER_GOLD ) + ( (silver or 0) * COPPER_PER_SILVER ) + (copper or 0);
Zerotorescue@62 404 end
Zerotorescue@62 405
Zerotorescue@62 406 function addon:ValidateReadableMoney(info, value)
Zerotorescue@62 407 -- If a player enters a value it will be filled without color codes
Zerotorescue@62 408 -- If it is retrieved from the database, it will be colored coded
Zerotorescue@62 409 -- Thus we look for both
Zerotorescue@62 410 local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
Zerotorescue@62 411 local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
Zerotorescue@62 412 local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
Zerotorescue@62 413
Zerotorescue@62 414 if not gold and not silver and not copper then
Zerotorescue@62 415 return "The provided amount of money is invalid. Please provide the amount of money as #g#s#c, e.g. 591617g24s43c.";
Zerotorescue@62 416 else
Zerotorescue@62 417 return true;
Zerotorescue@62 418 end
Zerotorescue@62 419 end
Zerotorescue@62 420
Zerotorescue@0 421
Zerotorescue@0 422
Zerotorescue@65 423
Zerotorescue@65 424
Zerotorescue@13 425 -- Public
Zerotorescue@13 426
Zerotorescue@36 427 function IMRegisterPricingAddon(name, get, enabled, onSelect)
Zerotorescue@13 428 addon.supportedAddons.auctionPricing[name] = {
Zerotorescue@13 429 GetValue = get,
Zerotorescue@13 430 IsEnabled = enabled,
Zerotorescue@36 431 OnSelect = onSelect,
Zerotorescue@13 432 };
Zerotorescue@13 433 end
Zerotorescue@13 434
Zerotorescue@50 435 function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled, onSelect)
Zerotorescue@13 436 addon.supportedAddons.itemCount[name] = {
Zerotorescue@17 437 GetTotalCount = getTotal,
Zerotorescue@17 438 GetCharacterCount = getCharacter,
Zerotorescue@13 439 IsEnabled = enabled,
Zerotorescue@50 440 OnSelect = onSelect,
Zerotorescue@13 441 };
Zerotorescue@13 442 end
Zerotorescue@13 443
Zerotorescue@50 444 function IMRegisterCraftingAddon(name, queue, enabled, onSelect)
Zerotorescue@13 445 addon.supportedAddons.crafting[name] = {
Zerotorescue@13 446 Queue = queue,
Zerotorescue@13 447 IsEnabled = enabled,
Zerotorescue@50 448 OnSelect = onSelect,
Zerotorescue@13 449 };
Zerotorescue@13 450 end
Zerotorescue@13 451
Zerotorescue@62 452 -- We need a global command handler for our chat-links
Zerotorescue@62 453 function InventoriumCommandHandler(msg)
Zerotorescue@62 454 addon:CommandHandler(msg);
Zerotorescue@62 455 end
Zerotorescue@62 456
Zerotorescue@13 457
Zerotorescue@13 458
Zerotorescue@65 459
Zerotorescue@65 460
Zerotorescue@76 461 -- General
Zerotorescue@76 462
Zerotorescue@76 463 addon.Colors = {
Zerotorescue@76 464 Red = { 1, 0, 0 },
Zerotorescue@98 465 Orange = { 1, .46, .1 },
Zerotorescue@76 466 Green = { 0, 1, 0 },
Zerotorescue@98 467 Blue = { 0, 0, 1 },
Zerotorescue@98 468 Yellow = { 1, 1, 0 },
Zerotorescue@98 469 Cyan = { 0, 1, 1 },
Zerotorescue@76 470 }; -- easy to extend if more colors are needed
Zerotorescue@76 471 function addon:Print(text, color)
Zerotorescue@76 472 local red, green, blue;
Zerotorescue@76 473
Zerotorescue@76 474 if color then
Zerotorescue@76 475 red, green, blue = color[1], color[2], color[3];
Zerotorescue@76 476 end
Zerotorescue@76 477
Zerotorescue@76 478 DEFAULT_CHAT_FRAME:AddMessage(text or "", red, green, blue, nil, 5);
Zerotorescue@76 479 end
Zerotorescue@76 480
Zerotorescue@95 481 function addon:GetItemId(itemLink)
Zerotorescue@84 482 itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part
Zerotorescue@84 483 itemLink = itemLink and tonumber(itemLink);
Zerotorescue@84 484
Zerotorescue@84 485 return itemLink;
Zerotorescue@84 486 end
Zerotorescue@84 487
Zerotorescue@13 488 -- Debug
Zerotorescue@0 489
Zerotorescue@89 490 function addon:Debug(t, ...)
Zerotorescue@0 491 if not self.debugChannel and self.debugChannel ~= false then
Zerotorescue@0 492 -- 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 493 self.debugChannel = false;
Zerotorescue@0 494
Zerotorescue@0 495 for i = 1, NUM_CHAT_WINDOWS do
Zerotorescue@0 496 local name = GetChatWindowInfo(i);
Zerotorescue@0 497
Zerotorescue@0 498 if name:upper() == "DEBUG" then
Zerotorescue@0 499 self.debugChannel = _G["ChatFrame" .. i];
Zerotorescue@0 500 end
Zerotorescue@0 501 end
Zerotorescue@0 502 end
Zerotorescue@0 503
Zerotorescue@0 504 if self.debugChannel then
Zerotorescue@110 505 self.debugChannel:AddMessage("|cffffff00Inventorium|r:" .. sformat(t, ...));
Zerotorescue@0 506 end
Zerotorescue@0 507 end