forked from frc5183/astrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait.lua
More file actions
32 lines (30 loc) · 858 Bytes
/
wait.lua
File metadata and controls
32 lines (30 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Imports
---@module 'lib.safety'
local safety = require "lib.safety"
local active = {}
local wait = {}
---@overload fun(seconds:number, func:function, ...:any)
setmetatable(wait, {
---@param self table
---@param seconds number
---@param func function
---@param ... any
__call = function(self, seconds, func, ...)
safety.ensureNumber(seconds, "seconds")
if type(func) ~= "nil" then safety.ensureFunction(func, "func") end
table.insert(active, {love.timer.getTime() + seconds, func, {...}})
end
})
-- Called every single frame-update in love.update
function wait.update()
---@param k any
---@param v table
for k, v in pairs(active) do
if love.timer.getTime() >= v[1] then
if v[2] then v[2](unpack(v[3] or {})) end
table.remove(active, k)
end
end
end
-- Return
return wait