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@193
|
61 bonusQueue = 100, -- 10.000%
|
Zerotorescue@0
|
62 priceThreshold = 0,
|
Zerotorescue@157
|
63
|
Zerotorescue@157
|
64 -- Summary
|
Zerotorescue@157
|
65 summaryThresholdShow = 10,
|
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@61
|
156 if not self.db.global.version then
|
Zerotorescue@61
|
157 -- Old version was before version was saved, many changes were done in that revision
|
Zerotorescue@61
|
158
|
Zerotorescue@98
|
159 addon:Print("Updating Inventorium database from version " .. (self.db.global.version or "Unknown") .. " to version " .. addonRevision .. "...");
|
Zerotorescue@61
|
160
|
Zerotorescue@61
|
161 if self.db.global and self.db.global.defaults then
|
Zerotorescue@98
|
162 addon:Print("Moving all global data into your current profile...");
|
Zerotorescue@61
|
163
|
Zerotorescue@61
|
164 -- All data mustn't be global but profile-based
|
Zerotorescue@61
|
165 self.db.profile.defaults = CopyTable(self.db.global.defaults);
|
Zerotorescue@61
|
166 self.db.profile.groups = CopyTable(self.db.global.groups);
|
Zerotorescue@61
|
167
|
Zerotorescue@61
|
168 self.db.global.defaults = nil;
|
Zerotorescue@61
|
169 self.db.global.groups = nil;
|
Zerotorescue@61
|
170
|
Zerotorescue@62
|
171 self.CommandHandler = function()
|
Zerotorescue@62
|
172 message("You must /reload once to finalize the Inventorium database updates. This will only be required once during the BETA.");
|
Zerotorescue@61
|
173 end;
|
Zerotorescue@62
|
174 self:CommandHandler();
|
Zerotorescue@61
|
175 end
|
Zerotorescue@61
|
176
|
Zerotorescue@61
|
177 if self.db.profile.defaults.minimumStock then
|
Zerotorescue@98
|
178 addon:Print("Copying the minimum stock value into the minimum global stock...");
|
Zerotorescue@61
|
179
|
Zerotorescue@61
|
180 -- We added another stock option and renamed the old to be more obvious about what it means
|
Zerotorescue@61
|
181 self.db.profile.defaults.minGlobalStock = self.db.profile.defaults.minimumStock;
|
Zerotorescue@61
|
182 self.db.profile.defaults.minimumStock = nil;
|
Zerotorescue@61
|
183 end
|
Zerotorescue@61
|
184
|
Zerotorescue@61
|
185 if self.db.profile.defaults.minimumLocalStock then
|
Zerotorescue@98
|
186 addon:Print("Renaming the minimum local stock property...");
|
Zerotorescue@61
|
187
|
Zerotorescue@61
|
188 -- We added another stock option and then renamed it
|
Zerotorescue@61
|
189 self.db.profile.defaults.minLocalStock = self.db.profile.defaults.minimumLocalStock;
|
Zerotorescue@61
|
190 self.db.profile.defaults.minimumLocalStock = nil;
|
Zerotorescue@61
|
191 end
|
Zerotorescue@61
|
192
|
Zerotorescue@61
|
193 if self.db.profile.defaults.alertBelowMinimum then
|
Zerotorescue@98
|
194 addon:Print("Copying the alert below minimum value into the alert below global minimum value...");
|
Zerotorescue@61
|
195
|
Zerotorescue@61
|
196 -- We added another stock option and then renamed it
|
Zerotorescue@61
|
197 self.db.profile.defaults.alertBelowGlobalMinimum = self.db.profile.defaults.alertBelowMinimum;
|
Zerotorescue@61
|
198 self.db.profile.defaults.alertBelowMinimum = nil;
|
Zerotorescue@61
|
199 end
|
Zerotorescue@61
|
200
|
Zerotorescue@61
|
201 -- Go through all groups to see if there's one with the above two renamed variables
|
Zerotorescue@61
|
202 for groupName, values in pairs(self.db.profile.groups) do
|
Zerotorescue@61
|
203 if values.minimumStock then
|
Zerotorescue@61
|
204 values.minGlobalStock = values.minimumStock;
|
Zerotorescue@61
|
205 values.minimumStock = nil;
|
Zerotorescue@61
|
206 end
|
Zerotorescue@61
|
207 end
|
Zerotorescue@180
|
208 -- end of old version which didn't have version numbers recorded
|
Zerotorescue@61
|
209 end
|
Zerotorescue@61
|
210
|
Zerotorescue@61
|
211 -- Remember the version of our database
|
Zerotorescue@61
|
212 self.db.global.version = addonRevision;
|
Zerotorescue@61
|
213 end
|
Zerotorescue@46
|
214 end
|
Zerotorescue@46
|
215
|
Zerotorescue@62
|
216 function addon:GetOptionByKey(groupName, optionName, noDefault)
|
Zerotorescue@62
|
217 if groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName][optionName] ~= nil then
|
Zerotorescue@62
|
218 -- If this option exists within the settings of this group
|
Zerotorescue@62
|
219
|
Zerotorescue@62
|
220 return addon.db.profile.groups[groupName][optionName];
|
Zerotorescue@62
|
221 elseif groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName].virtualGroup ~= "" and not noDefault then
|
Zerotorescue@62
|
222 -- If a virtual group was selected
|
Zerotorescue@62
|
223
|
Zerotorescue@62
|
224 return self:GetOptionByKey(addon.db.profile.groups[groupName].virtualGroup, optionName, noDefault);
|
Zerotorescue@62
|
225 elseif addon.db.profile.defaults[optionName] and not noDefault then
|
Zerotorescue@62
|
226 return addon.db.profile.defaults[optionName];
|
Zerotorescue@62
|
227 else
|
Zerotorescue@62
|
228 return nil;
|
Zerotorescue@0
|
229 end
|
Zerotorescue@0
|
230 end
|
Zerotorescue@0
|
231
|
Zerotorescue@215
|
232 local autoSelectedItemCountAddon;
|
Zerotorescue@35
|
233 function addon:GetItemCountAddon(group)
|
Zerotorescue@35
|
234 local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
|
Zerotorescue@35
|
235
|
Zerotorescue@35
|
236 if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then
|
Zerotorescue@35
|
237 -- Try to use the default item count addon
|
Zerotorescue@35
|
238
|
Zerotorescue@157
|
239 if self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState then
|
Zerotorescue@157
|
240 self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
|
Zerotorescue@157
|
241 end
|
Zerotorescue@157
|
242
|
Zerotorescue@35
|
243 return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon;
|
Zerotorescue@215
|
244 elseif self.supportedAddons.itemCount[autoSelectedItemCountAddon] and self.supportedAddons.itemCount[autoSelectedItemCountAddon].IsEnabled() then
|
Zerotorescue@215
|
245 -- Use previously automatically selected addon
|
Zerotorescue@215
|
246
|
Zerotorescue@215
|
247 if self.supportedAddons.itemCount[autoSelectedItemCountAddon].SetGuildState then
|
Zerotorescue@215
|
248 self.supportedAddons.itemCount[autoSelectedItemCountAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
|
Zerotorescue@215
|
249 end
|
Zerotorescue@215
|
250
|
Zerotorescue@215
|
251 return self.supportedAddons.itemCount[autoSelectedItemCountAddon], autoSelectedItemCountAddon;
|
Zerotorescue@35
|
252 else
|
Zerotorescue@35
|
253 -- Default not available, get the first one then
|
Zerotorescue@35
|
254
|
Zerotorescue@215
|
255 -- We are finding the best match, quality is used to compare everything
|
Zerotorescue@215
|
256 local altName, altValue, altQuality;
|
Zerotorescue@215
|
257
|
Zerotorescue@35
|
258 for name, value in pairs(self.supportedAddons.itemCount) do
|
Zerotorescue@35
|
259 if value.IsEnabled() then
|
Zerotorescue@215
|
260 -- Quality is based on functionality supported; TotalCount, LocalCount & GuildSelect = 3; TotalCount & LocalCount = 2, TotalCount = 1
|
Zerotorescue@215
|
261 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
|
262
|
Zerotorescue@215
|
263 if quality == 3 then
|
Zerotorescue@215
|
264 -- Best quality means instant return
|
Zerotorescue@215
|
265
|
Zerotorescue@215
|
266 -- Remember this was auto selected so we don't loop again
|
Zerotorescue@215
|
267 autoSelectedItemCountAddon = name;
|
Zerotorescue@215
|
268
|
Zerotorescue@215
|
269 return value, name;
|
Zerotorescue@215
|
270 elseif not altQuality or quality > altQuality then
|
Zerotorescue@215
|
271 -- Compare quality; improvement? = overwrite
|
Zerotorescue@215
|
272 altName = name;
|
Zerotorescue@215
|
273 altValue = value;
|
Zerotorescue@215
|
274 altQuality = quality;
|
Zerotorescue@157
|
275 end
|
Zerotorescue@35
|
276 end
|
Zerotorescue@35
|
277 end
|
Zerotorescue@215
|
278
|
Zerotorescue@215
|
279 if altName and altValue and altQuality then
|
Zerotorescue@215
|
280 -- Remember this was auto selected so we don't loop again
|
Zerotorescue@215
|
281 autoSelectedItemCountAddon = altName;
|
Zerotorescue@215
|
282
|
Zerotorescue@215
|
283 return altValue, altName;
|
Zerotorescue@215
|
284 end
|
Zerotorescue@35
|
285 end
|
Zerotorescue@35
|
286
|
Zerotorescue@35
|
287 return;
|
Zerotorescue@35
|
288 end
|
Zerotorescue@35
|
289
|
Zerotorescue@23
|
290 function addon:GetItemCount(itemId, group)
|
Zerotorescue@13
|
291 itemId = tonumber(itemId);
|
Zerotorescue@13
|
292
|
Zerotorescue@13
|
293 if not itemId then return; end
|
Zerotorescue@13
|
294
|
Zerotorescue@35
|
295 local itemCountAddon = self:GetItemCountAddon(group);
|
Zerotorescue@23
|
296
|
Zerotorescue@215
|
297 return (itemCountAddon and itemCountAddon.GetTotalCount and itemCountAddon.GetTotalCount(itemId)) or -1;
|
Zerotorescue@0
|
298 end
|
Zerotorescue@0
|
299
|
Zerotorescue@50
|
300 function addon:GetLocalItemCount(itemId, group)
|
Zerotorescue@50
|
301 itemId = tonumber(itemId);
|
Zerotorescue@50
|
302
|
Zerotorescue@50
|
303 if not itemId then return; end
|
Zerotorescue@50
|
304
|
Zerotorescue@50
|
305 local itemCountAddon = self:GetItemCountAddon(group);
|
Zerotorescue@50
|
306
|
Zerotorescue@50
|
307 local currentItemCount;
|
Zerotorescue@50
|
308
|
Zerotorescue@50
|
309 if itemCountAddon and itemCountAddon.GetCharacterCount then
|
Zerotorescue@50
|
310 local bag, bank, auctionHouse, mail = itemCountAddon.GetCharacterCount(itemId);
|
Zerotorescue@50
|
311
|
Zerotorescue@50
|
312 local selectedLocalItemCountSources = self:GetOptionByKey(group, "localItemData");
|
Zerotorescue@50
|
313
|
Zerotorescue@50
|
314 currentItemCount = 0;
|
Zerotorescue@50
|
315 if selectedLocalItemCountSources["Bag"] then
|
Zerotorescue@50
|
316 currentItemCount = currentItemCount + bag;
|
Zerotorescue@50
|
317 end
|
Zerotorescue@50
|
318 if selectedLocalItemCountSources["Bank"] then
|
Zerotorescue@50
|
319 currentItemCount = currentItemCount + bank;
|
Zerotorescue@50
|
320 end
|
Zerotorescue@50
|
321 if selectedLocalItemCountSources["Auction House"] then
|
Zerotorescue@50
|
322 currentItemCount = currentItemCount + auctionHouse;
|
Zerotorescue@50
|
323 end
|
Zerotorescue@50
|
324 if selectedLocalItemCountSources["Mailbox"] then
|
Zerotorescue@50
|
325 currentItemCount = currentItemCount + mail;
|
Zerotorescue@50
|
326 end
|
Zerotorescue@50
|
327 end
|
Zerotorescue@50
|
328
|
Zerotorescue@50
|
329 return currentItemCount or -1;
|
Zerotorescue@50
|
330 end
|
Zerotorescue@50
|
331
|
Zerotorescue@23
|
332 function addon:GetAuctionValue(itemLink, group)
|
Zerotorescue@23
|
333 if not itemLink then return -5; end
|
Zerotorescue@13
|
334
|
Zerotorescue@23
|
335 local selectedExternalAddon = self:GetOptionByKey(group, "auctionPricingAddon");
|
Zerotorescue@23
|
336
|
Zerotorescue@23
|
337 if self.supportedAddons.auctionPricing[selectedExternalAddon] and self.supportedAddons.auctionPricing[selectedExternalAddon].IsEnabled() then
|
Zerotorescue@13
|
338 -- Try to use the default auction pricing addon
|
Zerotorescue@1
|
339
|
Zerotorescue@23
|
340 return self.supportedAddons.auctionPricing[selectedExternalAddon].GetValue(itemLink);
|
Zerotorescue@13
|
341 else
|
Zerotorescue@13
|
342 -- Default not available, get the first one then
|
Zerotorescue@1
|
343
|
Zerotorescue@13
|
344 for name, value in pairs(self.supportedAddons.auctionPricing) do
|
Zerotorescue@13
|
345 if value.IsEnabled() then
|
Zerotorescue@13
|
346 return value.GetValue(itemLink);
|
Zerotorescue@13
|
347 end
|
Zerotorescue@1
|
348 end
|
Zerotorescue@1
|
349 end
|
Zerotorescue@7
|
350
|
Zerotorescue@7
|
351 return -2;
|
Zerotorescue@1
|
352 end
|
Zerotorescue@1
|
353
|
Zerotorescue@65
|
354
|
Zerotorescue@65
|
355
|
Zerotorescue@65
|
356
|
Zerotorescue@65
|
357
|
Zerotorescue@62
|
358 -- Slash commands
|
Zerotorescue@62
|
359
|
Zerotorescue@62
|
360 local slashArgs = {};
|
Zerotorescue@62
|
361 local slashError = "Wrong argument, the following arguments are available:";
|
Zerotorescue@62
|
362
|
Zerotorescue@62
|
363 function addon:CommandHandler(message)
|
Zerotorescue@122
|
364 local cmd, arg = ssplit(" ", (message or ""), 2);
|
Zerotorescue@122
|
365 cmd = slower(cmd);
|
Zerotorescue@62
|
366
|
Zerotorescue@62
|
367 if slashArgs[cmd] then
|
Zerotorescue@62
|
368 -- Pass a reference to the addon (to be used as "self") and the provided arg
|
Zerotorescue@62
|
369 slashArgs[cmd](addon, arg);
|
Zerotorescue@62
|
370 else
|
Zerotorescue@98
|
371 addon:Print(slashError);
|
Zerotorescue@62
|
372 end
|
Zerotorescue@62
|
373 end
|
Zerotorescue@62
|
374
|
Zerotorescue@62
|
375 function addon:RegisterSlash(func, args, description)
|
Zerotorescue@62
|
376 for _, arg in pairs(args) do
|
Zerotorescue@62
|
377 slashArgs[arg] = func;
|
Zerotorescue@62
|
378 end
|
Zerotorescue@62
|
379
|
Zerotorescue@62
|
380 if description then
|
Zerotorescue@62
|
381 slashError = slashError .. "\n" .. description;
|
Zerotorescue@62
|
382 end
|
Zerotorescue@62
|
383 end
|
Zerotorescue@62
|
384
|
Zerotorescue@65
|
385
|
Zerotorescue@65
|
386
|
Zerotorescue@65
|
387
|
Zerotorescue@65
|
388
|
Zerotorescue@106
|
389 function addon:ColorCode(num, required)
|
Zerotorescue@106
|
390 local percentage = ( num / required );
|
Zerotorescue@106
|
391
|
Zerotorescue@106
|
392 if percentage >= addon.db.profile.defaults.colors.green then
|
Zerotorescue@106
|
393 return sformat("|cff00ff00%d|r", num);
|
Zerotorescue@106
|
394 elseif percentage >= addon.db.profile.defaults.colors.yellow then
|
Zerotorescue@106
|
395 return sformat("|cffffff00%d|r", num);
|
Zerotorescue@106
|
396 elseif percentage >= addon.db.profile.defaults.colors.orange then
|
Zerotorescue@106
|
397 return sformat("|cffff9933%d|r", num);
|
Zerotorescue@106
|
398 elseif percentage >= addon.db.profile.defaults.colors.red then
|
Zerotorescue@106
|
399 return sformat("|cffff0000%d|r", num);
|
Zerotorescue@106
|
400 else
|
Zerotorescue@106
|
401 return num;
|
Zerotorescue@106
|
402 end
|
Zerotorescue@106
|
403 end
|
Zerotorescue@106
|
404
|
Zerotorescue@106
|
405 function addon:DisplayItemCount(value, minimumStock)
|
Zerotorescue@106
|
406 if value == -1 then
|
Zerotorescue@106
|
407 return "|cffffff00Unknown|r";
|
Zerotorescue@188
|
408 elseif value == -2 then
|
Zerotorescue@188
|
409 return "|cffffff00-|r";
|
Zerotorescue@106
|
410 elseif value == -3 then
|
Zerotorescue@106
|
411 return "|cffffff00Unknown|r";
|
Zerotorescue@106
|
412 else
|
Zerotorescue@106
|
413 return sformat("%s / %d", self:ColorCode(value, minimumStock), minimumStock);
|
Zerotorescue@106
|
414 end
|
Zerotorescue@106
|
415 end
|
Zerotorescue@106
|
416
|
Zerotorescue@62
|
417 -- Readable money
|
Zerotorescue@62
|
418
|
Zerotorescue@62
|
419 local goldText = "%s%d|cffffd700g|r ";
|
Zerotorescue@62
|
420 local silverText = "%s%d|cffc7c7cfs|r ";
|
Zerotorescue@62
|
421 local copperText = "%s%d|cffeda55fc|r";
|
Zerotorescue@62
|
422
|
Zerotorescue@62
|
423 function addon:ReadableMoney(copper, clean)
|
Zerotorescue@62
|
424 local text = "";
|
Zerotorescue@62
|
425
|
Zerotorescue@128
|
426 local gold = floor( copper / COPPER_PER_GOLD );
|
Zerotorescue@62
|
427 if gold > 0 then
|
Zerotorescue@106
|
428 text = sformat(goldText, text, gold);
|
Zerotorescue@62
|
429 end
|
Zerotorescue@62
|
430
|
Zerotorescue@62
|
431 if not clean or (not gold or gold < 10) then
|
Zerotorescue@128
|
432 local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
|
Zerotorescue@62
|
433 if silver > 0 then
|
Zerotorescue@106
|
434 text = sformat(silverText, text, silver);
|
Zerotorescue@62
|
435 end
|
Zerotorescue@62
|
436
|
Zerotorescue@62
|
437 if not clean or (not gold or gold < 1) then
|
Zerotorescue@128
|
438 local copper = floor( copper % COPPER_PER_SILVER );
|
Zerotorescue@62
|
439 if copper > 0 or text == "" then
|
Zerotorescue@106
|
440 text = sformat(copperText, text, copper);
|
Zerotorescue@62
|
441 end
|
Zerotorescue@62
|
442 end
|
Zerotorescue@62
|
443 end
|
Zerotorescue@62
|
444
|
Zerotorescue@62
|
445
|
Zerotorescue@122
|
446 return strim(text);
|
Zerotorescue@62
|
447 end
|
Zerotorescue@62
|
448
|
Zerotorescue@62
|
449 function addon:ReadableMoneyToCopper(value)
|
Zerotorescue@62
|
450 -- If a player enters a value it will be filled without color codes
|
Zerotorescue@62
|
451 -- If it is retrieved from the database, it will be colored coded
|
Zerotorescue@62
|
452 -- Thus we look for both
|
Zerotorescue@122
|
453 local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g"));
|
Zerotorescue@122
|
454 local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s"));
|
Zerotorescue@122
|
455 local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c"));
|
Zerotorescue@62
|
456
|
Zerotorescue@62
|
457 return ( (gold or 0) * COPPER_PER_GOLD ) + ( (silver or 0) * COPPER_PER_SILVER ) + (copper or 0);
|
Zerotorescue@62
|
458 end
|
Zerotorescue@62
|
459
|
Zerotorescue@62
|
460 function addon:ValidateReadableMoney(info, value)
|
Zerotorescue@62
|
461 -- If a player enters a value it will be filled without color codes
|
Zerotorescue@62
|
462 -- If it is retrieved from the database, it will be colored coded
|
Zerotorescue@62
|
463 -- Thus we look for both
|
Zerotorescue@122
|
464 local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g"));
|
Zerotorescue@122
|
465 local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s"));
|
Zerotorescue@122
|
466 local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c"));
|
Zerotorescue@62
|
467
|
Zerotorescue@62
|
468 if not gold and not silver and not copper then
|
Zerotorescue@62
|
469 return "The provided amount of money is invalid. Please provide the amount of money as #g#s#c, e.g. 591617g24s43c.";
|
Zerotorescue@62
|
470 else
|
Zerotorescue@62
|
471 return true;
|
Zerotorescue@62
|
472 end
|
Zerotorescue@62
|
473 end
|
Zerotorescue@62
|
474
|
Zerotorescue@0
|
475
|
Zerotorescue@0
|
476
|
Zerotorescue@65
|
477
|
Zerotorescue@65
|
478
|
Zerotorescue@13
|
479 -- Public
|
Zerotorescue@13
|
480
|
Zerotorescue@36
|
481 function IMRegisterPricingAddon(name, get, enabled, onSelect)
|
Zerotorescue@13
|
482 addon.supportedAddons.auctionPricing[name] = {
|
Zerotorescue@156
|
483 ["GetValue"] = get,
|
Zerotorescue@156
|
484 ["IsEnabled"] = enabled,
|
Zerotorescue@156
|
485 ["OnSelect"] = onSelect,
|
Zerotorescue@13
|
486 };
|
Zerotorescue@13
|
487 end
|
Zerotorescue@13
|
488
|
Zerotorescue@156
|
489 function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled, onSelect, getGuildNames, setGuildState)
|
Zerotorescue@13
|
490 addon.supportedAddons.itemCount[name] = {
|
Zerotorescue@156
|
491 ["GetTotalCount"] = getTotal,
|
Zerotorescue@156
|
492 ["GetCharacterCount"] = getCharacter,
|
Zerotorescue@156
|
493 ["IsEnabled"] = enabled,
|
Zerotorescue@156
|
494 ["OnSelect"] = onSelect,
|
Zerotorescue@156
|
495 ["GetGuildNames"] = getGuildNames,
|
Zerotorescue@156
|
496 ["SetGuildState"] = setGuildState,
|
Zerotorescue@13
|
497 };
|
Zerotorescue@13
|
498 end
|
Zerotorescue@13
|
499
|
Zerotorescue@50
|
500 function IMRegisterCraftingAddon(name, queue, enabled, onSelect)
|
Zerotorescue@13
|
501 addon.supportedAddons.crafting[name] = {
|
Zerotorescue@156
|
502 ["Queue"] = queue,
|
Zerotorescue@156
|
503 ["IsEnabled"] = enabled,
|
Zerotorescue@156
|
504 ["OnSelect"] = onSelect,
|
Zerotorescue@13
|
505 };
|
Zerotorescue@13
|
506 end
|
Zerotorescue@13
|
507
|
Zerotorescue@62
|
508 -- We need a global command handler for our chat-links
|
Zerotorescue@62
|
509 function InventoriumCommandHandler(msg)
|
Zerotorescue@62
|
510 addon:CommandHandler(msg);
|
Zerotorescue@62
|
511 end
|
Zerotorescue@62
|
512
|
Zerotorescue@13
|
513
|
Zerotorescue@13
|
514
|
Zerotorescue@65
|
515
|
Zerotorescue@65
|
516
|
Zerotorescue@76
|
517 -- General
|
Zerotorescue@76
|
518
|
Zerotorescue@76
|
519 addon.Colors = {
|
Zerotorescue@157
|
520 ["Red"] = { 1, 0, 0 },
|
Zerotorescue@157
|
521 ["Orange"] = { 1, .46, .1 },
|
Zerotorescue@157
|
522 ["Green"] = { 0, 1, 0 },
|
Zerotorescue@157
|
523 ["Blue"] = { 0, 0, 1 },
|
Zerotorescue@157
|
524 ["Yellow"] = { 1, 1, 0 },
|
Zerotorescue@157
|
525 ["Cyan"] = { 0, 1, 1 },
|
Zerotorescue@76
|
526 }; -- easy to extend if more colors are needed
|
Zerotorescue@76
|
527 function addon:Print(text, color)
|
Zerotorescue@76
|
528 local red, green, blue;
|
Zerotorescue@76
|
529
|
Zerotorescue@76
|
530 if color then
|
Zerotorescue@76
|
531 red, green, blue = color[1], color[2], color[3];
|
Zerotorescue@76
|
532 end
|
Zerotorescue@76
|
533
|
Zerotorescue@76
|
534 DEFAULT_CHAT_FRAME:AddMessage(text or "", red, green, blue, nil, 5);
|
Zerotorescue@76
|
535 end
|
Zerotorescue@76
|
536
|
Zerotorescue@95
|
537 function addon:GetItemId(itemLink)
|
Zerotorescue@84
|
538 itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part
|
Zerotorescue@84
|
539 itemLink = itemLink and tonumber(itemLink);
|
Zerotorescue@84
|
540
|
Zerotorescue@84
|
541 return itemLink;
|
Zerotorescue@84
|
542 end
|
Zerotorescue@84
|
543
|
Zerotorescue@13
|
544 -- Debug
|
Zerotorescue@0
|
545
|
Zerotorescue@176
|
546 local function ReadableTable(t, includeKeys, jumps)
|
Zerotorescue@176
|
547 local tabs = "";
|
Zerotorescue@176
|
548 for i = 1, (jumps or 0) do
|
Zerotorescue@176
|
549 tabs = tabs .. " ";
|
Zerotorescue@176
|
550 end
|
Zerotorescue@176
|
551
|
Zerotorescue@176
|
552 local temp = "{\n";
|
Zerotorescue@176
|
553
|
Zerotorescue@169
|
554 for i, v in pairs(t) do
|
Zerotorescue@169
|
555 if type(v) == "table" then
|
Zerotorescue@176
|
556 if includeKeys then
|
Zerotorescue@188
|
557 local key = (type(i) == "number" and tostring(i)) or sformat("\"%s\"", tostring(i));
|
Zerotorescue@176
|
558
|
Zerotorescue@188
|
559 temp = sformat("%s%s [%s] => %s,\n", temp, tabs, key, ReadableTable(v, includeKeys, (jumps or 0) + 1));
|
Zerotorescue@176
|
560 else
|
Zerotorescue@188
|
561 temp = sformat("%s%s %s,\n", temp, tabs, ReadableTable(v, includeKeys, (jumps or 0) + 1));
|
Zerotorescue@176
|
562 end
|
Zerotorescue@169
|
563 else
|
Zerotorescue@176
|
564 if includeKeys then
|
Zerotorescue@188
|
565 local key = (type(i) == "number" and tostring(i)) or sformat("\"%s\"", tostring(i));
|
Zerotorescue@188
|
566 local value = (type(v) == "number" and tostring(v)) or sformat("\"%s\"", tostring(v));
|
Zerotorescue@176
|
567
|
Zerotorescue@188
|
568 temp = sformat("%s%s [%s] => %s,\n", temp, tabs, key, value);
|
Zerotorescue@176
|
569 else
|
Zerotorescue@188
|
570 local value = (type(v) == "number" and tostring(v)) or sformat("\"%s\"", tostring(v));
|
Zerotorescue@176
|
571
|
Zerotorescue@188
|
572 temp = sformat("%s%s %s,\n", temp, tabs, value);
|
Zerotorescue@176
|
573 end
|
Zerotorescue@169
|
574 end
|
Zerotorescue@169
|
575 end
|
Zerotorescue@176
|
576 temp = temp .. tabs .. "}";
|
Zerotorescue@176
|
577
|
Zerotorescue@169
|
578 return temp;
|
Zerotorescue@169
|
579 end
|
Zerotorescue@169
|
580
|
Zerotorescue@89
|
581 function addon:Debug(t, ...)
|
Zerotorescue@0
|
582 if not self.debugChannel and self.debugChannel ~= false then
|
Zerotorescue@0
|
583 -- 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
|
584 self.debugChannel = false;
|
Zerotorescue@0
|
585
|
Zerotorescue@0
|
586 for i = 1, NUM_CHAT_WINDOWS do
|
Zerotorescue@0
|
587 local name = GetChatWindowInfo(i);
|
Zerotorescue@0
|
588
|
Zerotorescue@176
|
589 if name:upper() == "IMDEBUG" then
|
Zerotorescue@0
|
590 self.debugChannel = _G["ChatFrame" .. i];
|
Zerotorescue@0
|
591 end
|
Zerotorescue@0
|
592 end
|
Zerotorescue@0
|
593 end
|
Zerotorescue@0
|
594
|
Zerotorescue@0
|
595 if self.debugChannel then
|
Zerotorescue@169
|
596 if type(t) == "table" then
|
Zerotorescue@176
|
597 t = ReadableTable(t, true);
|
Zerotorescue@169
|
598 end
|
Zerotorescue@169
|
599
|
Zerotorescue@110
|
600 self.debugChannel:AddMessage("|cffffff00Inventorium|r:" .. sformat(t, ...));
|
Zerotorescue@0
|
601 end
|
Zerotorescue@0
|
602 end
|