aboutsummaryrefslogtreecommitdiff
path: root/lua/pets
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-03-04 18:10:34 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-03-04 18:11:41 +0100
commit9f02380f254bf77a47fc39a84b99df1ee0d8ba4c (patch)
tree7d6c750f5e122f5445d3fb12783ad52adc9f5550 /lua/pets
parentrefactor: PetsSleepToggle to PetsIdleToggle (diff)
refactor(animations): pet-specific set_next_col()
Diffstat (limited to 'lua/pets')
-rw-r--r--lua/pets/animations.lua19
-rw-r--r--lua/pets/pets/dog.lua6
2 files changed, 20 insertions, 5 deletions
diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua
index f3e24b5..65a410f 100644
--- a/lua/pets/animations.lua
+++ b/lua/pets/animations.lua
@@ -47,9 +47,10 @@ function M.Animation.new(sourcedir, type, style, popup, user_opts, state)
end
-- setup next_actions
- local specs = require("pets.pets." .. type)
- instance.next_actions = specs.next_actions
- instance.idle_actions = specs.idle_actions
+ local pet = require("pets.pets." .. type)
+ instance.next_actions = pet.next_actions
+ instance.idle_actions = pet.idle_actions
+ instance.movements = pet.movements
return instance
end
@@ -180,18 +181,26 @@ end
-- @function set horizontal movement per frame based on current action
function M.Animation:set_next_col()
- if self.current_action == "walk" then
+ if vim.tbl_contains(self.movements.right.normal, self.current_action) then
if self.col < self.popup.win_config.width - 8 then
self.col = self.col + 1
else
self.col = M.base_col
end
- elseif self.current_action == "run" then
+ elseif vim.tbl_contains(self.movements.right.fast, self.current_action) then
if self.col < self.popup.win_config.width - 8 then
self.col = self.col + 2
else
self.col = M.base_col
end
+ elseif vim.tbl_contains(self.movements.right.slow, self.current_action) then
+ if self.col < self.popup.win_config.width - 8 then
+ if self.frame_counter % 2 == 0 or self.repetitions % 2 == 0 then
+ self.col = self.col + 1
+ end
+ else
+ self.col = M.base_col
+ end
end
end
diff --git a/lua/pets/pets/dog.lua b/lua/pets/pets/dog.lua
index d9ef11f..80f04da 100644
--- a/lua/pets/pets/dog.lua
+++ b/lua/pets/pets/dog.lua
@@ -8,4 +8,10 @@ return {
walk = { "run", "idle" },
},
idle_actions = { "idle", "sit", "liedown" },
+ movements = {
+ right = {
+ normal = { "walk" },
+ fast = { "run" },
+ },
+ },
}