1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-03 18:14:01 +00:00

Improve some skel anim edge cases; warning fixes. Also new Lua function.

+ entity_setAnimationTime()
This commit is contained in:
fgenesis 2022-11-16 22:46:56 +01:00
parent da8faf2bd9
commit 92ab459736
3 changed files with 47 additions and 34 deletions

View file

@ -4323,16 +4323,15 @@ luaFunc(entity_isAnimating)
luaFunc(entity_getAnimationName)
{
Entity *e = entity(L);
const char *ret = "";
int layer = lua_tointeger(L, 2);
if (e)
{
if (Animation *anim = e->skeletalSprite.getCurrentAnimation(layer))
{
ret = anim->name.c_str();
luaReturnStr(anim->name.c_str());
}
}
luaReturnStr(ret);
luaReturnNil();
}
luaFunc(entity_getAnimationLength)
@ -4342,7 +4341,7 @@ luaFunc(entity_getAnimationLength)
if (e)
{
Animation *anim = 0;
if (lua_isstring(L, 2))
if (lua_type(L, 2) == LUA_TSTRING) // lua_isstring() is incorrect here
anim = e->skeletalSprite.getAnimation(lua_tostring(L, 2));
else
{
@ -4696,6 +4695,21 @@ luaFunc(entity_getAnimationTime)
luaReturnNil();
}
luaFunc(entity_setAnimationTime)
{
SkeletalSprite *skel = getSkeletalSprite(entity(L));
int layer = lua_tointeger(L, 3);
if (skel)
{
AnimationLayer *a = skel->getAnimationLayer(layer);
if(a)
{
a->timer = lua_tonumber(L, 2);
}
}
luaReturnNil();
}
// entity, x, y, time, ease, relative
luaFunc(entity_move)
{
@ -6449,8 +6463,8 @@ luaFunc(bone_getIndex)
Bone *b = bone(L);
int idx = -1;
if (b)
idx = b->boneIdx;
luaReturnNum(idx);
idx = (int)b->boneIdx;
luaReturnInt(idx);
}
luaFunc(bone_getName)
@ -9114,7 +9128,7 @@ luaFunc(isShuttingDownGameState)
static void _fillPathfindTables(lua_State *L, VectorPath& path, int xs_idx, int ys_idx)
{
const unsigned num = path.getNumPathNodes();
const unsigned num = (unsigned)path.getNumPathNodes();
if(lua_istable(L, xs_idx))
lua_pushvalue(L, xs_idx);
@ -9159,7 +9173,7 @@ luaFunc(findPath)
if(!PathFinding::generatePathSimple(path, start, end, lua_tointeger(L, 5), obs))
luaReturnBool(false);
const unsigned num = path.getNumPathNodes();
const unsigned num = (unsigned)path.getNumPathNodes();
lua_pushinteger(L, num);
_fillPathfindTables(L, path, 6, 7);
@ -10304,6 +10318,7 @@ static const struct {
luaRegister(entity_stopAnimation),
luaRegister(entity_getAnimationLoop),
luaRegister(entity_getAnimationTime),
luaRegister(entity_setAnimationTime),
luaRegister(entity_setCurrentTarget),
luaRegister(entity_stopInterpolating),

View file

@ -552,24 +552,28 @@ float AnimationLayer::transitionAnimate(std::string anim, float time, int loop)
{
stringToLower(anim);
float totalTime =0;
if (createTransitionAnimation(anim, time))
if(Animation *a = this->s->getAnimation(anim))
{
timeMultiplier = 1;
currentAnimation = -1;
this->loop = 0;
timer = 0;
animating = 1;
animationLength = getCurrentAnimation()->getAnimationLength();
enqueueAnimation(anim, loop);
Animation *a = this->s->getAnimation(anim);
if (a)
if (time <= 0) // no transition?
{
if (loop > -1)
totalTime = a->getAnimationLength()*(loop+1) + time;
else
totalTime = a->getAnimationLength() + time;
animate(anim, loop);
}
else
{
createTransitionAnimation(*a, time);
timeMultiplier = 1;
currentAnimation = -1;
this->loop = 0;
timer = 0;
animating = 1;
animationLength = getCurrentAnimation()->getAnimationLength();
enqueueAnimation(anim, loop);
}
if (loop > -1)
totalTime = a->getAnimationLength()*(loop+1) + time;
else
totalTime = a->getAnimationLength() + time;
}
return totalTime;
}
@ -593,11 +597,8 @@ Animation* AnimationLayer::getCurrentAnimation()
return &s->animations[currentAnimation];
}
bool AnimationLayer::createTransitionAnimation(const std::string& anim, float time)
void AnimationLayer::createTransitionAnimation(Animation& to, float time)
{
Animation *to = s->getAnimation(anim);
if (!to) return false;
blendAnimation.keyframes.clear();
SkeletalKeyframe k;
k.t = 0;
@ -615,14 +616,11 @@ bool AnimationLayer::createTransitionAnimation(const std::string& anim, float ti
blendAnimation.keyframes.push_back(k);
SkeletalKeyframe k2;
SkeletalKeyframe *rk = to->getKeyframe(0);
if (!rk) return false;
k2 = *rk;
k2 = *to.getKeyframe(0);
k2.t = time;
blendAnimation.keyframes.push_back(k2);
blendAnimation.name = anim;
return true;
blendAnimation.name = to.name;
}
@ -908,7 +906,7 @@ void AnimationLayer::update(float dt)
{
timer += dt*timeMultiplier.x;
if (timer > animationLength)
if (timer >= animationLength)
{
float leftover;
if (animationLength > 0)

View file

@ -203,7 +203,7 @@ public:
void updateBones();
void stopAnimation();
float getAnimationLength();
bool createTransitionAnimation(const std::string& anim, float time);
void createTransitionAnimation(Animation& to, float time);
void playAnimation(int idx, int loop);
void playCurrentAnimation(int loop);
void enqueueAnimation(const std::string& anim, int loop);