diff options
Diffstat (limited to 'lua/pets')
| -rw-r--r-- | lua/pets/animations.lua | 17 | ||||
| -rw-r--r-- | lua/pets/commands.lua | 5 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 4 | ||||
| -rw-r--r-- | lua/pets/pets/dog.lua | 2 |
4 files changed, 15 insertions, 13 deletions
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" }, } |