-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.lua
237 lines (205 loc) · 5.99 KB
/
helpers.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
local _, NS = ...
local LibStub = LibStub
local type = type
local next = next
local pairs = pairs
local wipe = wipe
local getmetatable = getmetatable
local setmetatable = setmetatable
local RetrieveCorpse = RetrieveCorpse -- Resurrects when the player is standing near its corpse.
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local format = format
local select = select
local UnitClass = UnitClass
local GetClassColor = GetClassColor
local print = print
local mfloor = math.floor
local mmax = math.max
local After = C_Timer.After
local SharedMedia = LibStub("LibSharedMedia-3.0")
NS.write = function(...)
local playerClass = select(2, UnitClass("player"))
local playerClassHexColor = "|c" .. select(4, GetClassColor(playerClass))
print(playerClassHexColor .. "AutoBodyRes|r: ", ...)
end
NS.isDead = function()
return UnitIsDeadOrGhost("player")
end
NS.UpdateSize = function(frame, text)
frame:SetWidth(text:GetStringWidth())
frame:SetHeight(text:GetStringHeight())
end
NS.UpdateFont = function(frame)
frame:SetFont(SharedMedia:Fetch("font", NS.db.global.font), NS.db.global.fontsize, "OUTLINE")
end
NS.UpdateColor = function(frame)
frame:SetTextColor(NS.db.global.color.r, NS.db.global.color.g, NS.db.global.color.b, NS.db.global.color.a)
end
NS.secondsToMinutes = function(seconds)
return seconds / SECONDS_PER_MIN
end
NS.minutesToSeconds = function(minutes)
return minutes * SECONDS_PER_MIN
end
function ConvertSecondsToUnits(timestamp)
timestamp = mmax(timestamp, 0)
local days = mfloor(timestamp / SECONDS_PER_DAY)
timestamp = timestamp - (days * SECONDS_PER_DAY)
local hours = mfloor(timestamp / SECONDS_PER_HOUR)
timestamp = timestamp - (hours * SECONDS_PER_HOUR)
local minutes = mfloor(timestamp / SECONDS_PER_MIN)
timestamp = timestamp - (minutes * SECONDS_PER_MIN)
local seconds = mfloor(timestamp)
local milliseconds = timestamp - seconds
return {
days = days,
hours = hours,
minutes = minutes,
seconds = seconds,
milliseconds = milliseconds,
}
end
NS.secondsToClock = function(seconds, displayZeroHours)
local units = ConvertSecondsToUnits(seconds)
if units.hours > 0 or displayZeroHours then
return format(HOURS_MINUTES_SECONDS, units.hours, units.minutes, units.seconds)
else
return format(MINUTES_SECONDS, units.minutes, units.seconds)
end
end
NS.getSeconds = function(time)
return time % SECONDS_PER_MIN
end
NS.getMinutes = function(time)
return mfloor(time / SECONDS_PER_MIN)
end
NS.formatTime = function(time)
return NS.secondsToClock(time, false)
-- return sformat("%02d:%02d", NS.getMinutes(time), NS.getSeconds(time))
end
NS.RetrieveBody = function()
RetrieveCorpse()
After(0, function()
if NS.isDead() then
RetrieveCorpse()
end
end)
end
NS.IsEpicBattleground = function(instanceID)
local INSTANCE_IDS = {
[30] = true,
[1191] = true,
[2118] = true,
[628] = true,
[2197] = true,
}
return INSTANCE_IDS[instanceID]
end
NS.isEpicBattlegroundAllowed = function(instanceID)
local INSTANCE_IDS = {
[30] = NS.db.global.alteracvalley,
[1191] = NS.db.global.ashran,
[2118] = NS.db.global.battleforwintergrasp,
[628] = NS.db.global.isleofconquest,
[2197] = NS.db.global.korraksrevenge, -- isBrawl
-- [2] = NS.db.global.classicashran, -- isBrawl
-- [9] = NS.db.global.tarrenmillvssouthshore, -- isBrawl
}
return INSTANCE_IDS[instanceID]
end
NS.isBrawlAllowed = function(brawlID)
local BRAWL_IDS = {
-- [1] = NS.db.global.arathiblizzard,
-- [3] = NS.db.global.compstomp,
[17] = NS.db.global.cookingimpossible,
-- [5] = NS.db.global.deepsix,
-- [6] = NS.db.global.deepwinddunk,
-- [7] = NS.db.global.gravitylapse,
-- [10] = NS.db.global.templeofhotmogu,
[9] = NS.db.global.warsongscramble,
}
return BRAWL_IDS[brawlID]
end
NS.isBattlegroundAllowed = function(instanceID)
local INSTANCE_IDS = {
[2107] = NS.db.global.arathibasin,
[2656] = NS.db.global.deephaulravine,
[2245] = NS.db.global.deepwindgorge,
[566] = NS.db.global.eyeofthestorm,
[968] = NS.db.global.eyeofthestorm,
[1803] = NS.db.global.seethingshore,
[727] = NS.db.global.silvershardmines,
[761] = NS.db.global.thebattleforgilneas,
[998] = NS.db.global.templeofkotmogu,
[726] = NS.db.global.twinpeaks,
[2106] = NS.db.global.warsonggulch,
}
return INSTANCE_IDS[instanceID]
end
NS.CopyTable = function(src, dest)
-- Handle non-tables and previously-seen tables.
if type(src) ~= "table" then
return src
end
if dest and dest[src] then
return dest[src]
end
-- New table; mark it as seen an copy recursively.
local s = dest or {}
local res = {}
s[src] = res
for k, v in next, src do
res[NS.CopyTable(k, s)] = NS.CopyTable(v, s)
end
return setmetatable(res, getmetatable(src))
end
-- Copies table values from src to dst if they don't exist in dst
NS.CopyDefaults = function(src, dst)
if type(src) ~= "table" then
return {}
end
if type(dst) ~= "table" then
dst = {}
end
for k, v in pairs(src) do
if type(v) == "table" then
dst[k] = NS.CopyDefaults(v, dst[k])
elseif type(v) ~= type(dst[k]) then
dst[k] = v
end
end
return dst
end
-- Cleanup savedvariables by removing table values in src that no longer
-- exists in table dst (default settings)
NS.CleanupDB = function(src, dst)
for key, value in pairs(src) do
if dst[key] == nil then
if key ~= "version" then
src[key] = nil
end
elseif type(value) == "table" then
dst[key] = NS.CleanupDB(value, dst[key])
end
end
return dst
end
-- Pool for reusing tables. (Garbage collector isn't ran in combat unless max garbage is reached, which causes fps drops)
do
local pool = {}
NS.NewTable = function()
local t = next(pool) or {}
pool[t] = nil -- remove from pool
return t
end
NS.RemoveTable = function(tbl)
if tbl then
pool[wipe(tbl)] = true -- add to pool, wipe returns pointer to tbl here
end
end
NS.ReleaseTables = function()
if next(pool) then
pool = {}
end
end
end