aboutsummaryrefslogtreecommitdiff
path: root/lua/pets
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-02-10 17:45:38 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-02-10 17:45:38 +0100
commitf3e45780dad4a28233a37e4773fea0372f993735 (patch)
tree4ce5b3a6f525c5f257fbb3a4a8ffa12eb681889b /lua/pets
parentrefactor(popup): create popup directly inside the Pet class (diff)
feat(animations): use row and col options
Diffstat (limited to 'lua/pets')
-rw-r--r--lua/pets/animations.lua5
-rw-r--r--lua/pets/pet.lua6
2 files changed, 6 insertions, 5 deletions
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