diff options
| author | Kyle Mendes <pink@hey.com> | 2023-02-16 09:51:52 -0500 |
|---|---|---|
| committer | Kyle Mendes <pink@hey.com> | 2023-02-16 09:51:52 -0500 |
| commit | f61dff6f8f008ad7928986938f2c8d9195ee684a (patch) | |
| tree | 9410c14872a32fa81ee0c98624c02bcae204ebcf /lua | |
| parent | docs(help): auto generate docs (diff) | |
Adding the ability to sleep pets, stopping their movement
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets.lua | 6 | ||||
| -rw-r--r-- | lua/pets/animations.lua | 16 | ||||
| -rw-r--r-- | lua/pets/commands.lua | 4 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 4 | ||||
| -rw-r--r-- | lua/pets/utils.lua | 9 |
5 files changed, 36 insertions, 3 deletions
diff --git a/lua/pets.lua b/lua/pets.lua index 30f3ef7..ac53551 100644 --- a/lua/pets.lua +++ b/lua/pets.lua @@ -100,4 +100,10 @@ function M.toggle_hide() end end +function M.toggle_sleep() + for _, pet in pairs(M.pets) do + pet:toggle_sleep() + end +end + return M diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua index 63a7fe9..1a0aa4b 100644 --- a/lua/pets/animations.lua +++ b/lua/pets/animations.lua @@ -1,3 +1,5 @@ +local utils = require("pets.utils") + local M = {} M.Animation = {} M.Animation.__index = M.Animation @@ -28,7 +30,7 @@ function M.Animation.new(sourcedir, type, style, popup, user_opts) instance.actions = listdir(sourcedir) instance.frames = {} instance.popup = popup - instance.diying = false + instance.sleeping = false -- user options instance.row, instance.col = user_opts.row, user_opts.col @@ -129,8 +131,16 @@ function M.Animation:set_next_action() sneak = { "crouch", "walk", "liedown" }, walk = { "idle", "idle_blink" }, } - if math.random() < 0.5 then - self.current_action = next_actions[self.current_action][math.random(#next_actions[self.current_action])] + local sleeping_animations = {'idle', 'sit', 'liedown'} + if self.sleeping then + -- If the animation isn't currently a sleeping animtion, put the pet in it, otherwise loop the animation + if not utils.table_includes(sleeping_animations, self.current_action) then + self.current_action = sleeping_animations[math.random(#sleeping_animations)] + end + else + if math.random() < 0.5 then + self.current_action = next_actions[self.current_action][math.random(#next_actions[self.current_action])] + end end end diff --git a/lua/pets/commands.lua b/lua/pets/commands.lua index b2b9888..447f323 100644 --- a/lua/pets/commands.lua +++ b/lua/pets/commands.lua @@ -52,3 +52,7 @@ end, {}) vim.api.nvim_create_user_command("PetsHideToggle", function() pets.toggle_hide() end, {}) + +vim.api.nvim_create_user_command("PetsSleepToggle", function() + pets.toggle_sleep() +end, {}) diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua index 5f5dbc4..411efa6 100644 --- a/lua/pets/pet.lua +++ b/lua/pets/pet.lua @@ -72,4 +72,8 @@ function M.Pet:toggle_hide() end end +function M.Pet:toggle_sleep() + self.animation.sleeping = not self.animation.sleeping +end + return M diff --git a/lua/pets/utils.lua b/lua/pets/utils.lua index dbf1191..366de2a 100644 --- a/lua/pets/utils.lua +++ b/lua/pets/utils.lua @@ -88,4 +88,13 @@ function M.parse_popup_hl(highlight) ) end +function M.table_includes(table, key) + for _, value in ipairs(table) do + if value == key then + return true + end + end + return false +end + return M |