aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-02-08 15:37:05 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-02-10 16:05:59 +0100
commitcf2ccf182c0a09ad2221edaf134a9ce890644a0b (patch)
tree8d9d57737078bce7314c17d84302a73398f2bee0 /lua
parentrefactor: removed fps option (diff)
refactor: going with OOP approach
- creating a pet metatable/class - storing all the pets in a table with 'pet' objects
Diffstat (limited to 'lua')
-rw-r--r--lua/pets.lua21
-rw-r--r--lua/pets/commands.lua4
-rw-r--r--lua/pets/pet.lua19
3 files changed, 33 insertions, 11 deletions
diff --git a/lua/pets.lua b/lua/pets.lua
index b43997e..c5ed58e 100644
--- a/lua/pets.lua
+++ b/lua/pets.lua
@@ -1,11 +1,5 @@
local M = {}
-M.stack = {
- popups = {},
- images = {},
- jobs = {},
-}
-
M.options = {
pet_name = "cat",
pet_style = "brown",
@@ -13,6 +7,8 @@ M.options = {
offset_cols = 0,
}
+M.pets = {}
+
function M.setup(options)
options = options or {}
M.options = vim.tbl_deep_extend("force", M.options, options)
@@ -33,12 +29,15 @@ function M.show()
local utils = require("pets.utils")
popup:mount()
- popup.buf_options = { -- then set the buffer to be readonly
- modifiable = false,
- readonly = true,
- }
-
utils.ShowPet(popup.bufnr, M.options.offset_rows, M.options.offset_cols, M.options.pet_name, M.options.pet_style)
end
+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.pets, pet)
+end
+
return M
diff --git a/lua/pets/commands.lua b/lua/pets/commands.lua
index a211d2d..80709fd 100644
--- a/lua/pets/commands.lua
+++ b/lua/pets/commands.lua
@@ -4,6 +4,10 @@ vim.api.nvim_create_user_command("Pets", function()
pets.show()
end, {}) -- use nargs = 1 to accept arguments
+vim.api.nvim_create_user_command("PetsNew", function(input)
+ pets.create_pet("Giulio", "cat", "brown") -- TODO: use input.args as name
+end, { nargs = 1 }) -- use nargs = 1 to accept arguments
+
vim.api.nvim_create_user_command("PetsCloseAll", function()
pets.closeAll()
end, {})
diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua
new file mode 100644
index 0000000..4179b38
--- /dev/null
+++ b/lua/pets/pet.lua
@@ -0,0 +1,19 @@
+local M = {}
+M.Pet = {}
+M.Pet.__index = M.Pet
+
+function M.Pet.new(name, type, style)
+ local instance = setmetatable({}, M.Pet)
+ instance.name = name
+ instance.type = type
+ instance.style = style
+ local wd = "/mnt/shared/coding/lua/plugins/pets.nvim/media/" -- TODO: adapt to use the correct path when plugin is installed
+ instance.sourcedir = wd .. type .. "/" .. style .. "/"
+ return instance
+end
+
+function M.Pet:animate(bufnr)
+ require("pets.animations").animate(bufnr, self.sourcedir)
+end
+
+return M