feature/simple_ui #18

Merged
PeaAshMeter merged 25 commits from feature/simple_ui into main 2025-11-08 01:32:47 +03:00
Showing only changes of commit eb45ffade4 - Show all commits

View File

@ -1,3 +1,5 @@
local easing = require "lib.utils.easing"
--- @alias voidCallback fun(): nil --- @alias voidCallback fun(): nil
--- @alias animationRunner fun(node: AnimationNode) --- @alias animationRunner fun(node: AnimationNode)
@ -28,6 +30,9 @@
--- @field children AnimationNode[] --- @field children AnimationNode[]
--- @field finish voidCallback --- @field finish voidCallback
--- @field onEnd voidCallback? --- @field onEnd voidCallback?
--- @field duration number продолжительность в миллисекундах
--- @field easing ease функция смягчения
--- @field t number прогресс анимации
local animation = {} local animation = {}
animation.__index = animation animation.__index = animation
@ -50,7 +55,21 @@ function animation:chain(children)
return self return self
end end
--- @param data {[1]: animationRunner?, onEnd?: voidCallback, children?: AnimationNode[]} --- Возвращает текущий прогресс анимации с учетом смягчения
function animation:getValue()
return self.easing(self.t)
end
function animation:update(dt)
if self.t < 1 then
self.t = self.t + dt * 1000 / self.duration -- в знаменателе продолжительность анимации в секундах
else
self.t = 1
self:finish()
end
end
--- @param data {[1]: animationRunner?, onEnd?: voidCallback, duration: number?, easing: ease?, children?: AnimationNode[]}
--- @return AnimationNode --- @return AnimationNode
local function new(data) local function new(data)
local t = setmetatable({}, animation) local t = setmetatable({}, animation)
@ -61,6 +80,9 @@ local function new(data)
t.count = 1 -- своя анимация t.count = 1 -- своя анимация
t.children = {} t.children = {}
t:chain(data.children or {}) t:chain(data.children or {})
t.duration = data.duration or 1000
t.easing = data.easing or easing.linear
t.t = 0
t.finish = function() t.finish = function()
t:bubbleUp() t:bubbleUp()
for _, anim in ipairs(t.children) do for _, anim in ipairs(t.children) do