From 68c66f0bc054f4c59b73c2e252aa11cf66cb5bd6 Mon Sep 17 00:00:00 2001 From: Frowmza <66181451+Frowmza@users.noreply.github.com> Date: Sat, 9 Nov 2024 03:31:02 +0100 Subject: [PATCH 1/5] fix(timer): restart can prevent executing onEnd function --- imports/timer/shared.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/imports/timer/shared.lua b/imports/timer/shared.lua index d3ed76b24..2f8e42af3 100644 --- a/imports/timer/shared.lua +++ b/imports/timer/shared.lua @@ -96,6 +96,7 @@ function timer:restart(async) self:forceEnd(false) Wait(0) self.private.currentTimeLeft = self.private.initialTime + self.private.triggerOnEnd = true self.private.startTime = 0 self:start(async) end From 62fd6af521d0c048b7246ad499bd1ee3bc741780 Mon Sep 17 00:00:00 2001 From: Frowmza <66181451+Frowmza@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:46:01 +0100 Subject: [PATCH 2/5] Update shared.lua Didn't notice we can disable/enable it thru :forceEnd --- imports/timer/shared.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/imports/timer/shared.lua b/imports/timer/shared.lua index 2f8e42af3..074c0fcd1 100644 --- a/imports/timer/shared.lua +++ b/imports/timer/shared.lua @@ -93,10 +93,9 @@ function timer:isPaused() end function timer:restart(async) - self:forceEnd(false) + self:forceEnd(true) Wait(0) self.private.currentTimeLeft = self.private.initialTime - self.private.triggerOnEnd = true self.private.startTime = 0 self:start(async) end From 40c0647101d4658121bb72cd6e8f84f143c270cd Mon Sep 17 00:00:00 2001 From: Frowmza <66181451+Frowmza@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:24:47 +0100 Subject: [PATCH 3/5] feat(timer): add triggerOnEnd toggle for restart method --- imports/timer/shared.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imports/timer/shared.lua b/imports/timer/shared.lua index 074c0fcd1..edb026701 100644 --- a/imports/timer/shared.lua +++ b/imports/timer/shared.lua @@ -92,8 +92,8 @@ function timer:isPaused() return self.private.paused end -function timer:restart(async) - self:forceEnd(true) +function timer:restart(async, triggerOnEnd) + self:forceEnd(triggerOnEnd) Wait(0) self.private.currentTimeLeft = self.private.initialTime self.private.startTime = 0 From 606e2b331b89576683918c3eb8838ee40216337c Mon Sep 17 00:00:00 2001 From: Frowmza <66181451+Frowmza@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:48:22 +0100 Subject: [PATCH 4/5] feat(timer): edit onEnd function on restart --- imports/timer/shared.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/imports/timer/shared.lua b/imports/timer/shared.lua index edb026701..545613d7f 100644 --- a/imports/timer/shared.lua +++ b/imports/timer/shared.lua @@ -92,8 +92,13 @@ function timer:isPaused() return self.private.paused end -function timer:restart(async, triggerOnEnd) - self:forceEnd(triggerOnEnd) +function timer:restart(async, onEnd) + self:forceEnd(not not onEnd) + + if type(onEnd) == 'function' then + self.private.onEnd = onEnd + end + Wait(0) self.private.currentTimeLeft = self.private.initialTime self.private.startTime = 0 From a71b8ecf9653c4f7d0ec6a853134e46125cee304 Mon Sep 17 00:00:00 2001 From: Frowmza <66181451+Frowmza@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:56:49 +0100 Subject: [PATCH 5/5] chore(timer): restart data type --- imports/timer/shared.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/imports/timer/shared.lua b/imports/timer/shared.lua index 545613d7f..108f8f996 100644 --- a/imports/timer/shared.lua +++ b/imports/timer/shared.lua @@ -10,6 +10,7 @@ ---@class OxTimer : OxClass ---@field private private TimerPrivateProps ---@field start fun(self: self, async?: boolean) starts the timer +---@field restart fun(self: self, async?: boolean, onEnd?: boolean | function) restart the timer ---@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