mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Update timer & text
This commit is contained in:
@@ -47,24 +47,26 @@ end
|
||||
--- The @{Timer} constructor
|
||||
-- @tparam Timer self @{Timer}
|
||||
-- @tparam node node Gui text node
|
||||
-- @tparam number seconds_from Start timer value in seconds
|
||||
-- @tparam number|nil seconds_from Start timer value in seconds
|
||||
-- @tparam number|nil seconds_to End timer value in seconds
|
||||
-- @tparam function|nil callback Function on timer end
|
||||
function Timer.init(self, node, seconds_from, seconds_to, callback)
|
||||
self.node = self:get_node(node)
|
||||
seconds_from = math.max(seconds_from, 0)
|
||||
seconds_to = math.max(seconds_to or 0, 0)
|
||||
|
||||
self.on_tick = Event()
|
||||
self.on_set_enabled = Event()
|
||||
self.on_timer_end = Event(callback)
|
||||
|
||||
self:set_to(seconds_from)
|
||||
self:set_interval(seconds_from, seconds_to)
|
||||
if seconds_from then
|
||||
seconds_from = math.max(seconds_from, 0)
|
||||
self:set_to(seconds_from)
|
||||
self:set_interval(seconds_from, seconds_to)
|
||||
|
||||
if seconds_to - seconds_from == 0 then
|
||||
self:set_state(false)
|
||||
self.on_timer_end:trigger(self:get_context(), self)
|
||||
if seconds_to - seconds_from == 0 then
|
||||
self:set_state(false)
|
||||
self.on_timer_end:trigger(self:get_context(), self)
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
|
Reference in New Issue
Block a user