aboutsummaryrefslogtreecommitdiff
path: root/lua/pets/pet.lua
diff options
context:
space:
mode:
authorKyle Mendes <pink@hey.com>2023-02-16 14:33:05 -0500
committerKyle Mendes <pink@hey.com>2023-02-16 14:33:05 -0500
commit1edd15c5045ccdf84dd57a3de199e008cda52f34 (patch)
treeeee06deb1255e80f4a233cd2a65c6ba6a57f35a5 /lua/pets/pet.lua
parentdocs(help): auto generate docs (diff)
Adding statefulness when toggling settings
Diffstat (limited to 'lua/pets/pet.lua')
-rw-r--r--lua/pets/pet.lua46
1 files changed, 18 insertions, 28 deletions
diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua
index 411efa6..7e2a302 100644
--- a/lua/pets/pet.lua
+++ b/lua/pets/pet.lua
@@ -8,19 +8,20 @@ M.Pet.__index = M.Pet
-- @param style the color/style of the pet e.g. brown
-- @param user_opts the table with user options
-- @return a new Pet instance
-function M.Pet.new(name, type, style, user_opts)
+function M.Pet.new(name, type, style, user_opts, state)
local instance = setmetatable({}, M.Pet)
instance.name = name
instance.type = type
instance.style = style
instance.death_animation = user_opts.death_animation
+ instance.state = state
local wd = debug.getinfo(1).source:sub(2):match("(.*nvim/)") .. "media/"
instance.sourcedir = wd .. type .. "/" .. style .. "/"
instance.popup = require("nui.popup")(user_opts.popup)
instance.animation =
- require("pets.animations").Animation.new(instance.sourcedir, type, style, instance.popup, user_opts)
+ require("pets.animations").Animation.new(instance.sourcedir, type, style, instance.popup, user_opts, instance.state)
return instance
end
@@ -44,36 +45,25 @@ function M.Pet:kill()
end
end
-function M.Pet:toggle_pause()
- if not self.paused then
- self.animation:stop_timer()
- self.paused = true
- else
- if self.animation.current_image then
- self.animation.current_image:delete(0, { free = false })
- end
- self.animation:start_timer()
- self.paused = false
- end
+function M.Pet:set_paused(paused)
+ self.state.paused = paused
+ self.animation:set_state({
+ paused = paused,
+ })
end
-function M.Pet:toggle_hide()
- if not self.paused then
- self.animation:stop_timer()
- if self.animation.current_image then
- self.animation.current_image:delete(0, { free = false })
- end
- self.popup:unmount()
- self.paused = true
- else
- self.popup:mount()
- self.animation:start()
- self.paused = false
- end
+function M.Pet:set_hidden(hidden)
+ self.state.hidden = hidden
+ self.state.paused = hidden
+
+ self.animation:set_state({
+ hidden = hidden,
+ paused = hidden,
+ })
end
-function M.Pet:toggle_sleep()
- self.animation.sleeping = not self.animation.sleeping
+function M.Pet:set_sleep(sleeping)
+ self.animation:set_state({sleeping = sleeping})
end
return M