aboutsummaryrefslogtreecommitdiff
path: root/lua/pets
diff options
context:
space:
mode:
Diffstat (limited to 'lua/pets')
-rw-r--r--lua/pets/animations.lua61
-rw-r--r--lua/pets/commands.lua4
-rw-r--r--lua/pets/popup.lua28
-rw-r--r--lua/pets/utils.lua13
4 files changed, 85 insertions, 21 deletions
diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua
new file mode 100644
index 0000000..20e0520
--- /dev/null
+++ b/lua/pets/animations.lua
@@ -0,0 +1,61 @@
+local M = {}
+M.timer = nil
+M.bufnr = nil
+M.frame_counter = 1
+M.frames = {}
+M.current_image = nil
+
+local lines = {}
+local string = ""
+for _ = 0, 150 do
+ string = string .. " "
+end
+for _ = 0, 15 do
+ table.insert(lines, string)
+end
+
+function M.animate(buf, sourcedir, fps)
+ local files = M._listdir(sourcedir .. "8fps/" .. "walk/")
+ for _, file in pairs(files) do
+ table.insert(M.frames, sourcedir .. "8fps/" .. "walk/" .. file)
+ end
+ M.timer = vim.loop.new_timer()
+ M.bufnr = buf
+
+ M.timer:start(100, 1000 / 8, vim.schedule_wrap(M.next_frame))
+end
+
+function M.next_frame()
+ M.frame_counter = M.frame_counter + 1
+ vim.api.nvim_buf_set_lines(M.bufnr, 0, -1, false, lines)
+ if not M.current_image then
+ M.frame_counter = 1
+ else
+ M.current_image:delete(0, { free = false })
+ end
+ if M.frame_counter > #M.frames then
+ M.frame_counter = 1
+ end
+ local image = require("hologram.image"):new(M.frames[M.frame_counter])
+ image:display(1, M.frame_counter, M.bufnr, {})
+ M.current_image = image
+ 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/commands.lua b/lua/pets/commands.lua
index 8124cbc..a211d2d 100644
--- a/lua/pets/commands.lua
+++ b/lua/pets/commands.lua
@@ -1,9 +1,9 @@
local pets = require("pets")
vim.api.nvim_create_user_command("Pets", function()
- pets.show()
+ pets.show()
end, {}) -- use nargs = 1 to accept arguments
vim.api.nvim_create_user_command("PetsCloseAll", function()
- pets.closeAll()
+ pets.closeAll()
end, {})
diff --git a/lua/pets/popup.lua b/lua/pets/popup.lua
index 8fe7ebf..9a1b3a4 100644
--- a/lua/pets/popup.lua
+++ b/lua/pets/popup.lua
@@ -1,19 +1,19 @@
local M = {}
local Popup = require("nui.popup")
+
M.popup = Popup({
- position = {
- row = "100%", -- FIX: set row for different sizes / implement offset
- col = "100%",
- },
- relative = "editor",
- size = {
- width = "25%",
- height = 10,
- },
- focusable = false,
- enter = false,
- win_options = {
- winblend = 10,
- },
+ position = {
+ row = "100%",
+ col = "100%",
+ },
+ size = {
+ width = "25%",
+ height = 10,
+ },
+ focusable = false,
+ enter = false,
+ win_options = {
+ winblend = 100,
+ },
})
return M
diff --git a/lua/pets/utils.lua b/lua/pets/utils.lua
index 4325928..a83b750 100644
--- a/lua/pets/utils.lua
+++ b/lua/pets/utils.lua
@@ -1,11 +1,14 @@
local M = {}
-function M.ShowPet(buf)
- local source = "/mnt/shared/coding/lua/plugins/pets.nvim/media/test/brown_idle-0.png"
- local image = require("hologram.image"):new(source, {})
+function M.ShowPet(buf, offset_rows, offset_cols, pet_name, pet_style, fps)
+ 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 .. "/"
- image:display(5, 0, buf, {}) -- TODO: offset option to show the pet at the desired height
- return image
+ require("pets.animations").animate(buf, sourcedir, fps)
+
+ -- 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
return M