From 3959f76aae76fabfe610274beac22e49b444b6a5 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sat, 20 Apr 2024 06:55:56 +1000 Subject: [PATCH] refactor(timer): adjust module return and types --- imports/timer/shared.lua | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/imports/timer/shared.lua b/imports/timer/shared.lua index 74dcdf9..3f55953 100644 --- a/imports/timer/shared.lua +++ b/imports/timer/shared.lua @@ -8,8 +8,7 @@ ---@field paused boolean the pause state of the timer ---@class OxTimer : OxClass ----@field private TimerPrivateProps ----@field constructor fun(self: self, time: number, onEnd: fun(), async: boolean) +---@field private private TimerPrivateProps ---@field start fun(self: self, async?: boolean) starts 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 @@ -18,6 +17,10 @@ ---@field getTimeLeft fun(self: self, format?: 'ms' | 's' | 'm' | 'h'): number | table returns the time left on the timer with the specified format rounded to 2 decimal places (miliseconds, seconds, minutes, hours). returns a table of all if not specified. local timer = lib.class('OxTimer') +---@private +---@param time number +---@param onEnd fun(self: OxTimer) +---@param async? boolean function timer:constructor(time, onEnd, async) assert(type(time) == "number" and time > 0, "Time must be a positive number") assert(onEnd == nil or type(onEnd) == "function", "onEnd must be a function or nil") @@ -140,16 +143,11 @@ function timer:getTimeLeft(format) } end -lib.timer = { - async = function(time, onEnd) - return timer:new(time, onEnd, true) - end -} +---@param time number +---@param onEnd fun(self: OxTimer) +---@param async? boolean +function lib.timer(time, onEnd, async) + return timer:new(time, onEnd, async) +end -setmetatable(lib.timer, { - __call = function(t, time, onEnd) - return timer:new(time, onEnd) - end -}) - -return lib.timer \ No newline at end of file +return lib.timer