feature/task-tweens #30

Merged
PeaAshMeter merged 9 commits from feature/task-tweens into main 2026-02-12 00:07:35 +03:00
Showing only changes of commit 7695fe7698 - Show all commits

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]