forked from xmyno/Broker_WorldQuests
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUtilities.lua
83 lines (73 loc) · 2.35 KB
/
Utilities.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
local _, addon = ...
local CONSTANTS = addon.CONSTANTS
--==========================================================
-- Utility Functions
--==========================================================
function BWQ:AbbreviateNumber(number)
number = tonumber(number)
if number >= 1000000 then
number = number / 1000000
return string.format((number % 1 == 0) and "%.0f%s" or "%.1f%s", number, "M")
elseif number >= 10000 then
return string.format("%.0f%s", number / 1000, "K")
end
return number
end
function BWQ:FormatTimeLeftString(minutes)
local timeLeftStr = ""
if not minutes or minutes <= 0 then return "" end
local days = math.floor(minutes / 1440)
local hours = math.floor((minutes % 1440) / 60)
local mins = minutes % 60
if days > 0 then
timeLeftStr = string.format("%dd %dh", days, hours)
elseif hours > 0 then
timeLeftStr = string.format("%dh %dm", hours, mins)
else
timeLeftStr = string.format("%dm", mins)
end
if minutes <= 120 then timeLeftStr = string.format("|cffD96932%s|r", timeLeftStr)
elseif minutes <= 240 then timeLeftStr = string.format("|cffDBA43B%s|r", timeLeftStr)
elseif minutes <= 480 then timeLeftStr = string.format("|cffE6D253%s|r", timeLeftStr)
elseif minutes <= 960 then timeLeftStr = string.format("|cffE6DA8E%s|r", timeLeftStr)
end
return timeLeftStr
end
-- Search for a mapID across all zones supported by the addon
function BWQ:SearchMapZones(table, mapID)
if not table then
if BWQcfg.spewDebugInfo then
print("[BWQ] Bad table provided to BWQ:SearchMapZones()")
end
return false, nil
end
for expansion, zones in pairs(table) do
for _, _mapID in ipairs(zones) do
if _mapID == mapID then
return true, expansion
end
end
end
return false, nil
end
-- Search for a mapID within a specific expansion supported by the addon
function BWQ:SearchSpecificExpansion(table, expansion, mapID)
if not table then
if BWQcfg.spewDebugInfo then
print("[BWQ] Bad table provided to BWQ:SearchSpecificExpansion()")
end
return false
end
if not table[expansion] then
if BWQcfg.spewDebugInfo then
print("[BWQ] Bad expansion string provided to BWQ:SearchSpecificExpansion()")
end
return false
end
for _, _mapID in ipairs(table[expansion]) do
if _mapID == mapID then
return true
end
end
return false
end