diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets.lua | 7 | ||||
| -rw-r--r-- | lua/pets/animations.lua | 24 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 9 |
3 files changed, 25 insertions, 15 deletions
diff --git a/lua/pets.lua b/lua/pets.lua index 7c7097f..c0ebf24 100644 --- a/lua/pets.lua +++ b/lua/pets.lua @@ -1,8 +1,9 @@ local M = {} M.options = { - row = 1, - col = 0, + row = 5, -- 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, } M.pets = {} @@ -26,7 +27,7 @@ function M.create_pet(name, type, style) vim.api.nvim_err_writeln("Name already in use") return end - local pet = require("pets.pet").Pet.new(name, type, style, M.options.row, M.options.col) + local pet = require("pets.pet").Pet.new(name, type, style, M.options) pet:animate() M.pets[pet.name] = pet end diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua index e49883e..3ae253a 100644 --- a/lua/pets/animations.lua +++ b/lua/pets/animations.lua @@ -14,7 +14,7 @@ end local listdir = require("pets.utils").listdir -function M.Animation.new(sourcedir, type, style, row, col, popup_width) +function M.Animation.new(sourcedir, type, style, popup_width, user_opts) local instance = setmetatable({}, M.Animation) instance.type = type instance.style = style @@ -23,7 +23,17 @@ function M.Animation.new(sourcedir, type, style, row, col, popup_width) instance.actions = listdir(sourcedir) instance.frames = {} instance.popup_width = popup_width - instance.row, instance.col = row, col + + -- user options + instance.row, instance.col = user_opts.row, user_opts.col + instance.speed_multiplier = user_opts.speed_multiplier + if user_opts.col > popup_width - 8 then + M.base_col = popup_width - 8 + else + M.base_col = user_opts.col + end + + -- setup frames for _, action in pairs(instance.actions) do local current_actions = {} for _, file in pairs(listdir(sourcedir .. action)) do @@ -43,7 +53,7 @@ function M.Animation:start(bufnr) self.bufnr = bufnr self.current_action = "idle" - self.timer:start(0, 1000 / 8, function() -- run timer at 8fps + self.timer:start(0, 1000 / (self.speed_multiplier * 8), function() -- run timer at 8fps vim.schedule(function() M.Animation.next_frame(self) end) @@ -87,18 +97,18 @@ end function M.Animation:set_next_col() if self.current_action == "walk" then - if self.col < self.popup_width - 5 then + if self.col < self.popup_width - 8 then self.col = self.col + 1 else - self.col = 0 + self.col = M.base_col end - elseif self.current_action == "sneak" then + elseif self.current_action == "sneak" or self.current_action == "crouch" then if self.col < self.popup_width - 8 then if self.frame_counter % 2 == 0 then self.col = self.col + 1 end else - self.col = 0 + self.col = M.base_col end end end diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua index 424f138..1b1249e 100644 --- a/lua/pets/pet.lua +++ b/lua/pets/pet.lua @@ -9,7 +9,7 @@ local popup_opts = { col = "100%", }, size = { - width = "25%", + width = "30%", height = 10, }, focusable = false, @@ -22,7 +22,7 @@ local popup_opts = { -- @param type the species of the pet e.g. cat -- @param style the color/style of the pet e.g. brown -- @return a new Pet instance -function M.Pet.new(name, type, style, row, col) +function M.Pet.new(name, type, style, user_opts) local instance = setmetatable({}, M.Pet) instance.name = name instance.type = type @@ -36,9 +36,8 @@ function M.Pet.new(name, type, style, row, col) instance.sourcedir, type, style, - row, - col, - instance.popup.win_config.width + instance.popup.win_config.width, + user_opts ) return instance end |