Skip to content

Commit

Permalink
fix(timer): set initial value of triggerOnEnd to true
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Jan 27, 2025
1 parent 769fa35 commit d0a0f34
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions imports/timer/shared.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d0a0f34

Please sign in to comment.