diff options
| author | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-10 12:22:37 +0100 |
|---|---|---|
| committer | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-10 16:05:59 +0100 |
| commit | 8ebd08eb7929ae2433b14629aa9d6b4fcd5c6594 (patch) | |
| tree | 0df5537ba8397b82152f7469657b1d66c87255c1 /lua | |
| parent | feat(pets): ability to remove pets (diff) | |
refactor(popups): popups are now an attribute of the pet class
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets.lua | 14 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 9 |
2 files changed, 11 insertions, 12 deletions
diff --git a/lua/pets.lua b/lua/pets.lua index 41e830b..ed827db 100644 --- a/lua/pets.lua +++ b/lua/pets.lua @@ -7,7 +7,7 @@ M.options = { offset_cols = 0, } -M.stack = { pets = {}, popups = {} } +M.pets = {} function M.setup(options) options = options or {} @@ -25,22 +25,16 @@ end -- create a Pet object and add it to the pets table function M.create_pet(name, type, style) local pet = require("pets.pet").Pet.new(name, type, style) - local popup = require("pets.popup").popup - popup:mount() - pet:animate(popup.bufnr) - table.insert(M.stack.pets, pet) - table.insert(M.stack.popups, popup) + pet:animate() + table.insert(M.pets, pet) end -- function M.kill_pet(name) end function M.kill_all() - for _, pet in pairs(M.stack.pets) do + for _, pet in pairs(M.pets) do pet:kill() end - for _, popup in pairs(M.stack.popups) do - popup:unmount() - end end return M diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua index 0b191c9..f0e6cfa 100644 --- a/lua/pets/pet.lua +++ b/lua/pets/pet.lua @@ -11,17 +11,22 @@ function M.Pet.new(name, type, style) instance.name = name instance.type = type instance.style = 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 return instance end -function M.Pet:animate(bufnr) - self.animation:start(bufnr) +function M.Pet:animate() + self.popup:mount() + self.animation:start(self.popup.bufnr) end function M.Pet:kill() + self.popup:unmount() self.animation:stop() end |