aboutsummaryrefslogtreecommitdiff
path: root/lua/pets/animations.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/pets/animations.lua')
-rw-r--r--lua/pets/animations.lua34
1 files changed, 25 insertions, 9 deletions
diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua
index fad62e8..3965b7a 100644
--- a/lua/pets/animations.lua
+++ b/lua/pets/animations.lua
@@ -51,16 +51,10 @@ function M.Animation.new(sourcedir, type, style, popup, user_opts)
return instance
end
--- @param bufnr buffer number of the popup
--- @function start the animation
-function M.Animation:start(bufnr)
- if self.timer ~= nil then -- reset timer
- self.timer = nil
+function M.Animation:start_timer()
+ if self.timer == nil then
+ self.timer = vim.loop.new_timer()
end
- self.timer = vim.loop.new_timer()
- self.bufnr = bufnr
- self.current_action = "idle"
-
self.timer:start(0, 1000 / (self.speed_multiplier * 8), function()
vim.schedule(function()
M.Animation.next_frame(self)
@@ -68,6 +62,26 @@ function M.Animation:start(bufnr)
end)
end
+function M.Animation:stop_timer()
+ if self.timer == nil then
+ return
+ end
+ self.timer:stop()
+ self.timer:close()
+ self.timer = nil
+end
+
+-- @param bufnr buffer number of the popup
+-- @function start the animation
+function M.Animation:start()
+ if self.timer ~= nil then -- reset timer
+ self.timer = nil
+ end
+ self.bufnr = self.popup.bufnr
+ self.current_action = self.current_action or "idle"
+ M.Animation.start_timer(self)
+end
+
-- @function called on every tick from the timer, go to the next frame
function M.Animation:next_frame()
self.frame_counter = self.frame_counter + 1
@@ -146,6 +160,8 @@ function M.Animation:stop()
end
if self.timer then
self.timer:stop()
+ self.timer:close()
+ self.timer = nil
end
end