mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-04 02:24:00 +00:00
Improve some skel anim edge cases; warning fixes. Also new Lua function.
+ entity_setAnimationTime()
This commit is contained in:
parent
da8faf2bd9
commit
92ab459736
3 changed files with 47 additions and 34 deletions
|
@ -4323,16 +4323,15 @@ luaFunc(entity_isAnimating)
|
||||||
luaFunc(entity_getAnimationName)
|
luaFunc(entity_getAnimationName)
|
||||||
{
|
{
|
||||||
Entity *e = entity(L);
|
Entity *e = entity(L);
|
||||||
const char *ret = "";
|
|
||||||
int layer = lua_tointeger(L, 2);
|
int layer = lua_tointeger(L, 2);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
if (Animation *anim = e->skeletalSprite.getCurrentAnimation(layer))
|
if (Animation *anim = e->skeletalSprite.getCurrentAnimation(layer))
|
||||||
{
|
{
|
||||||
ret = anim->name.c_str();
|
luaReturnStr(anim->name.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
luaReturnStr(ret);
|
luaReturnNil();
|
||||||
}
|
}
|
||||||
|
|
||||||
luaFunc(entity_getAnimationLength)
|
luaFunc(entity_getAnimationLength)
|
||||||
|
@ -4342,7 +4341,7 @@ luaFunc(entity_getAnimationLength)
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
Animation *anim = 0;
|
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));
|
anim = e->skeletalSprite.getAnimation(lua_tostring(L, 2));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -4696,6 +4695,21 @@ luaFunc(entity_getAnimationTime)
|
||||||
luaReturnNil();
|
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
|
// entity, x, y, time, ease, relative
|
||||||
luaFunc(entity_move)
|
luaFunc(entity_move)
|
||||||
{
|
{
|
||||||
|
@ -6449,8 +6463,8 @@ luaFunc(bone_getIndex)
|
||||||
Bone *b = bone(L);
|
Bone *b = bone(L);
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
if (b)
|
if (b)
|
||||||
idx = b->boneIdx;
|
idx = (int)b->boneIdx;
|
||||||
luaReturnNum(idx);
|
luaReturnInt(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
luaFunc(bone_getName)
|
luaFunc(bone_getName)
|
||||||
|
@ -9114,7 +9128,7 @@ luaFunc(isShuttingDownGameState)
|
||||||
|
|
||||||
static void _fillPathfindTables(lua_State *L, VectorPath& path, int xs_idx, int ys_idx)
|
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))
|
if(lua_istable(L, xs_idx))
|
||||||
lua_pushvalue(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))
|
if(!PathFinding::generatePathSimple(path, start, end, lua_tointeger(L, 5), obs))
|
||||||
luaReturnBool(false);
|
luaReturnBool(false);
|
||||||
|
|
||||||
const unsigned num = path.getNumPathNodes();
|
const unsigned num = (unsigned)path.getNumPathNodes();
|
||||||
lua_pushinteger(L, num);
|
lua_pushinteger(L, num);
|
||||||
|
|
||||||
_fillPathfindTables(L, path, 6, 7);
|
_fillPathfindTables(L, path, 6, 7);
|
||||||
|
@ -10304,6 +10318,7 @@ static const struct {
|
||||||
luaRegister(entity_stopAnimation),
|
luaRegister(entity_stopAnimation),
|
||||||
luaRegister(entity_getAnimationLoop),
|
luaRegister(entity_getAnimationLoop),
|
||||||
luaRegister(entity_getAnimationTime),
|
luaRegister(entity_getAnimationTime),
|
||||||
|
luaRegister(entity_setAnimationTime),
|
||||||
|
|
||||||
luaRegister(entity_setCurrentTarget),
|
luaRegister(entity_setCurrentTarget),
|
||||||
luaRegister(entity_stopInterpolating),
|
luaRegister(entity_stopInterpolating),
|
||||||
|
|
|
@ -552,8 +552,15 @@ float AnimationLayer::transitionAnimate(std::string anim, float time, int loop)
|
||||||
{
|
{
|
||||||
stringToLower(anim);
|
stringToLower(anim);
|
||||||
float totalTime =0;
|
float totalTime =0;
|
||||||
if (createTransitionAnimation(anim, time))
|
if(Animation *a = this->s->getAnimation(anim))
|
||||||
{
|
{
|
||||||
|
if (time <= 0) // no transition?
|
||||||
|
{
|
||||||
|
animate(anim, loop);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
createTransitionAnimation(*a, time);
|
||||||
timeMultiplier = 1;
|
timeMultiplier = 1;
|
||||||
|
|
||||||
currentAnimation = -1;
|
currentAnimation = -1;
|
||||||
|
@ -562,15 +569,12 @@ float AnimationLayer::transitionAnimate(std::string anim, float time, int loop)
|
||||||
animating = 1;
|
animating = 1;
|
||||||
animationLength = getCurrentAnimation()->getAnimationLength();
|
animationLength = getCurrentAnimation()->getAnimationLength();
|
||||||
enqueueAnimation(anim, loop);
|
enqueueAnimation(anim, loop);
|
||||||
Animation *a = this->s->getAnimation(anim);
|
}
|
||||||
if (a)
|
|
||||||
{
|
|
||||||
if (loop > -1)
|
if (loop > -1)
|
||||||
totalTime = a->getAnimationLength()*(loop+1) + time;
|
totalTime = a->getAnimationLength()*(loop+1) + time;
|
||||||
else
|
else
|
||||||
totalTime = a->getAnimationLength() + time;
|
totalTime = a->getAnimationLength() + time;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return totalTime;
|
return totalTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,11 +597,8 @@ Animation* AnimationLayer::getCurrentAnimation()
|
||||||
return &s->animations[currentAnimation];
|
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();
|
blendAnimation.keyframes.clear();
|
||||||
SkeletalKeyframe k;
|
SkeletalKeyframe k;
|
||||||
k.t = 0;
|
k.t = 0;
|
||||||
|
@ -615,14 +616,11 @@ bool AnimationLayer::createTransitionAnimation(const std::string& anim, float ti
|
||||||
blendAnimation.keyframes.push_back(k);
|
blendAnimation.keyframes.push_back(k);
|
||||||
|
|
||||||
SkeletalKeyframe k2;
|
SkeletalKeyframe k2;
|
||||||
SkeletalKeyframe *rk = to->getKeyframe(0);
|
k2 = *to.getKeyframe(0);
|
||||||
if (!rk) return false;
|
|
||||||
k2 = *rk;
|
|
||||||
k2.t = time;
|
k2.t = time;
|
||||||
blendAnimation.keyframes.push_back(k2);
|
blendAnimation.keyframes.push_back(k2);
|
||||||
|
|
||||||
blendAnimation.name = anim;
|
blendAnimation.name = to.name;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -908,7 +906,7 @@ void AnimationLayer::update(float dt)
|
||||||
{
|
{
|
||||||
timer += dt*timeMultiplier.x;
|
timer += dt*timeMultiplier.x;
|
||||||
|
|
||||||
if (timer > animationLength)
|
if (timer >= animationLength)
|
||||||
{
|
{
|
||||||
float leftover;
|
float leftover;
|
||||||
if (animationLength > 0)
|
if (animationLength > 0)
|
||||||
|
|
|
@ -203,7 +203,7 @@ public:
|
||||||
void updateBones();
|
void updateBones();
|
||||||
void stopAnimation();
|
void stopAnimation();
|
||||||
float getAnimationLength();
|
float getAnimationLength();
|
||||||
bool createTransitionAnimation(const std::string& anim, float time);
|
void createTransitionAnimation(Animation& to, float time);
|
||||||
void playAnimation(int idx, int loop);
|
void playAnimation(int idx, int loop);
|
||||||
void playCurrentAnimation(int loop);
|
void playCurrentAnimation(int loop);
|
||||||
void enqueueAnimation(const std::string& anim, int loop);
|
void enqueueAnimation(const std::string& anim, int loop);
|
||||||
|
|
Loading…
Add table
Reference in a new issue