diff options
| author | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-13 19:56:29 +0100 |
|---|---|---|
| committer | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-14 19:17:20 +0100 |
| commit | 495a01fdae20b0ec86d4257fc1029318dbccb5ca (patch) | |
| tree | 1dfaa381fe07f1a80cd04145d1fafc4b42409207 | |
| parent | docs(readme): added description and pets (diff) | |
refactor(popup): the popup is now passed as a whole to the animation
| -rw-r--r-- | lua/pets/animations.lua | 14 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 9 |
2 files changed, 9 insertions, 14 deletions
diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua index edc896d..960230f 100644 --- a/lua/pets/animations.lua +++ b/lua/pets/animations.lua @@ -16,10 +16,10 @@ local listdir = require("pets.utils").listdir -- @param sourcedir the full path for the media directory -- @param type,style type and style of the pet --- @param popup_width width of the popup in columns +-- @param popup the popup where the pet is displayed -- @param user_opts table with user options -- @return a new animation instance -function M.Animation.new(sourcedir, type, style, popup_width, user_opts) +function M.Animation.new(sourcedir, type, style, popup, user_opts) local instance = setmetatable({}, M.Animation) instance.type = type instance.style = style @@ -27,13 +27,13 @@ function M.Animation.new(sourcedir, type, style, popup_width, user_opts) instance.frame_counter = 1 instance.actions = listdir(sourcedir) instance.frames = {} - instance.popup_width = popup_width + instance.popup = popup -- 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 + if user_opts.col > popup.win_config.width - 8 then + M.base_col = popup.win_config.width - 8 else M.base_col = user_opts.col end @@ -110,13 +110,13 @@ end -- @function set horizontal movement per frame based on current action function M.Animation:set_next_col() if self.current_action == "walk" then - if self.col < self.popup_width - 8 then + if self.col < self.popup.win_config.width - 8 then self.col = self.col + 1 else self.col = M.base_col end elseif self.current_action == "sneak" or self.current_action == "crouch" then - if self.col < self.popup_width - 8 then + if self.col < self.popup.win_config.width - 8 then if self.frame_counter % 2 == 0 then self.col = self.col + 1 end diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua index 6a31ff2..175e51d 100644 --- a/lua/pets/pet.lua +++ b/lua/pets/pet.lua @@ -34,13 +34,8 @@ function M.Pet.new(name, type, style, user_opts) instance.sourcedir = wd .. type .. "/" .. style .. "/" instance.popup = require("nui.popup")(popup_opts) - instance.animation = require("pets.animations").Animation.new( - instance.sourcedir, - type, - style, - instance.popup.win_config.width, - user_opts - ) + instance.animation = + require("pets.animations").Animation.new(instance.sourcedir, type, style, instance.popup, user_opts) return instance end |