mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
fix(timer): set initial value of triggerOnEnd to true
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
---@class TimerPrivateProps
|
---@class TimerPrivateProps
|
||||||
---@field initialTime number the initial duration of the timer.
|
---@field initialTime number the initial duration of the timer.
|
||||||
---@field onEnd? fun() cb function triggered when the timer finishes
|
|
||||||
---@field async? boolean wether the timer should run asynchronously or not
|
---@field async? boolean wether the timer should run asynchronously or not
|
||||||
---@field startTime number the gametimer stamp of when the timer starts. changes when paused and played
|
---@field startTime number the gametimer stamp of when the timer starts. changes when paused and played
|
||||||
---@field triggerOnEnd boolean set in the forceEnd method using the optional param. wether or not the onEnd function is triggered when force ending the timer early
|
---@field triggerOnEnd boolean set in the forceEnd method using the optional param. wether or not the onEnd function is triggered when force ending the timer early
|
||||||
@@ -10,6 +9,7 @@
|
|||||||
---@class OxTimer : OxClass
|
---@class OxTimer : OxClass
|
||||||
---@field private private TimerPrivateProps
|
---@field private private TimerPrivateProps
|
||||||
---@field start fun(self: self, async?: boolean) starts the timer
|
---@field start fun(self: self, async?: boolean) starts the timer
|
||||||
|
---@field onEnd? fun() cb function triggered when the timer finishes
|
||||||
---@field forceEnd fun(self: self, triggerOnEnd: boolean) end timer early and optionally trigger the onEnd function still
|
---@field forceEnd fun(self: self, triggerOnEnd: boolean) end timer early and optionally trigger the onEnd function still
|
||||||
---@field isPaused fun(self: self): boolean returns wether the timer is paused or not
|
---@field isPaused fun(self: self): boolean returns wether the timer is paused or not
|
||||||
---@field pause fun(self: self) pauses the timer until play method is called
|
---@field pause fun(self: self) pauses the timer until play method is called
|
||||||
@@ -26,11 +26,12 @@ function timer:constructor(time, onEnd, async)
|
|||||||
assert(onEnd == nil or type(onEnd) == "function", "onEnd must be a function or nil")
|
assert(onEnd == nil or type(onEnd) == "function", "onEnd must be a function or nil")
|
||||||
assert(type(async) == "boolean" or async == nil, "async must be a boolean or nil")
|
assert(type(async) == "boolean" or async == nil, "async must be a boolean or nil")
|
||||||
|
|
||||||
|
self.onEnd = onEnd
|
||||||
self.private.initialTime = time
|
self.private.initialTime = time
|
||||||
self.private.currentTimeLeft = time
|
self.private.currentTimeLeft = time
|
||||||
self.private.startTime = 0
|
self.private.startTime = 0
|
||||||
self.private.paused = false
|
self.private.paused = false
|
||||||
self.private.onEnd = onEnd
|
self.private.triggerOnEnd = true
|
||||||
|
|
||||||
self:start(async)
|
self:start(async)
|
||||||
end
|
end
|
||||||
@@ -60,14 +61,6 @@ function timer:start(async)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function timer:onEnd()
|
|
||||||
if self:getTimeLeft('ms') > 0 then return end
|
|
||||||
|
|
||||||
if self.private.triggerOnEnd and self.private.onEnd then
|
|
||||||
self.private:onEnd()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function timer:forceEnd(triggerOnEnd)
|
function timer:forceEnd(triggerOnEnd)
|
||||||
if self:getTimeLeft('ms') <= 0 then return end
|
if self:getTimeLeft('ms') <= 0 then return end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user