diff --git a/imports/timer/shared.lua b/imports/timer/shared.lua index ce6aebff..f39daaee 100644 --- a/imports/timer/shared.lua +++ b/imports/timer/shared.lua @@ -1,6 +1,5 @@ ---@class TimerPrivateProps ---@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 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 @@ -10,6 +9,7 @@ ---@class OxTimer : OxClass ---@field private private TimerPrivateProps ---@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 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 @@ -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(type(async) == "boolean" or async == nil, "async must be a boolean or nil") + self.onEnd = onEnd self.private.initialTime = time self.private.currentTimeLeft = time self.private.startTime = 0 self.private.paused = false - self.private.onEnd = onEnd + self.private.triggerOnEnd = true self:start(async) end @@ -60,14 +61,6 @@ function timer:start(async) 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) if self:getTimeLeft('ms') <= 0 then return end