Fix formatting and add type annotations to task completer function
This commit is contained in:
parent
52db521107
commit
7695fe7698
@ -33,11 +33,11 @@ function task.update(dt)
|
|||||||
t.elapsed = t.elapsed + dt * 1000
|
t.elapsed = t.elapsed + dt * 1000
|
||||||
local progress = math.min(t.elapsed / t.duration, 1)
|
local progress = math.min(t.elapsed / t.duration, 1)
|
||||||
local value = t.easing(progress)
|
local value = t.easing(progress)
|
||||||
|
|
||||||
for key, targetValue in pairs(t.properties) do
|
for key, targetValue in pairs(t.properties) do
|
||||||
t.target[key] = lerp(t.initial[key], targetValue, value)
|
t.target[key] = lerp(t.initial[key], targetValue, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
if progress >= 1 then
|
if progress >= 1 then
|
||||||
t.completed = true
|
t.completed = true
|
||||||
table.remove(activeTweens, i)
|
table.remove(activeTweens, i)
|
||||||
@ -50,7 +50,8 @@ function task.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Возвращает Completer — объект, который позволяет вручную завершить таску.
|
--- Возвращает Completer — объект, который позволяет вручную завершить таску.
|
||||||
--- @return table completer { complete: fun(val: T) }, Task<T> future
|
--- @generic T
|
||||||
|
--- @return { complete: fun(val: T) }, Task<T> future
|
||||||
function task.completer()
|
function task.completer()
|
||||||
local c = { completed = false, value = nil, cb = nil }
|
local c = { completed = false, value = nil, cb = nil }
|
||||||
function c:complete(val)
|
function c:complete(val)
|
||||||
@ -61,8 +62,11 @@ function task.completer()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local future = function(callback)
|
local future = function(callback)
|
||||||
if c.completed then callback(c.value)
|
if c.completed then
|
||||||
else c.cb = callback end
|
callback(c.value)
|
||||||
|
else
|
||||||
|
c.cb = callback
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return c, future
|
return c, future
|
||||||
end
|
end
|
||||||
@ -86,7 +90,7 @@ end
|
|||||||
--- @return Task<nil>
|
--- @return Task<nil>
|
||||||
function task.tween(target, properties, duration, easing)
|
function task.tween(target, properties, duration, easing)
|
||||||
task.cancel(target) -- Cancel previous animations on this target
|
task.cancel(target) -- Cancel previous animations on this target
|
||||||
|
|
||||||
local initial = {}
|
local initial = {}
|
||||||
for k, _ in pairs(properties) do
|
for k, _ in pairs(properties) do
|
||||||
initial[k] = target[k]
|
initial[k] = target[k]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user