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@62
|
13 local print, pairs, tonumber = _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@0
|
21 function addon:OnInitialize()
|
Zerotorescue@0
|
22 self:Debug("OnInitialize");
|
Zerotorescue@0
|
23
|
Zerotorescue@0
|
24 -- SAVED VARIABLES
|
Zerotorescue@0
|
25
|
Zerotorescue@0
|
26 local defaults = {
|
Zerotorescue@0
|
27 global = {
|
Zerotorescue@61
|
28 version = nil,
|
Zerotorescue@61
|
29 },
|
Zerotorescue@61
|
30 profile = {
|
Zerotorescue@0
|
31 defaults = {
|
Zerotorescue@13
|
32 auctionPricingAddon = "Auctioneer",
|
Zerotorescue@13
|
33 itemCountAddon = "Altoholic",
|
Zerotorescue@13
|
34 craftingAddon = "AdvancedTradeSkillWindow",
|
Zerotorescue@61
|
35 minLocalStock = 20,
|
Zerotorescue@57
|
36 alertBelowLocalMinimum = true,
|
Zerotorescue@61
|
37 minGlobalStock = 60,
|
Zerotorescue@61
|
38 alertBelowGlobalMinimum = true,
|
Zerotorescue@0
|
39 summaryThresholdShow = 10,
|
Zerotorescue@0
|
40 restockTarget = 60,
|
Zerotorescue@0
|
41 minCraftingQueue = 0.05,
|
Zerotorescue@0
|
42 bonusQueue = 0.1,
|
Zerotorescue@0
|
43 priceThreshold = 0,
|
Zerotorescue@13
|
44 summaryHidePriceThreshold = false,
|
Zerotorescue@40
|
45 trackAtCharacters = {
|
Zerotorescue@40
|
46 },
|
Zerotorescue@31
|
47 localItemData = {
|
Zerotorescue@31
|
48 ["Bag"] = true,
|
Zerotorescue@31
|
49 ["Auction House"] = true,
|
Zerotorescue@31
|
50 },
|
Zerotorescue@13
|
51 summary = {
|
Zerotorescue@13
|
52 speed = 5,
|
Zerotorescue@74
|
53 width = 700,
|
Zerotorescue@13
|
54 height = 600,
|
Zerotorescue@13
|
55 },
|
Zerotorescue@0
|
56 colors = {
|
Zerotorescue@17
|
57 red = 0,
|
Zerotorescue@17
|
58 orange = 0.3,
|
Zerotorescue@17
|
59 yellow = 0.6,
|
Zerotorescue@17
|
60 green = 0.95,
|
Zerotorescue@0
|
61 },
|
Zerotorescue@0
|
62 },
|
Zerotorescue@61
|
63 groups = {
|
Zerotorescue@61
|
64 },
|
Zerotorescue@0
|
65 },
|
Zerotorescue@0
|
66 factionrealm = {
|
Zerotorescue@40
|
67 characters = {
|
Zerotorescue@40
|
68 },
|
Zerotorescue@0
|
69 },
|
Zerotorescue@0
|
70 };
|
Zerotorescue@0
|
71
|
Zerotorescue@0
|
72 -- Register our saved variables database
|
Zerotorescue@11
|
73 self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true);
|
Zerotorescue@61
|
74
|
Zerotorescue@62
|
75 -- SLASH COMMANDS
|
Zerotorescue@62
|
76
|
Zerotorescue@62
|
77 -- Disable the AddonLoader slash commands
|
Zerotorescue@62
|
78 SLASH_INVENTORIUM1 = nil;
|
Zerotorescue@62
|
79 SLASH_IM1 = nil;
|
Zerotorescue@62
|
80
|
Zerotorescue@62
|
81 -- Register our own slash commands
|
Zerotorescue@62
|
82 SLASH_INVENTORIUM1 = "/inventorium";
|
Zerotorescue@62
|
83 SLASH_INVENTORIUM2 = "/im";
|
Zerotorescue@62
|
84 SlashCmdList["INVENTORIUM"] = function(msg)
|
Zerotorescue@62
|
85 addon:CommandHandler(msg);
|
Zerotorescue@62
|
86 end;
|
Zerotorescue@62
|
87
|
Zerotorescue@62
|
88 -- Debug command handling
|
Zerotorescue@62
|
89 self:RegisterSlash(function(this)
|
Zerotorescue@62
|
90 this.debugChannel = false;
|
Zerotorescue@62
|
91 for i = 1, NUM_CHAT_WINDOWS do
|
Zerotorescue@62
|
92 local name = GetChatWindowInfo(i);
|
Zerotorescue@62
|
93
|
Zerotorescue@62
|
94 if name:upper() == "DEBUG" then
|
Zerotorescue@62
|
95 this.debugChannel = _G["ChatFrame" .. i];
|
Zerotorescue@62
|
96
|
Zerotorescue@62
|
97 print("A debug channel already exists, used the old one. (" .. i .. ")");
|
Zerotorescue@62
|
98 return;
|
Zerotorescue@62
|
99 end
|
Zerotorescue@62
|
100 end
|
Zerotorescue@62
|
101
|
Zerotorescue@62
|
102 if not this.debugChannel then
|
Zerotorescue@62
|
103 -- Create a new debug channel
|
Zerotorescue@62
|
104 local chatFrame = FCF_OpenNewWindow('Debug');
|
Zerotorescue@62
|
105 ChatFrame_RemoveAllMessageGroups(chatFrame);
|
Zerotorescue@62
|
106 this.debugChannel = chatFrame;
|
Zerotorescue@62
|
107
|
Zerotorescue@62
|
108 print("New debug channel created.");
|
Zerotorescue@62
|
109 end
|
Zerotorescue@62
|
110 end, { "d", "debug" });
|
Zerotorescue@62
|
111
|
Zerotorescue@62
|
112 -- Remember this character is on this account
|
Zerotorescue@62
|
113 local playerName = UnitName("player");
|
Zerotorescue@62
|
114 if not self.db.factionrealm.characters[playerName] then
|
Zerotorescue@62
|
115 self.db.factionrealm.characters[playerName] = true;
|
Zerotorescue@62
|
116
|
Zerotorescue@62
|
117 -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports.
|
Zerotorescue@62
|
118 self.db.profile.defaults.trackAtCharacters[playerName] = true;
|
Zerotorescue@62
|
119 end
|
Zerotorescue@66
|
120
|
Zerotorescue@66
|
121 self:UpdateDatabase();
|
Zerotorescue@62
|
122 end
|
Zerotorescue@62
|
123
|
Zerotorescue@65
|
124
|
Zerotorescue@65
|
125
|
Zerotorescue@65
|
126
|
Zerotorescue@65
|
127
|
Zerotorescue@65
|
128 -- Database patching after new revisions
|
Zerotorescue@65
|
129
|
Zerotorescue@62
|
130 function addon:UpdateDatabase()
|
Zerotorescue@61
|
131 if not self.db.global.version or self.db.global.version < addonRevision then
|
Zerotorescue@61
|
132 -- Is our database outdated? Then patch it.
|
Zerotorescue@61
|
133
|
Zerotorescue@61
|
134 if not self.db.global.version then
|
Zerotorescue@61
|
135 -- Old version was before version was saved, many changes were done in that revision
|
Zerotorescue@61
|
136
|
Zerotorescue@61
|
137 print("Updating Inventorium database from version " .. (self.db.global.version or "Unknown") .. " to version " .. addonRevision .. "...");
|
Zerotorescue@61
|
138
|
Zerotorescue@61
|
139 if self.db.global and self.db.global.defaults then
|
Zerotorescue@61
|
140 print("Moving all global data into your current profile...");
|
Zerotorescue@61
|
141
|
Zerotorescue@61
|
142 -- All data mustn't be global but profile-based
|
Zerotorescue@61
|
143 self.db.profile.defaults = CopyTable(self.db.global.defaults);
|
Zerotorescue@61
|
144 self.db.profile.groups = CopyTable(self.db.global.groups);
|
Zerotorescue@61
|
145
|
Zerotorescue@61
|
146 self.db.global.defaults = nil;
|
Zerotorescue@61
|
147 self.db.global.groups = nil;
|
Zerotorescue@61
|
148
|
Zerotorescue@62
|
149 self.CommandHandler = function()
|
Zerotorescue@62
|
150 message("You must /reload once to finalize the Inventorium database updates. This will only be required once during the BETA.");
|
Zerotorescue@61
|
151 end;
|
Zerotorescue@62
|
152 self:CommandHandler();
|
Zerotorescue@61
|
153 end
|
Zerotorescue@61
|
154
|
Zerotorescue@61
|
155 if self.db.profile.defaults.minimumStock then
|
Zerotorescue@61
|
156 print("Copying the minimum stock value into the minimum global stock...");
|
Zerotorescue@61
|
157
|
Zerotorescue@61
|
158 -- We added another stock option and renamed the old to be more obvious about what it means
|
Zerotorescue@61
|
159 self.db.profile.defaults.minGlobalStock = self.db.profile.defaults.minimumStock;
|
Zerotorescue@61
|
160 self.db.profile.defaults.minimumStock = nil;
|
Zerotorescue@61
|
161 end
|
Zerotorescue@61
|
162
|
Zerotorescue@61
|
163 if self.db.profile.defaults.minimumLocalStock then
|
Zerotorescue@61
|
164 print("Renaming the minimum local stock property...");
|
Zerotorescue@61
|
165
|
Zerotorescue@61
|
166 -- We added another stock option and then renamed it
|
Zerotorescue@61
|
167 self.db.profile.defaults.minLocalStock = self.db.profile.defaults.minimumLocalStock;
|
Zerotorescue@61
|
168 self.db.profile.defaults.minimumLocalStock = nil;
|
Zerotorescue@61
|
169 end
|
Zerotorescue@61
|
170
|
Zerotorescue@61
|
171 if self.db.profile.defaults.alertBelowMinimum then
|
Zerotorescue@61
|
172 print("Copying the alert below minimum value into the alert below global minimum value...");
|
Zerotorescue@61
|
173
|
Zerotorescue@61
|
174 -- We added another stock option and then renamed it
|
Zerotorescue@61
|
175 self.db.profile.defaults.alertBelowGlobalMinimum = self.db.profile.defaults.alertBelowMinimum;
|
Zerotorescue@61
|
176 self.db.profile.defaults.alertBelowMinimum = nil;
|
Zerotorescue@61
|
177 end
|
Zerotorescue@61
|
178
|
Zerotorescue@61
|
179 -- Go through all groups to see if there's one with the above two renamed variables
|
Zerotorescue@61
|
180 for groupName, values in pairs(self.db.profile.groups) do
|
Zerotorescue@61
|
181 if values.minimumStock then
|
Zerotorescue@61
|
182 values.minGlobalStock = values.minimumStock;
|
Zerotorescue@61
|
183 values.minimumStock = nil;
|
Zerotorescue@61
|
184 end
|
Zerotorescue@61
|
185 end
|
Zerotorescue@61
|
186 end
|
Zerotorescue@61
|
187
|
Zerotorescue@61
|
188 -- Remember the version of our database
|
Zerotorescue@61
|
189 self.db.global.version = addonRevision;
|
Zerotorescue@61
|
190 end
|
Zerotorescue@46
|
191 end
|
Zerotorescue@46
|
192
|
Zerotorescue@0
|
193 function addon:GetItemId(itemLink)
|
Zerotorescue@13
|
194 itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part
|
Zerotorescue@0
|
195 itemLink = itemLink and tonumber(itemLink);
|
Zerotorescue@0
|
196
|
Zerotorescue@0
|
197 return itemLink;
|
Zerotorescue@0
|
198 end
|
Zerotorescue@0
|
199
|
Zerotorescue@62
|
200 function addon:GetOptionByKey(groupName, optionName, noDefault)
|
Zerotorescue@62
|
201 if groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName][optionName] ~= nil then
|
Zerotorescue@62
|
202 -- If this option exists within the settings of this group
|
Zerotorescue@62
|
203
|
Zerotorescue@62
|
204 return addon.db.profile.groups[groupName][optionName];
|
Zerotorescue@62
|
205 elseif groupName and addon.db.profile.groups[groupName] and addon.db.profile.groups[groupName].virtualGroup ~= "" and not noDefault then
|
Zerotorescue@62
|
206 -- If a virtual group was selected
|
Zerotorescue@62
|
207
|
Zerotorescue@62
|
208 return self:GetOptionByKey(addon.db.profile.groups[groupName].virtualGroup, optionName, noDefault);
|
Zerotorescue@62
|
209 elseif addon.db.profile.defaults[optionName] and not noDefault then
|
Zerotorescue@62
|
210 return addon.db.profile.defaults[optionName];
|
Zerotorescue@62
|
211 else
|
Zerotorescue@62
|
212 return nil;
|
Zerotorescue@0
|
213 end
|
Zerotorescue@0
|
214 end
|
Zerotorescue@0
|
215
|
Zerotorescue@35
|
216 function addon:GetItemCountAddon(group)
|
Zerotorescue@35
|
217 local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
|
Zerotorescue@35
|
218
|
Zerotorescue@35
|
219 if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then
|
Zerotorescue@35
|
220 -- Try to use the default item count addon
|
Zerotorescue@35
|
221
|
Zerotorescue@35
|
222 return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon;
|
Zerotorescue@35
|
223 else
|
Zerotorescue@35
|
224 -- Default not available, get the first one then
|
Zerotorescue@35
|
225
|
Zerotorescue@35
|
226 for name, value in pairs(self.supportedAddons.itemCount) do
|
Zerotorescue@35
|
227 if value.IsEnabled() then
|
Zerotorescue@35
|
228 return value, name;
|
Zerotorescue@35
|
229 end
|
Zerotorescue@35
|
230 end
|
Zerotorescue@35
|
231 end
|
Zerotorescue@35
|
232
|
Zerotorescue@35
|
233 return;
|
Zerotorescue@35
|
234 end
|
Zerotorescue@35
|
235
|
Zerotorescue@23
|
236 function addon:GetItemCount(itemId, group)
|
Zerotorescue@13
|
237 itemId = tonumber(itemId);
|
Zerotorescue@13
|
238
|
Zerotorescue@13
|
239 if not itemId then return; end
|
Zerotorescue@13
|
240
|
Zerotorescue@35
|
241 local itemCountAddon = self:GetItemCountAddon(group);
|
Zerotorescue@23
|
242
|
Zerotorescue@35
|
243 return (itemCountAddon and itemCountAddon.GetTotalCount(itemId)) or -1;
|
Zerotorescue@0
|
244 end
|
Zerotorescue@0
|
245
|
Zerotorescue@50
|
246 function addon:GetLocalItemCount(itemId, group)
|
Zerotorescue@50
|
247 itemId = tonumber(itemId);
|
Zerotorescue@50
|
248
|
Zerotorescue@50
|
249 if not itemId then return; end
|
Zerotorescue@50
|
250
|
Zerotorescue@50
|
251 local itemCountAddon = self:GetItemCountAddon(group);
|
Zerotorescue@50
|
252
|
Zerotorescue@50
|
253 local currentItemCount;
|
Zerotorescue@50
|
254
|
Zerotorescue@50
|
255 if itemCountAddon and itemCountAddon.GetCharacterCount then
|
Zerotorescue@50
|
256 local bag, bank, auctionHouse, mail = itemCountAddon.GetCharacterCount(itemId);
|
Zerotorescue@50
|
257
|
Zerotorescue@50
|
258 local selectedLocalItemCountSources = self:GetOptionByKey(group, "localItemData");
|
Zerotorescue@50
|
259
|
Zerotorescue@50
|
260 currentItemCount = 0;
|
Zerotorescue@50
|
261 if selectedLocalItemCountSources["Bag"] then
|
Zerotorescue@50
|
262 currentItemCount = currentItemCount + bag;
|
Zerotorescue@50
|
263 end
|
Zerotorescue@50
|
264 if selectedLocalItemCountSources["Bank"] then
|
Zerotorescue@50
|
265 currentItemCount = currentItemCount + bank;
|
Zerotorescue@50
|
266 end
|
Zerotorescue@50
|
267 if selectedLocalItemCountSources["Auction House"] then
|
Zerotorescue@50
|
268 currentItemCount = currentItemCount + auctionHouse;
|
Zerotorescue@50
|
269 end
|
Zerotorescue@50
|
270 if selectedLocalItemCountSources["Mailbox"] then
|
Zerotorescue@50
|
271 currentItemCount = currentItemCount + mail;
|
Zerotorescue@50
|
272 end
|
Zerotorescue@50
|
273 end
|
Zerotorescue@50
|
274
|
Zerotorescue@50
|
275 return currentItemCount or -1;
|
Zerotorescue@50
|
276 end
|
Zerotorescue@50
|
277
|
Zerotorescue@23
|
278 function addon:GetAuctionValue(itemLink, group)
|
Zerotorescue@23
|
279 if not itemLink then return -5; end
|
Zerotorescue@13
|
280
|
Zerotorescue@23
|
281 local selectedExternalAddon = self:GetOptionByKey(group, "auctionPricingAddon");
|
Zerotorescue@23
|
282
|
Zerotorescue@23
|
283 if self.supportedAddons.auctionPricing[selectedExternalAddon] and self.supportedAddons.auctionPricing[selectedExternalAddon].IsEnabled() then
|
Zerotorescue@13
|
284 -- Try to use the default auction pricing addon
|
Zerotorescue@1
|
285
|
Zerotorescue@23
|
286 return self.supportedAddons.auctionPricing[selectedExternalAddon].GetValue(itemLink);
|
Zerotorescue@13
|
287 else
|
Zerotorescue@13
|
288 -- Default not available, get the first one then
|
Zerotorescue@1
|
289
|
Zerotorescue@13
|
290 for name, value in pairs(self.supportedAddons.auctionPricing) do
|
Zerotorescue@13
|
291 if value.IsEnabled() then
|
Zerotorescue@13
|
292 return value.GetValue(itemLink);
|
Zerotorescue@13
|
293 end
|
Zerotorescue@1
|
294 end
|
Zerotorescue@1
|
295 end
|
Zerotorescue@7
|
296
|
Zerotorescue@7
|
297 return -2;
|
Zerotorescue@1
|
298 end
|
Zerotorescue@1
|
299
|
Zerotorescue@65
|
300
|
Zerotorescue@65
|
301
|
Zerotorescue@65
|
302
|
Zerotorescue@65
|
303
|
Zerotorescue@62
|
304 -- Slash commands
|
Zerotorescue@62
|
305
|
Zerotorescue@62
|
306 local slashArgs = {};
|
Zerotorescue@62
|
307 local slashError = "Wrong argument, the following arguments are available:";
|
Zerotorescue@62
|
308
|
Zerotorescue@62
|
309 function addon:CommandHandler(message)
|
Zerotorescue@62
|
310 local cmd, arg = string.split(" ", (message or ""), 2);
|
Zerotorescue@62
|
311 cmd = string.lower(cmd);
|
Zerotorescue@62
|
312
|
Zerotorescue@62
|
313 if slashArgs[cmd] then
|
Zerotorescue@62
|
314 -- Pass a reference to the addon (to be used as "self") and the provided arg
|
Zerotorescue@62
|
315 slashArgs[cmd](addon, arg);
|
Zerotorescue@62
|
316 else
|
Zerotorescue@62
|
317 print(slashError);
|
Zerotorescue@62
|
318 end
|
Zerotorescue@62
|
319 end
|
Zerotorescue@62
|
320
|
Zerotorescue@62
|
321 function addon:RegisterSlash(func, args, description)
|
Zerotorescue@62
|
322 for _, arg in pairs(args) do
|
Zerotorescue@62
|
323 slashArgs[arg] = func;
|
Zerotorescue@62
|
324 end
|
Zerotorescue@62
|
325
|
Zerotorescue@62
|
326 if description then
|
Zerotorescue@62
|
327 slashError = slashError .. "\n" .. description;
|
Zerotorescue@62
|
328 end
|
Zerotorescue@62
|
329 end
|
Zerotorescue@62
|
330
|
Zerotorescue@65
|
331
|
Zerotorescue@65
|
332
|
Zerotorescue@65
|
333
|
Zerotorescue@65
|
334
|
Zerotorescue@62
|
335 -- Readable money
|
Zerotorescue@62
|
336
|
Zerotorescue@62
|
337 local goldText = "%s%d|cffffd700g|r ";
|
Zerotorescue@62
|
338 local silverText = "%s%d|cffc7c7cfs|r ";
|
Zerotorescue@62
|
339 local copperText = "%s%d|cffeda55fc|r";
|
Zerotorescue@62
|
340
|
Zerotorescue@62
|
341 function addon:ReadableMoney(copper, clean)
|
Zerotorescue@62
|
342 local text = "";
|
Zerotorescue@62
|
343
|
Zerotorescue@62
|
344 local gold = floor( copper / COPPER_PER_GOLD );
|
Zerotorescue@62
|
345 if gold > 0 then
|
Zerotorescue@62
|
346 text = goldText:format(text, gold);
|
Zerotorescue@62
|
347 end
|
Zerotorescue@62
|
348
|
Zerotorescue@62
|
349 if not clean or (not gold or gold < 10) then
|
Zerotorescue@62
|
350 local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
|
Zerotorescue@62
|
351 if silver > 0 then
|
Zerotorescue@62
|
352 text = silverText:format(text, silver);
|
Zerotorescue@62
|
353 end
|
Zerotorescue@62
|
354
|
Zerotorescue@62
|
355 if not clean or (not gold or gold < 1) then
|
Zerotorescue@62
|
356 local copper = floor( copper % COPPER_PER_SILVER );
|
Zerotorescue@62
|
357 if copper > 0 or text == "" then
|
Zerotorescue@62
|
358 text = copperText:format(text, copper);
|
Zerotorescue@62
|
359 end
|
Zerotorescue@62
|
360 end
|
Zerotorescue@62
|
361 end
|
Zerotorescue@62
|
362
|
Zerotorescue@62
|
363
|
Zerotorescue@62
|
364 return string.trim(text);
|
Zerotorescue@62
|
365 end
|
Zerotorescue@62
|
366
|
Zerotorescue@62
|
367 function addon:ReadableMoneyToCopper(value)
|
Zerotorescue@62
|
368 -- If a player enters a value it will be filled without color codes
|
Zerotorescue@62
|
369 -- If it is retrieved from the database, it will be colored coded
|
Zerotorescue@62
|
370 -- Thus we look for both
|
Zerotorescue@62
|
371 local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
|
Zerotorescue@62
|
372 local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
|
Zerotorescue@62
|
373 local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
|
Zerotorescue@62
|
374
|
Zerotorescue@62
|
375 return ( (gold or 0) * COPPER_PER_GOLD ) + ( (silver or 0) * COPPER_PER_SILVER ) + (copper or 0);
|
Zerotorescue@62
|
376 end
|
Zerotorescue@62
|
377
|
Zerotorescue@62
|
378 function addon:ValidateReadableMoney(info, value)
|
Zerotorescue@62
|
379 -- If a player enters a value it will be filled without color codes
|
Zerotorescue@62
|
380 -- If it is retrieved from the database, it will be colored coded
|
Zerotorescue@62
|
381 -- Thus we look for both
|
Zerotorescue@62
|
382 local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
|
Zerotorescue@62
|
383 local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
|
Zerotorescue@62
|
384 local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
|
Zerotorescue@62
|
385
|
Zerotorescue@62
|
386 if not gold and not silver and not copper then
|
Zerotorescue@62
|
387 return "The provided amount of money is invalid. Please provide the amount of money as #g#s#c, e.g. 591617g24s43c.";
|
Zerotorescue@62
|
388 else
|
Zerotorescue@62
|
389 return true;
|
Zerotorescue@62
|
390 end
|
Zerotorescue@62
|
391 end
|
Zerotorescue@62
|
392
|
Zerotorescue@0
|
393
|
Zerotorescue@0
|
394
|
Zerotorescue@65
|
395
|
Zerotorescue@65
|
396
|
Zerotorescue@13
|
397 -- Public
|
Zerotorescue@13
|
398
|
Zerotorescue@36
|
399 function IMRegisterPricingAddon(name, get, enabled, onSelect)
|
Zerotorescue@13
|
400 addon.supportedAddons.auctionPricing[name] = {
|
Zerotorescue@13
|
401 GetValue = get,
|
Zerotorescue@13
|
402 IsEnabled = enabled,
|
Zerotorescue@36
|
403 OnSelect = onSelect,
|
Zerotorescue@13
|
404 };
|
Zerotorescue@13
|
405 end
|
Zerotorescue@13
|
406
|
Zerotorescue@50
|
407 function IMRegisterItemCountAddon(name, getTotal, getCharacter, enabled, onSelect)
|
Zerotorescue@13
|
408 addon.supportedAddons.itemCount[name] = {
|
Zerotorescue@17
|
409 GetTotalCount = getTotal,
|
Zerotorescue@17
|
410 GetCharacterCount = getCharacter,
|
Zerotorescue@13
|
411 IsEnabled = enabled,
|
Zerotorescue@50
|
412 OnSelect = onSelect,
|
Zerotorescue@13
|
413 };
|
Zerotorescue@13
|
414 end
|
Zerotorescue@13
|
415
|
Zerotorescue@50
|
416 function IMRegisterCraftingAddon(name, queue, enabled, onSelect)
|
Zerotorescue@13
|
417 addon.supportedAddons.crafting[name] = {
|
Zerotorescue@13
|
418 Queue = queue,
|
Zerotorescue@13
|
419 IsEnabled = enabled,
|
Zerotorescue@50
|
420 OnSelect = onSelect,
|
Zerotorescue@13
|
421 };
|
Zerotorescue@13
|
422 end
|
Zerotorescue@13
|
423
|
Zerotorescue@62
|
424 -- We need a global command handler for our chat-links
|
Zerotorescue@62
|
425 function InventoriumCommandHandler(msg)
|
Zerotorescue@62
|
426 addon:CommandHandler(msg);
|
Zerotorescue@62
|
427 end
|
Zerotorescue@62
|
428
|
Zerotorescue@13
|
429
|
Zerotorescue@13
|
430
|
Zerotorescue@65
|
431
|
Zerotorescue@65
|
432
|
Zerotorescue@13
|
433 -- Debug
|
Zerotorescue@0
|
434
|
Zerotorescue@0
|
435 function addon:Debug(t)
|
Zerotorescue@0
|
436 if not self.debugChannel and self.debugChannel ~= false then
|
Zerotorescue@0
|
437 -- 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
|
438 self.debugChannel = false;
|
Zerotorescue@0
|
439
|
Zerotorescue@0
|
440 for i = 1, NUM_CHAT_WINDOWS do
|
Zerotorescue@0
|
441 local name = GetChatWindowInfo(i);
|
Zerotorescue@0
|
442
|
Zerotorescue@0
|
443 if name:upper() == "DEBUG" then
|
Zerotorescue@0
|
444 self.debugChannel = _G["ChatFrame" .. i];
|
Zerotorescue@0
|
445 end
|
Zerotorescue@0
|
446 end
|
Zerotorescue@0
|
447 end
|
Zerotorescue@0
|
448
|
Zerotorescue@0
|
449 if self.debugChannel then
|
Zerotorescue@0
|
450 self.debugChannel:AddMessage(t);
|
Zerotorescue@0
|
451 end
|
Zerotorescue@0
|
452 end
|