Fix formatting and add type annotations to task completer function

This commit is contained in:
PeaAshMeter 2026-02-08 06:18:26 +03:00
parent 52db521107
commit 7695fe7698

View File

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