mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 06:04:35 +00:00
managed expired state inside the timer rather than just checking if the time has expired; makes sure the callback fires even for zero length timers
This commit is contained in:
parent
795f2587d2
commit
dbce7e6083
@ -22,6 +22,7 @@ function timer:new(time, on_progress, on_finish)
|
||||
self.timer = 0
|
||||
self.on_progress = on_progress
|
||||
self.on_finish = on_finish
|
||||
self.has_expired = false
|
||||
self:reset(time)
|
||||
end
|
||||
|
||||
@ -30,7 +31,8 @@ function timer:update(dt)
|
||||
if not self:expired() then
|
||||
self.timer = self.timer + dt
|
||||
|
||||
--get the relevant callback
|
||||
--set the expired state and get the relevant callback
|
||||
self.has_expired = self.timer >= self.time
|
||||
local cb = self:expired()
|
||||
and self.on_finish
|
||||
or self.on_progress
|
||||
@ -43,7 +45,7 @@ end
|
||||
|
||||
--check if the timer has expired
|
||||
function timer:expired()
|
||||
return self.timer >= self.time
|
||||
return self.has_expired
|
||||
end
|
||||
|
||||
--get the timer's progress from 0 to 1
|
||||
|
Loading…
Reference in New Issue
Block a user