aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-03-05 09:47:05 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-03-05 09:48:03 +0100
commitb61c317cd91aa4acd0a031ccdb9e3d4bc9f8c331 (patch)
treebb845b16e384202c4bddc5d24b17414313ffcfca
parentchore(media): resize dog images (diff)
fix: extend pet-specific table to not raise errors
-rw-r--r--lua/pets/animations.lua22
-rw-r--r--lua/pets/utils.lua7
2 files changed, 19 insertions, 10 deletions
diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua
index 65a410f..9118523 100644
--- a/lua/pets/animations.lua
+++ b/lua/pets/animations.lua
@@ -5,7 +5,8 @@ M.Animation.__index = M.Animation
-- lines to insert in the buffer to avoid image stretching
local lines = {}
-local listdir = require("pets.utils").listdir
+local utils = require("pets.utils")
+local listdir = utils.listdir
-- @param sourcedir the full path for the media directory
-- @param type,style type and style of the pet
@@ -46,8 +47,9 @@ function M.Animation.new(sourcedir, type, style, popup, user_opts, state)
instance.frames[action] = current_frames
end
- -- setup next_actions
- local pet = require("pets.pets." .. type)
+ -- setup pet-specific values
+ -- extend the table to not get errors when something is not specified (i.e. left movements)
+ local pet = vim.tbl_deep_extend("keep", require("pets.pets." .. type), utils.default_pet_table)
instance.next_actions = pet.next_actions
instance.idle_actions = pet.idle_actions
instance.movements = pet.movements
@@ -109,6 +111,13 @@ function M.Animation:start()
end
end
+function M.Animation:stop()
+ if self.current_image then
+ self.current_image:delete(0, { free = false })
+ end
+ self:stop_timer()
+end
+
-- @function called on every tick from the timer, go to the next frame
function M.Animation:next_frame()
-- pouplate the buffer with spaces to avoid image distortion
@@ -204,13 +213,6 @@ function M.Animation:set_next_col()
end
end
-function M.Animation:stop()
- if self.current_image then
- self.current_image:delete(0, { free = false })
- end
- self:stop_timer()
-end
-
function M.Animation:set_state(new_state)
for key, value in pairs(new_state) do
self.state[key] = value
diff --git a/lua/pets/utils.lua b/lua/pets/utils.lua
index ffcbe6e..afea61d 100644
--- a/lua/pets/utils.lua
+++ b/lua/pets/utils.lua
@@ -1,5 +1,12 @@
local M = {}
M.available_pets = {}
+M.default_pet_table = {
+ idle_actions = {},
+ movements = {
+ right = { slow = {}, normal = {}, fast = {} },
+ left = { slow = {}, normal = {}, fast = {} },
+ },
+}
function M.listdir(path)
local sol = {}