aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-03-04 17:42:52 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-03-04 17:49:03 +0100
commit94e2b2fa25e9f4ee0acca16853f58f0967796f22 (patch)
treee58661486d5b4577c6edde445b285dc2e6516f67
parentrefactor: pet-specific values (diff)
refactor: PetsSleepToggle to PetsIdleToggle
The word "sleep" is changed to "idle" in the whole project for readability.
-rw-r--r--README.md2
-rw-r--r--lua/pets.lua10
-rw-r--r--lua/pets/animations.lua17
-rw-r--r--lua/pets/commands.lua5
-rw-r--r--lua/pets/pet.lua4
-rw-r--r--lua/pets/pets/dog.lua2
6 files changed, 21 insertions, 19 deletions
diff --git a/README.md b/README.md
index c79e44b..1df5990 100644
--- a/README.md
+++ b/README.md
@@ -88,7 +88,7 @@ These are all the available commands:
- `PetsKillAll`: kills all the pets, poor creatures. Works just as PetsKill but for every pet.
- `PetsPauseToggle`: pause/resume animations for all pets, leaving them on screen as cute little statues
- `PetsHideToggle`: pause the animation for all pets and hide them / show all the pets again and resume animations
-- `PetsSleepToggle`: basically a do-not-disturb mode, pets are still animated but do not move around
+- `PetsIdleToggle`/`PetsSleepToggle`: basically a do-not-disturb mode, pets are still animated but do not move around
## ⚠️ Limitations
diff --git a/lua/pets.lua b/lua/pets.lua
index 6703a3d..6f04798 100644
--- a/lua/pets.lua
+++ b/lua/pets.lua
@@ -3,7 +3,7 @@ local utils = require("pets.utils")
M.paused = false
M.paused = false
-M.sleeping = false
+M.idle = false
M.options = {
row = 1, -- the row (height) to display the pet at
@@ -64,7 +64,7 @@ function M.create_pet(name, type, style)
local state = {
paused = M.paused,
hidden = M.paused,
- sleeping = M.sleeping,
+ idle = M.idle,
}
local pet = require("pets.pet").Pet.new(name, type, style, M.options, state)
pet:animate()
@@ -117,10 +117,10 @@ function M.toggle_hide()
end
end
-function M.toggle_sleep()
- M.sleeping = not M.sleeping
+function M.toggle_idle()
+ M.idle = not M.idle
for _, pet in pairs(M.pets) do
- pet:set_sleep(M.sleeping)
+ pet:set_idle(M.idle)
end
end
diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua
index 62c86ac..f3e24b5 100644
--- a/lua/pets/animations.lua
+++ b/lua/pets/animations.lua
@@ -11,13 +11,12 @@ local listdir = require("pets.utils").listdir
-- @param type,style type and style of the pet
-- @param popup the popup where the pet is displayed
-- @param user_opts table with user options
--- @param state table with the current plugin state (sleeping, paused, hidden)
+-- @param state table with the current plugin state (idle, paused, hidden)
-- @return a new animation instance
function M.Animation.new(sourcedir, type, style, popup, user_opts, state)
local instance = setmetatable({}, M.Animation)
instance.type = type
instance.style = style
- instance.sourcedir = sourcedir
instance.frame_counter = 1
instance.actions = listdir(sourcedir)
instance.frames = {}
@@ -50,7 +49,7 @@ function M.Animation.new(sourcedir, type, style, popup, user_opts, state)
-- setup next_actions
local specs = require("pets.pets." .. type)
instance.next_actions = specs.next_actions
- instance.sleeping_animations = specs.sleeping_animations
+ instance.idle_actions = specs.idle_actions
return instance
end
@@ -84,8 +83,8 @@ function M.Animation:start()
end
self.repetitions = 0
- if self.state.sleeping then
- self.current_action = self.sleeping_animations[math.random(#self.sleeping_animations)]
+ if self.state.idle then
+ self.current_action = self.idle_actions[math.random(#self.idle_actions)]
else
-- get available first action
local first_action
@@ -166,10 +165,10 @@ function M.Animation:set_next_action()
self.current_action = "die"
return
end
- if self.state.sleeping then
- -- If the animation isn't currently a sleeping animtion, put the pet in it, otherwise loop the animation
- if not vim.tbl_contains(self.sleeping_animations, self.current_action) then
- self.current_action = self.sleeping_animations[math.random(#self.sleeping_animations)]
+ if self.state.idle then
+ -- If the animation isn't currently a idle animtion, put the pet in it, otherwise loop the animation
+ if not vim.tbl_contains(self.idle_actions, self.current_action) then
+ self.current_action = self.idle_actions[math.random(#self.idle_actions)]
end
else
if math.random() < 0.5 then
diff --git a/lua/pets/commands.lua b/lua/pets/commands.lua
index 336a816..da4490d 100644
--- a/lua/pets/commands.lua
+++ b/lua/pets/commands.lua
@@ -53,6 +53,9 @@ vim.api.nvim_create_user_command("PetsHideToggle", function()
pets.toggle_hide()
end, {})
+vim.api.nvim_create_user_command("PetsIdleToggle", function()
+ pets.toggle_idle()
+end, {})
vim.api.nvim_create_user_command("PetsSleepToggle", function()
- pets.toggle_sleep()
+ pets.toggle_idle()
end, {})
diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua
index 99f0053..2cc6cfc 100644
--- a/lua/pets/pet.lua
+++ b/lua/pets/pet.lua
@@ -68,8 +68,8 @@ function M.Pet:set_hidden(hidden)
})
end
-function M.Pet:set_sleep(sleeping)
- self.animation:set_state({ sleeping = sleeping })
+function M.Pet:set_idle(idle)
+ self.animation:set_state({ idle = idle })
end
return M
diff --git a/lua/pets/pets/dog.lua b/lua/pets/pets/dog.lua
index d05a4d2..d9ef11f 100644
--- a/lua/pets/pets/dog.lua
+++ b/lua/pets/pets/dog.lua
@@ -7,5 +7,5 @@ return {
sit = { "walk", "liedown", "pee" },
walk = { "run", "idle" },
},
- sleeping_animations = { "idle", "sit", "liedown" },
+ idle_actions = { "idle", "sit", "liedown" },
}