mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-28 09:39:31 +00:00
Timed functions callbacks now receive the timed function object as first argument
This commit is contained in:
parent
ddcb03f89e
commit
c7e72a0295
1 changed files with 8 additions and 6 deletions
14
time.lua
14
time.lua
|
|
@ -82,14 +82,14 @@ local function newTimerRegistry()
|
||||||
t.coroutine = co
|
t.coroutine = co
|
||||||
t.started = registry.get()
|
t.started = registry.get()
|
||||||
if t.times > 0 then t.times = t.times - 1 end
|
if t.times > 0 then t.times = t.times - 1 end
|
||||||
for _, f in ipairs(t.onStart) do f() end
|
for _, f in ipairs(t.onStart) do f(t.object) end
|
||||||
end
|
end
|
||||||
assert(coroutine.resume(co, function(delay)
|
assert(coroutine.resume(co, function(delay)
|
||||||
t.after = delay
|
t.after = delay
|
||||||
d[func] = t
|
d[func] = t
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end, dt))
|
end, dt))
|
||||||
for _, f in ipairs(t.onUpdate) do f() end
|
for _, f in ipairs(t.onUpdate) do f(t.object) end
|
||||||
if all(t.stopWhen, false) then t.forceStop = true end
|
if all(t.stopWhen, false) then t.forceStop = true end
|
||||||
if t.forceStop or coroutine.status(co) == "dead" then
|
if t.forceStop or coroutine.status(co) == "dead" then
|
||||||
if t.forceStop
|
if t.forceStop
|
||||||
|
|
@ -98,7 +98,7 @@ local function newTimerRegistry()
|
||||||
or (not all(t.repeatWhile, true))
|
or (not all(t.repeatWhile, true))
|
||||||
or (t.every == -1 and t.times == -1 and t.during == -1 and #t.repeatWhile == 0) -- no repeat
|
or (t.every == -1 and t.times == -1 and t.during == -1 and #t.repeatWhile == 0) -- no repeat
|
||||||
then
|
then
|
||||||
for _, f in ipairs(t.onEnd) do f() end
|
for _, f in ipairs(t.onEnd) do f(t.object) end
|
||||||
else
|
else
|
||||||
if t.times > 0 then t.times = t.times - 1 end
|
if t.times > 0 then t.times = t.times - 1 end
|
||||||
t.after = t.every
|
t.after = t.every
|
||||||
|
|
@ -129,6 +129,7 @@ local function newTimerRegistry()
|
||||||
-- Since delayed functions can end in any order, it doesn't really make sense to use a integer-keyed list.
|
-- Since delayed functions can end in any order, it doesn't really make sense to use a integer-keyed list.
|
||||||
-- Using the function as the key works and it's unique.
|
-- Using the function as the key works and it's unique.
|
||||||
delayed[func] = {
|
delayed[func] = {
|
||||||
|
object = nil,
|
||||||
coroutine = nil,
|
coroutine = nil,
|
||||||
started = 0,
|
started = 0,
|
||||||
|
|
||||||
|
|
@ -216,17 +217,17 @@ local function newTimerRegistry()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Callbacks functions ---
|
--- Callbacks functions ---
|
||||||
--- Will execute func() when the function execution start.
|
--- Will execute func(self) when the function execution start.
|
||||||
onStart = function(_, func)
|
onStart = function(_, func)
|
||||||
table.insert(t.onStart, func)
|
table.insert(t.onStart, func)
|
||||||
return r
|
return r
|
||||||
end,
|
end,
|
||||||
--- Will execute func() each frame the main function is run..
|
--- Will execute func(self) each frame the main function is run..
|
||||||
onUpdate = function(_, func)
|
onUpdate = function(_, func)
|
||||||
table.insert(t.onUpdate, func)
|
table.insert(t.onUpdate, func)
|
||||||
return r
|
return r
|
||||||
end,
|
end,
|
||||||
--- Will execute func() when the function execution end.
|
--- Will execute func(self) when the function execution end.
|
||||||
onEnd = function(_, func)
|
onEnd = function(_, func)
|
||||||
table.insert(t.onEnd, func)
|
table.insert(t.onEnd, func)
|
||||||
return r
|
return r
|
||||||
|
|
@ -242,6 +243,7 @@ local function newTimerRegistry()
|
||||||
:initWhen(function() return done end)
|
:initWhen(function() return done end)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
t.object = r
|
||||||
return r
|
return r
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue