vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Name: Abacus-2.0
3 Revision: $Rev: 15222 $
4 Author(s): ckknight (ckknight@gmail.com)
5 Website: http://ckknight.wowinterface.com/
6 Documentation: http://wiki.wowace.com/index.php/Abacus-2.0
7 SVN: http://svn.wowace.com/root/trunk/AbacusLib/Abacus-2.0
8 Description: A library to provide tools for formatting money and time.
9 Dependencies: AceLibrary
10 ]]
11  
12 local MAJOR_VERSION = "Abacus-2.0"
13 local MINOR_VERSION = "$Revision: 15222 $"
14  
15 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
16 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
17  
18 local Abacus = {}
19  
20 local table_setn
21 do
22 local version = GetBuildInfo()
23 if string.find(version, "^2%.") then
24 -- 2.0.0
25 table_setn = function() end
26 else
27 table_setn = table.setn
28 end
29 end
30  
31 local COPPER_ABBR = string.lower(string.sub(COPPER, 1, 1))
32 local SILVER_ABBR = string.lower(string.sub(SILVER, 1, 1))
33 local GOLD_ABBR = string.lower(string.sub(GOLD, 1, 1))
34 if (string.byte(COPPER_ABBR) or 128) > 127 then
35 -- non-western
36 COPPER_ABBR = COPPER
37 SILVER_ABBR = SILVER
38 GOLD_ABBR = GOLD
39 end
40  
41 local COLOR_WHITE = "ffffff"
42 local COLOR_GREEN = "00ff00"
43 local COLOR_RED = "ff0000"
44 local COLOR_COPPER = "eda55f"
45 local COLOR_SILVER = "c7c7cf"
46 local COLOR_GOLD = "ffd700"
47  
48 local L_DAY_ONELETTER_ABBR = string.gsub(DAY_ONELETTER_ABBR, "%s*%%d%s*", "")
49 local L_HOUR_ONELETTER_ABBR = string.gsub(HOUR_ONELETTER_ABBR, "%s*%%d%s*", "")
50 local L_MINUTE_ONELETTER_ABBR = string.gsub(MINUTE_ONELETTER_ABBR, "%s*%%d%s*", "")
51 local L_SECOND_ONELETTER_ABBR = string.gsub(SECOND_ONELETTER_ABBR, "%s*%%d%s*", "")
52  
53 local L_UNDETERMINED = "Undetermined"
54  
55 if ( GetLocale() =="koKR" ) then
56 L_UNDETERMINED = "측정불가"
57 end
58  
59 local inf = 1/0
60  
61 function Abacus:FormatMoneyExtended(value, colorize, textColor)
62 self:argCheck(value, 2, "number")
63 local gold = abs(value / 10000)
64 local silver = abs(mod(value / 100, 100))
65 local copper = abs(mod(value, 100))
66  
67 local negl = ""
68 local color = COLOR_WHITE
69 if value > 0 then
70 if textColor then
71 color = COLOR_GREEN
72 end
73 elseif value < 0 then
74 negl = "-"
75 if textColor then
76 color = COLOR_RED
77 end
78 end
79 if colorize then
80 if value == inf or value == -inf then
81 return format("|cff%s%s|r", color, value)
82 elseif value ~= value then
83 return format("|cff%s0|r|cff%s %s|r", COLOR_WHITE, COLOR_COPPER, COPPER)
84 elseif value >= 10000 or value <= -10000 then
85 return format("|cff%s%s%d|r|cff%s %s|r |cff%s%d|r|cff%s %s|r |cff%s%d|r|cff%s %s|r", color, negl, gold, COLOR_GOLD, GOLD, color, silver, COLOR_SILVER, SILVER, color, copper, COLOR_COPPER, COPPER)
86 elseif value >= 100 or value <= -100 then
87 return format("|cff%s%s%d|r|cff%s %s|r |cff%s%d|r|cff%s %s|r", color, negl, silver, COLOR_SILVER, SILVER, color, copper, COLOR_COPPER, COPPER)
88 else
89 return format("|cff%s%s%d|r|cff%s %s|r", color, negl, copper, COLOR_COPPER, COPPER)
90 end
91 else
92 if value == inf or value == -inf then
93 return format("%s", value)
94 elseif value ~= value then
95 return format("0 %s", COPPER)
96 elseif value >= 10000 or value <= -10000 then
97 return format("%s%d %s %d %s %d %s", negl, gold, GOLD, silver, SILVER, copper, COPPER)
98 elseif value >= 100 or value <= -100 then
99 return format("%s%d %s %d %s", negl, silver, SILVER, copper, COPPER)
100 else
101 return format("%s%d %s", negl, copper, COPPER)
102 end
103 end
104 end
105  
106 function Abacus:FormatMoneyFull(value, colorize, textColor)
107 self:argCheck(value, 2, "number")
108 local gold = abs(value / 10000)
109 local silver = abs(mod(value / 100, 100))
110 local copper = abs(mod(value, 100))
111  
112 local negl = ""
113 local color = COLOR_WHITE
114 if value > 0 then
115 if textColor then
116 color = COLOR_GREEN
117 end
118 elseif value < 0 then
119 negl = "-"
120 if textColor then
121 color = COLOR_RED
122 end
123 end
124 if colorize then
125 if value == inf or value == -inf then
126 return format("|cff%s%s|r", color, value)
127 elseif value ~= value then
128 return format("|cff%s0|r|cff%s%s|r", COLOR_WHITE, COLOR_COPPER, COPPER_ABBR)
129 elseif value >= 10000 or value <= -10000 then
130 return format("|cff%s%s%d|r|cff%s%s|r |cff%s%d|r|cff%s%s|r |cff%s%d|r|cff%s%s|r", color, negl, gold, COLOR_GOLD, GOLD_ABBR, color, silver, COLOR_SILVER, SILVER_ABBR, color, copper, COLOR_COPPER, COPPER_ABBR)
131 elseif value >= 100 or value <= -100 then
132 return format("|cff%s%s%d|r|cff%s%s|r |cff%s%d|r|cff%s%s|r", color, negl, silver, COLOR_SILVER, SILVER_ABBR, color, copper, COLOR_COPPER, COPPER_ABBR)
133 else
134 return format("|cff%s%s%d|r|cff%s%s|r", color, negl, copper, COLOR_COPPER, COPPER_ABBR)
135 end
136 else
137 if value == inf or value == -inf then
138 return format("%s", value)
139 elseif value ~= value then
140 return format("0%s", COPPER_ABBR)
141 elseif value >= 10000 or value <= -10000 then
142 return format("%s%d%s %d%s %d%s", negl, gold, GOLD_ABBR, silver, SILVER_ABBR, copper, COPPER_ABBR)
143 elseif value >= 100 or value <= -100 then
144 return format("%s%d%s %d%s", negl, silver, SILVER_ABBR, copper, COPPER_ABBR)
145 else
146 return format("%s%d%s", negl, copper, COPPER_ABBR)
147 end
148 end
149 end
150  
151 function Abacus:FormatMoneyShort(copper, colorize, textColor)
152 self:argCheck(copper, 2, "number")
153 local color = COLOR_WHITE
154 if textColor then
155 if copper > 0 then
156 color = COLOR_GREEN
157 elseif copper < 0 then
158 color = COLOR_RED
159 end
160 end
161 if colorize then
162 if copper == inf or copper == -inf then
163 return format("|cff%s%s|r", color, copper)
164 elseif copper ~= copper then
165 return format("|cff%s0|r|cff%s%s|r", COLOR_WHITE, COLOR_COPPER, COPPER_ABBR)
166 elseif copper >= 10000 or copper <= -10000 then
167 return format("|cff%s%.1f|r|cff%s%s|r", color, copper / 10000, COLOR_GOLD, GOLD_ABBR)
168 elseif copper >= 100 or copper <= -100 then
169 return format("|cff%s%.1f|r|cff%s%s|r", color, copper / 100, COLOR_SILVER, SILVER_ABBR)
170 else
171 return format("|cff%s%d|r|cff%s%s|r", color, copper, COLOR_COPPER, COPPER_ABBR)
172 end
173 else
174 if value == copper or value == -copper then
175 return format("%s", copper)
176 elseif copper ~= copper then
177 return format("0%s", COPPER_ABBR)
178 elseif copper >= 10000 or copper <= -10000 then
179 return format("%.1f%s", copper / 10000, GOLD_ABBR)
180 elseif copper >= 100 or copper <= -100 then
181 return format("%.1f%s", copper / 100, SILVER_ABBR)
182 else
183 return format("%.0f%s", copper, COPPER_ABBR)
184 end
185 end
186 end
187  
188 function Abacus:FormatMoneyCondensed(value, colorize, textColor)
189 self:argCheck(value, 2, "number")
190 local negl = ""
191 local negr = ""
192 if value < 0 then
193 if colorize and textColor then
194 negl = "|cffff0000-(|r"
195 negr = "|cffff0000)|r"
196 else
197 negl = "-("
198 negr = ")"
199 end
200 end
201 local gold = floor(math.abs(value) / 10000)
202 local silver = mod(floor(math.abs(value) / 100), 100)
203 local copper = mod(floor(math.abs(value)), 100)
204 if colorize then
205 if value == inf or value == -inf then
206 return format("%s|cff%s%s|r%s", negl, COLOR_COPPER, math.abs(value), negr)
207 elseif value ~= value then
208 return format("|cff%s0|r", COLOR_COPPER)
209 elseif gold ~= 0 then
210 return format("%s|cff%s%d|r.|cff%s%02d|r.|cff%s%02d|r%s", negl, COLOR_GOLD, gold, COLOR_SILVER, silver, COLOR_COPPER, copper, negr)
211 elseif silver ~= 0 then
212 return format("%s|cff%s%d|r.|cff%s%02d|r%s", negl, COLOR_SILVER, silver, COLOR_COPPER, copper, negr)
213 else
214 return format("%s|cff%s%d|r%s", negl, COLOR_COPPER, copper, negr)
215 end
216 else
217 if value == inf or value == -inf then
218 return tostring(value)
219 elseif value ~= value then
220 return "0"
221 elseif gold ~= 0 then
222 return format("%s%d.%02d.%02d%s", negl, gold, silver, copper, negr)
223 elseif silver ~= 0 then
224 return format("%s%d.%02d%s", negl, silver, copper, negr)
225 else
226 return format("%s%d%s", negl, copper, negr)
227 end
228 end
229 end
230  
231 local t
232 function Abacus:FormatDurationExtended(duration, colorize, hideSeconds)
233 self:argCheck(duration, 2, "number")
234 local negative = ""
235 if duration ~= duration then
236 duration = 0
237 end
238 if duration < 0 then
239 negative = "-"
240 duration = -duration
241 end
242 local days = floor(duration / 86400)
243 local hours = mod(floor(duration / 3600), 24)
244 local mins = mod(floor(duration / 60), 60)
245 local secs = mod(floor(duration), 60)
246 if not t then
247 t = {}
248 else
249 for k in pairs(t) do
250 t[k] = nil
251 end
252 table_setn(t, 0)
253 end
254 if not colorize then
255 if not duration or duration > 86400*365 then
256 return L_UNDETERMINED
257 end
258 if days > 1 then
259 table.insert(t, format("%d %s", days, DAYS_ABBR_P1))
260 elseif days == 1 then
261 table.insert(t, format("%d %s", days, DAYS_ABBR))
262 end
263 if hours > 1 then
264 table.insert(t, format("%d %s", hours, HOURS_ABBR_P1))
265 elseif hours == 1 then
266 table.insert(t, format("%d %s", hours, HOURS_ABBR))
267 end
268 if mins > 1 then
269 table.insert(t, format("%d %s", mins, MINUTES_ABBR_P1))
270 elseif mins == 1 then
271 table.insert(t, format("%d %s", mins, MINUTES_ABBR))
272 end
273 if not hideSeconds then
274 if secs > 1 then
275 table.insert(t, format("%d %s", secs, SECONDS_ABBR_P1))
276 elseif secs == 1 then
277 table.insert(t, format("%d %s", secs, SECONDS_ABBR))
278 end
279 end
280 if table.getn(t) == 0 then
281 if not hideSeconds then
282 return "0 " .. SECONDS_ABBR_P1
283 else
284 return "0 " .. MINUTES_ABBR_P1
285 end
286 else
287 return negative .. table.concat(t, " ")
288 end
289 else
290 if not duration or duration > 86400*365 then
291 return "|cffffffff"..L_UNDETERMINED.."|r"
292 end
293 if days > 1 then
294 table.insert(t, format("|cffffffff%d|r %s", days, DAYS_ABBR_P1))
295 elseif days == 1 then
296 table.insert(t, format("|cffffffff%d|r %s", days, DAYS_ABBR))
297 end
298 if hours > 1 then
299 table.insert(t, format("|cffffffff%d|r %s", hours, HOURS_ABBR_P1))
300 elseif hours == 1 then
301 table.insert(t, format("|cffffffff%d|r %s", hours, HOURS_ABBR))
302 end
303 if mins > 1 then
304 table.insert(t, format("|cffffffff%d|r %s", mins, MINUTES_ABBR_P1))
305 elseif mins == 1 then
306 table.insert(t, format("|cffffffff%d|r %s", mins, MINUTES_ABBR))
307 end
308 if not hideSeconds then
309 if secs > 1 then
310 table.insert(t, format("|cffffffff%d|r %s", secs, SECONDS_ABBR_P1))
311 elseif secs == 1 then
312 table.insert(t, format("|cffffffff%d|r %s", secs, SECONDS_ABBR))
313 end
314 end
315 if table.getn(t) == 0 then
316 if not hideSeconds then
317 return "|cffffffff0|r " .. SECONDS_ABBR_P1
318 else
319 return "|cffffffff0|r " .. MINUTES_ABBR_P1
320 end
321 elseif negative == "-" then
322 return "|cffffffff-|r" .. table.concat(t, " ")
323 else
324 return table.concat(t, " ")
325 end
326 end
327 end
328  
329 --local DAY_ONELETTER_ABBR = string.gsub(DAY_ONELETTER_ABBR, "%s*%%d%s*", "")
330 --local HOUR_ONELETTER_ABBR = string.gsub(HOUR_ONELETTER_ABBR, "%s*%%d%s*", "")
331 --local MINUTE_ONELETTER_ABBR = string.gsub(MINUTE_ONELETTER_ABBR, "%s*%%d%s*", "")
332 --local SECOND_ONELETTER_ABBR = string.gsub(SECOND_ONELETTER_ABBR, "%s*%%d%s*", "")
333  
334 function Abacus:FormatDurationFull(duration, colorize, hideSeconds)
335 self:argCheck(duration, 2, "number")
336 local negative = ""
337 if duration ~= duration then
338 duration = 0
339 end
340 if duration < 0 then
341 negative = "-"
342 duration = -duration
343 end
344 if not colorize then
345 if not hideSeconds then
346 if not duration or duration > 86400*365 then
347 return L_UNDETERMINED
348 elseif duration >= 86400 then
349 return format("%s%d%s %02d%s %02d%s %02d%s", negative, duration/86400, L_DAY_ONELETTER_ABBR, mod(duration/3600, 24), L_HOUR_ONELETTER_ABBR, mod(duration/60, 60), L_MINUTE_ONELETTER_ABBR, mod(duration, 60), L_SECOND_ONELETTER_ABBR)
350 elseif duration >= 3600 then
351 return format("%s%d%s %02d%s %02d%s", negative, duration/3600, L_HOUR_ONELETTER_ABBR, mod(duration/60, 60), L_MINUTE_ONELETTER_ABBR, mod(duration, 60), L_SECOND_ONELETTER_ABBR)
352 elseif duration >= 120 then
353 return format("%s%d%s %02d%s", negative, duration/60, L_MINUTE_ONELETTER_ABBR, mod(duration, 60), L_SECOND_ONELETTER_ABBR)
354 else
355 return format("%s%d%s", negative, duration, L_SECOND_ONELETTER_ABBR)
356 end
357 else
358 if not duration or duration > 86400*365 then
359 return L_UNDETERMINED
360 elseif duration >= 86400 then
361 return format("%s%d%s %02d%s %02d%s", negative, duration/86400, L_DAY_ONELETTER_ABBR, mod(duration/3600, 24), L_HOUR_ONELETTER_ABBR, mod(duration/60, 60), L_MINUTE_ONELETTER_ABBR)
362 elseif duration >= 3600 then
363 return format("%s%d%s %02d%s", negative, duration/3600, L_HOUR_ONELETTER_ABBR, mod(duration/60, 60), L_MINUTE_ONELETTER_ABBR)
364 else
365 return format("%s%d%s", negative, duration/60, L_MINUTE_ONELETTER_ABBR)
366 end
367 end
368 else
369 if not hideSeconds then
370 if not duration or duration > 86400*365 then
371 return "|cffffffff"..L_UNDETERMINED.."|r"
372 elseif duration >= 86400 then
373 return format("|cffffffff%s%d|r%s |cffffffff%02d|r%s |cffffffff%02d|r%s |cffffffff%02d|r%s", negative, duration/86400, L_DAY_ONELETTER_ABBR, mod(duration/3600, 24), L_HOUR_ONELETTER_ABBR, mod(duration/60, 60), L_MINUTE_ONELETTER_ABBR, mod(duration, 60), L_SECOND_ONELETTER_ABBR)
374 elseif duration >= 3600 then
375 return format("|cffffffff%s%d|r%s |cffffffff%02d|r%s |cffffffff%02d|r%s", negative, duration/3600, L_HOUR_ONELETTER_ABBR, mod(duration/60, 60), L_MINUTE_ONELETTER_ABBR, mod(duration, 60), L_SECOND_ONELETTER_ABBR)
376 elseif duration >= 120 then
377 return format("|cffffffff%s%d|r%s |cffffffff%02d|r%s", negative, duration/60, L_MINUTE_ONELETTER_ABBR, mod(duration, 60), L_SECOND_ONELETTER_ABBR)
378 else
379 return format("|cffffffff%s%d|r%s", negative, duration, L_SECOND_ONELETTER_ABBR)
380 end
381 else
382 if not duration or duration > 86400*365 then
383 return "|cffffffff"..L_UNDETERMINED.."|r"
384 elseif duration >= 86400 then
385 return format("|cffffffff%s%d|r%s |cffffffff%02d|r%s |cffffffff%02d|r%s", negative, duration/86400, L_DAY_ONELETTER_ABBR, mod(duration/3600, 24), L_HOUR_ONELETTER_ABBR, mod(duration/60, 60), L_MINUTE_ONELETTER_ABBR)
386 elseif duration >= 3600 then
387 return format("|cffffffff%s%d|r%s |cffffffff%02d|r%s", negative, duration/3600, L_HOUR_ONELETTER_ABBR, mod(duration/60, 60), L_MINUTE_ONELETTER_ABBR)
388 else
389 return format("|cffffffff%s%d|r%s", negative, duration/60, L_MINUTE_ONELETTER_ABBR)
390 end
391 end
392 end
393 end
394  
395 function Abacus:FormatDurationShort(duration, colorize, hideSeconds)
396 self:argCheck(duration, 2, "number")
397 local negative = ""
398 if duration ~= duration then
399 duration = 0
400 end
401 if duration < 0 then
402 negative = "-"
403 duration = -duration
404 end
405 if not colorize then
406 if not duration or duration >= 86400*365 then
407 return "***"
408 elseif duration >= 172800 then
409 return format("%s%.1f %s", negative, duration/86400, DAYS_ABBR_P1)
410 elseif duration >= 7200 then
411 return format("%s%.1f %s", negative, duration/3600, HOURS_ABBR_P1)
412 elseif duration >= 120 or not hideSeconds then
413 return format("%s%.1f %s", negative, duration/60, MINUTES_ABBR_P1)
414 else
415 return format("%s%.0f %s", negative, duration, SECONDS_ABBR_P1)
416 end
417 else
418 if not duration or duration >= 86400*365 then
419 return "|cffffffff***|r"
420 elseif duration >= 172800 then
421 return format("|cffffffff%s%.1f|r %s", negative, duration/86400, DAYS_ABBR_P1)
422 elseif duration >= 7200 then
423 return format("|cffffffff%s%.1f|r %s", negative, duration/3600, HOURS_ABBR_P1)
424 elseif duration >= 120 or not hideSeconds then
425 return format("|cffffffff%s%.1f|r %s", negative, duration/60, MINUTES_ABBR_P1)
426 else
427 return format("|cffffffff%s%.0f|r %s", negative, duration, SECONDS_ABBR_P1)
428 end
429 end
430 end
431  
432 function Abacus:FormatDurationCondensed(duration, colorize, hideSeconds)
433 self:argCheck(duration, 2, "number")
434 local negative = ""
435 if duration ~= duration then
436 duration = 0
437 end
438 if duration < 0 then
439 negative = "-"
440 duration = -duration
441 end
442 if not colorize then
443 if hideSeconds then
444 if not duration or duration >= 86400*365 then
445 return format("%s**%s **:**", negative, L_DAY_ONELETTER_ABBR)
446 elseif duration >= 86400 then
447 return format("%s%d%s %d:%02d", negative, duration/86400, L_DAY_ONELETTER_ABBR, mod(duration/3600, 24), mod(duration/60, 60))
448 else
449 return format("%s%d:%02d", negative, duration/3600, mod(duration/60, 60))
450 end
451 else
452 if not duration or duration >= 86400*365 then
453 return negative .. "**:**:**:**"
454 elseif duration >= 86400 then
455 return format("%s%d%s %d:%02d:%02d", negative, duration/86400, L_DAY_ONELETTER_ABBR, mod(duration/3600, 24), mod(duration/60, 60), mod(duration, 60))
456 elseif duration >= 3600 then
457 return format("%s%d:%02d:%02d", negative, duration/3600, mod(duration/60, 60), mod(duration, 60))
458 else
459 return format("%s%d:%02d", negative, duration/60, mod(duration, 60))
460 end
461 end
462 else
463 if hideSeconds then
464 if not duration or duration >= 86400*365 then
465 return format("|cffffffff%s**|r%s |cffffffff**|r:|cffffffff**|r", negative, L_DAY_ONELETTER_ABBR)
466 elseif duration >= 86400 then
467 return format("|cffffffff%s%d|r%s |cffffffff%d|r:|cffffffff%02d|r", negative, duration/86400, L_DAY_ONELETTER_ABBR, mod(duration/3600, 24), mod(duration/60, 60))
468 else
469 return format("|cffffffff%s%d|r:|cffffffff%02d|r", negative, duration/3600, mod(duration/60, 60))
470 end
471 else
472 if not duration or duration >= 86400*365 then
473 return format("|cffffffff%s**|r%s |cffffffff**|r:|cffffffff**|r:|cffffffff**|r", negative, L_DAY_ONELETTER_ABBR)
474 elseif duration >= 86400 then
475 return format("|cffffffff%s%d|r%s |cffffffff%d|r:|cffffffff%02d|r:|cffffffff%02d|r", negative, duration/86400, L_DAY_ONELETTER_ABBR, mod(duration/3600, 24), mod(duration/60, 60), mod(duration, 60))
476 elseif duration >= 3600 then
477 return format("|cffffffff%s%d|r:|cffffffff%02d|r:|cffffffff%02d|r", negative, duration/3600, mod(duration/60, 60), mod(duration, 60))
478 else
479 return format("|cffffffff%s%d|r:|cffffffff%02d|r", negative, duration/60, mod(duration, 60))
480 end
481 end
482 end
483 end
484  
485 AceLibrary:Register(Abacus, MAJOR_VERSION, MINOR_VERSION)
486 Abacus = nil