diff options
| author | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-15 23:02:02 +0100 |
|---|---|---|
| committer | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-15 23:02:02 +0100 |
| commit | 9a3d34f61a3b5d6d348f1b8b79b827a29d342b1c (patch) | |
| tree | 53c6693c2045606c1884c449c4a06b7fa9cf65e4 /lua | |
| parent | docs(help): auto generate docs (diff) | |
refactor(animation): refactored popup bufnr and lines tweaks
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets.lua | 2 | ||||
| -rw-r--r-- | lua/pets/animations.lua | 13 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 4 |
3 files changed, 9 insertions, 10 deletions
diff --git a/lua/pets.lua b/lua/pets.lua index 2191e2f..10bccbc 100644 --- a/lua/pets.lua +++ b/lua/pets.lua @@ -2,7 +2,7 @@ local M = {} local utils = require("pets.utils") M.options = { - row = 5, -- the row (height) to display the pet at + row = 1, -- the row (height) to display the pet at col = 0, -- the column to display the pet at (set to high numeber to have it stay stil at the right) speed_multiplier = 1, default_pet = "cat", diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua index 3965b7a..63a7fe9 100644 --- a/lua/pets/animations.lua +++ b/lua/pets/animations.lua @@ -5,10 +5,10 @@ M.Animation.__index = M.Animation -- lines to insert in the buffer to avoid image stretching local lines = {} local string = "" -for _ = 0, 150 do +for _ = 0, 200 do string = string .. " " end -for _ = 0, 15 do +for _ = 0, 20 do table.insert(lines, string) end @@ -77,7 +77,6 @@ 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 @@ -87,8 +86,8 @@ function M.Animation:next_frame() self.frame_counter = self.frame_counter + 1 -- pouplate the buffer with spaces to avoid image distortion - if vim.api.nvim_buf_is_valid(self.bufnr) then - vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, lines) + if vim.api.nvim_buf_is_valid(self.popup.bufnr) then + vim.api.nvim_buf_set_lines(self.popup.bufnr, 0, -1, false, lines) end if not self.current_image then self.frame_counter = 1 @@ -98,7 +97,7 @@ function M.Animation:next_frame() if self.frame_counter > #self.frames[self.current_action] then -- true every 8 frames M.Animation.set_next_action(self) if self.dead then - self.timer = nil + M.Animation.stop_timer(self) return end self.frame_counter = 1 @@ -106,7 +105,7 @@ function M.Animation:next_frame() -- frames contains the images for every action local image = self.frames[self.current_action][self.frame_counter] M.Animation.set_next_col(self) - image:display(self.row, self.col, self.bufnr, {}) + image:display(self.row, self.col, self.popup.bufnr, {}) self.current_image = image end diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua index f045f70..0cdd77b 100644 --- a/lua/pets/pet.lua +++ b/lua/pets/pet.lua @@ -42,8 +42,8 @@ end -- start the animation of the pet function M.Pet:animate() - if self.animation.row <= 0 then - vim.notify("Row must be 1 or greater. Check your config", vim.log.levels.ERROR) + if self.animation.row <= 0 or self.animation.row > 10 then + vim.notify("Row must be >= 1 and <= 10. Check your config", vim.log.levels.ERROR) return end self.popup:mount() |