From 84e48c03209263de620a411a04e3f9f5450e8b62 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 26 May 2022 13:09:47 +0200 Subject: [PATCH] fix: add fallback for animations --- .../birb/modules/assets/types/animator.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/birb/modules/assets/types/animator.lua b/sonic-radiance.love/birb/modules/assets/types/animator.lua index 38a7f3f..5787e09 100644 --- a/sonic-radiance.love/birb/modules/assets/types/animator.lua +++ b/sonic-radiance.love/birb/modules/assets/types/animator.lua @@ -87,9 +87,18 @@ function Animator:changeAnimation(name, restart) restart = restart or false end - self.currentAnimation = name + if (self.sprite.data.animations[name] ~= nil) then + self.currentAnimation = name + else + self.currentAnimation = self.sprite.data.metadata.defaultAnim + end + self.animationData = self.sprite.data.animations[self.currentAnimation] + if (self.animationData == nil) then + error("animation " .. self.currentAnimation .. " not found.") + end + if (restart == true) then self.frame = self.animationData.startAt self.frameTimer = 0