From dca4ece7fe403bc09a9c1e98fc97c0fd59a13a1d Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 23 Jun 2019 15:25:56 +0200 Subject: [PATCH] feat(assets): add a new getCurrentAnimation function --- CHANGELOG.md | 2 ++ gamecore/modules/assets/animator.lua | 4 ++++ gamecore/modules/assets/sprites.lua | 4 ++++ gamecore/modules/world/actors/baseactor.lua | 9 +++++++++ 4 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b7208a..18e70d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **world:** Add more wrapper around sprite functions in BaseActor +- **assets:** Add a new getCurrentAnimation function + ### Changed - **world2D:** Use a list for bodies (hitboxes, etc) and one other for actors diff --git a/gamecore/modules/assets/animator.lua b/gamecore/modules/assets/animator.lua index 6aced5a..17fa139 100644 --- a/gamecore/modules/assets/animator.lua +++ b/gamecore/modules/assets/animator.lua @@ -94,6 +94,10 @@ end -- INFO FUNCTIONS -- get information with these functions +function Animator:getCurrentAnimation() + return self.currentAnimation +end + function Animator:getAnimationDuration(animation) return (self.animationData.endAt - self.animationData.startAt) / self.animationData.speed end diff --git a/gamecore/modules/assets/sprites.lua b/gamecore/modules/assets/sprites.lua index 052f3f2..f33b919 100644 --- a/gamecore/modules/assets/sprites.lua +++ b/gamecore/modules/assets/sprites.lua @@ -66,6 +66,10 @@ end -- INFO FUNCTIONS -- get information with these functions +function Sprite:getCurrentAnimation() + return self.animator:getCurrentAnimation() +end + function Sprite:animationExist(name) return self.animator:animationExist(name) end diff --git a/gamecore/modules/world/actors/baseactor.lua b/gamecore/modules/world/actors/baseactor.lua index c9703ab..231d15f 100644 --- a/gamecore/modules/world/actors/baseactor.lua +++ b/gamecore/modules/world/actors/baseactor.lua @@ -236,6 +236,15 @@ function BaseActor:setSpriteScallingY(sy) self.sprite.sy = sy end +function BaseActor:getCurrentAnimation() + if (self.sprite.clone == nil) then + self.assets.sprites[self.sprite.name]:getCurrentAnimation() + else + self.sprite.clone:getCurrentAnimation() + end +end + + function BaseActor:getSpriteScalling() return self.sprite.sx, self.sprite.sy end