aboutsummaryrefslogtreecommitdiff
path: root/lua/pets
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/pets
parentdocs: added things to do short term (diff)
refactor: removed fps option
Diffstat (limited to 'lua/pets')
-rw-r--r--lua/pets/animations.lua30
-rw-r--r--lua/pets/utils.lua20
2 files changed, 27 insertions, 23 deletions
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