aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-02-08 14:51:41 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-02-10 16:05:59 +0100
commit090287071c47438667dc4ad19b3f3ccf63beccb0 (patch)
treeb61ecf77cb31b9947a5535f01d60e28d7522df39 /lua
parentdocs: added things to do short term (diff)
refactor: removed fps option
Diffstat (limited to 'lua')
-rw-r--r--lua/pets.lua24
-rw-r--r--lua/pets/animations.lua30
-rw-r--r--lua/pets/utils.lua20
3 files changed, 28 insertions, 46 deletions
diff --git a/lua/pets.lua b/lua/pets.lua
index 914e68a..b43997e 100644
--- a/lua/pets.lua
+++ b/lua/pets.lua
@@ -9,7 +9,6 @@ M.stack = {
M.options = {
pet_name = "cat",
pet_style = "brown",
- fps = 8,
offset_rows = 0,
offset_cols = 0,
}
@@ -39,28 +38,7 @@ function M.show()
readonly = true,
}
- local image = utils.ShowPet(
- popup.bufnr,
- M.options.offset_rows,
- M.options.offset_cols,
- M.options.pet_name,
- M.options.pet_style,
- M.options.fps
- )
- table.insert(M.stack.popups, popup) -- TODO: update for multiple images
- table.insert(M.stack.images, image)
-end
-
--- close all the popups and stop displaying any image
-function M.closeAll() -- TODO: update for multiple images
- for _, image in pairs(M.stack.images) do
- image:delete(0, {
- free = false,
- })
- end
- for _, popup in pairs(M.stack.popups) do
- popup:unmount()
- end
+ utils.ShowPet(popup.bufnr, M.options.offset_rows, M.options.offset_cols, M.options.pet_name, M.options.pet_style)
end
return M
diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua
index 20e0520..5dc39fa 100644
--- a/lua/pets/animations.lua
+++ b/lua/pets/animations.lua
@@ -2,7 +2,7 @@ local M = {}
M.timer = nil
M.bufnr = nil
M.frame_counter = 1
-M.frames = {}
+M.frames = {} -- TODO: init frames to be images, not paths
M.current_image = nil
local lines = {}
@@ -14,12 +14,16 @@ for _ = 0, 15 do
table.insert(lines, string)
end
-function M.animate(buf, sourcedir, fps)
- local files = M._listdir(sourcedir .. "8fps/" .. "walk/")
+function M.animate(buf, sourcedir)
+ local files = require("pets.utils").listdir(sourcedir .. "walk/")
for _, file in pairs(files) do
- table.insert(M.frames, sourcedir .. "8fps/" .. "walk/" .. file)
+ table.insert(M.frames, sourcedir .. "walk/" .. file)
+ end
+ if M.timer == nil then
+ M.timer = vim.loop.new_timer()
+ else
+ print("timer already exists")
end
- M.timer = vim.loop.new_timer()
M.bufnr = buf
M.timer:start(100, 1000 / 8, vim.schedule_wrap(M.next_frame))
@@ -42,20 +46,4 @@ function M.next_frame()
return true
end
-function M._listdir(directory)
- local i, t, popen = 0, {}, io.popen
- local pfile = popen('/bin/ls -a "' .. directory .. '"')
- if pfile == nil then
- error("Error getting assets for specified pet")
- end
- for filename in pfile:lines() do
- if filename ~= "." and filename ~= ".." then
- i = i + 1
- t[i] = filename
- end
- end
- pfile:close()
- return t
-end
-
return M
diff --git a/lua/pets/utils.lua b/lua/pets/utils.lua
index a83b750..3e78d61 100644
--- a/lua/pets/utils.lua
+++ b/lua/pets/utils.lua
@@ -1,14 +1,30 @@
local M = {}
-function M.ShowPet(buf, offset_rows, offset_cols, pet_name, pet_style, fps)
+function M.ShowPet(buf, offset_rows, offset_cols, pet_name, pet_style)
local wd = "/mnt/shared/coding/lua/plugins/pets.nvim/media/" -- TODO: adapt to use the correct path when plugin is installed
local sourcedir = wd .. pet_name .. "/" .. pet_style .. "/"
- require("pets.animations").animate(buf, sourcedir, fps)
+ require("pets.animations").animate(buf, sourcedir)
-- local image = require("hologram.image"):new(sourcedir .. "8fps/walk/0.png", {})
-- image:display(1 + offset_rows, 0 + offset_cols, buf, {}) -- TODO: offset option to show the pet at the desired height
return -1
end
+function M.listdir(directory)
+ local i, t, popen = 0, {}, io.popen
+ local pfile = popen('/bin/ls -a "' .. directory .. '"')
+ if pfile == nil then
+ error("Error getting assets for specified pet")
+ end
+ for filename in pfile:lines() do
+ if filename ~= "." and filename ~= ".." then
+ i = i + 1
+ t[i] = filename
+ end
+ end
+ pfile:close()
+ return t
+end
+
return M