-
Notifications
You must be signed in to change notification settings - Fork 21
/
Timer.lua
48 lines (38 loc) · 1.07 KB
/
Timer.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
local UPDATE_INTERVAL = 0.1
local sinceLastUpdate = 0
local newDeathCount = 0
function WarpDeplete:OnTimerTick(elapsed)
sinceLastUpdate = sinceLastUpdate + elapsed
if sinceLastUpdate <= UPDATE_INTERVAL then
return
end
sinceLastUpdate = 0
newDeathCount = C_ChallengeMode.GetDeathCount()
if newDeathCount ~= self.state.deathCount then
self:SetDeathCount(newDeathCount)
end
self.state.timer = select(2, GetWorldElapsedTime(1))
-- These might change after the timer has started, so rerender
-- them once here
if self.state.timer > 0 and not self.state.timerStarted then
self.state.timerStarted = true
self:RenderForces()
self:RenderObjectives()
end
self:RenderTimer()
end
function WarpDeplete:StartTimerLoop()
if self.state.timerLoopRunning then
return
end
self.state.timerLoopRunning = true
sinceLastUpdate = 0
self.frames.root:SetScript("OnUpdate", function(_, elapsed)
WarpDeplete:OnTimerTick(elapsed)
end)
end
function WarpDeplete:StopTimerLoop()
sinceLastUpdate = 0
self.state.timerLoopRunning = false
self.frames.root:SetScript("OnUpdate", nil)
end