diff options
| author | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-10 17:45:38 +0100 |
|---|---|---|
| committer | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-10 17:45:38 +0100 |
| commit | f3e45780dad4a28233a37e4773fea0372f993735 (patch) | |
| tree | 4ce5b3a6f525c5f257fbb3a4a8ffa12eb681889b /lua | |
| parent | refactor(popup): create popup directly inside the Pet class (diff) | |
feat(animations): use row and col options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets.lua | 8 | ||||
| -rw-r--r-- | lua/pets/animations.lua | 5 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 6 |
3 files changed, 9 insertions, 10 deletions
diff --git a/lua/pets.lua b/lua/pets.lua index b76df2e..1688db2 100644 --- a/lua/pets.lua +++ b/lua/pets.lua @@ -1,10 +1,8 @@ local M = {} M.options = { - pet_type = "cat", - pet_style = "brown", - offset_rows = 0, - offset_cols = 0, + row = 1, + col = 0, } M.pets = {} @@ -24,7 +22,7 @@ end -- create a Pet object and add it to the pets table function M.create_pet(name, type, style) -- TODO: don't allow duplicate names - local pet = require("pets.pet").Pet.new(name, type, style) + local pet = require("pets.pet").Pet.new(name, type, style, M.options.row, M.options.col) pet:animate() table.insert(M.pets, pet) end diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua index 970274b..e2f6225 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) +function M.Animation.new(sourcedir, type, style, row, col) local instance = setmetatable({}, M.Animation) instance.type = type instance.style = style @@ -22,6 +22,7 @@ function M.Animation.new(sourcedir, type, style) instance.frame_counter = 1 instance.actions = listdir(sourcedir) instance.frames = {} + instance.row, instance.col = row, col for _, action in pairs(instance.actions) do local current_actions = {} for _, file in pairs(listdir(sourcedir .. action)) do @@ -62,7 +63,7 @@ function M.Animation:next_frame() self.frame_counter = 1 end local image = self.frames[self.current_action][self.frame_counter] - image:display(1, self.frame_counter, self.bufnr, {}) + image:display(self.row, self.col, self.bufnr, {}) self.current_image = image end diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua index 4f31792..e5dca4d 100644 --- a/lua/pets/pet.lua +++ b/lua/pets/pet.lua @@ -1,4 +1,5 @@ local M = {} + M.Pet = {} M.Pet.__index = M.Pet @@ -21,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) +function M.Pet.new(name, type, style, row, col) local instance = setmetatable({}, M.Pet) instance.name = name instance.type = type @@ -30,8 +31,7 @@ function M.Pet.new(name, type, style) local wd = debug.getinfo(1).source:sub(2):match("(.*nvim/)") .. "media/" instance.sourcedir = wd .. type .. "/" .. style .. "/" - instance.animation = require("pets.animations").Animation.new(instance.sourcedir, type, style) - instance.popup = require("pets.popup").popup + instance.animation = require("pets.animations").Animation.new(instance.sourcedir, type, style, row, col) instance.popup = require("nui.popup")(popup_opts) return instance end |