diff options
Diffstat (limited to 'src/lua/modules/graphics/je_lua_animation.cpp')
-rw-r--r-- | src/lua/modules/graphics/je_lua_animation.cpp | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/src/lua/modules/graphics/je_lua_animation.cpp b/src/lua/modules/graphics/je_lua_animation.cpp index 1db66f1..cc82685 100644 --- a/src/lua/modules/graphics/je_lua_animation.cpp +++ b/src/lua/modules/graphics/je_lua_animation.cpp @@ -35,34 +35,67 @@ namespace JinEngine return 0; } - LUA_IMPLEMENT int l_render(lua_State* L) + // addFrame(frame) + LUA_IMPLEMENT int l_addFrame(lua_State* L) { - SharedAnimation sprite = checkAnimation(L); - float x = luax_checknumber(L, 2); - float y = luax_checknumber(L, 3); - float sx = luax_checknumber(L, 4); - float sy = luax_checknumber(L, 5); - float r = luax_checknumber(L, 6); - sprite->render(x, y, sx, sy, r); + SharedAnimation shrAnimation = checkAnimation(L); + Proxy* pxySprite = (Proxy*)luax_checktype(L, 2, Jin_Lua_Sprite); + Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>(); + shrAnimation->addFrame(shrSprite.getObject()); + int i = shrAnimation->getFrameCount() - 1; + shrAnimation.setDependency((int)AnimationDependency::DEP_SPRITES + i, &shrSprite); return 0; } - LUA_IMPLEMENT int l_getSize(lua_State* L) + // addFrames(frames table) + LUA_IMPLEMENT int l_addFrames(lua_State* L) { - SharedAnimation sprite = checkAnimation(L); - //Vector2<int> size = sprite->getSize(); - //luax_pushinteger(L, size.x); - //luax_pushinteger(L, size.y); + SharedAnimation shrAnimation = checkAnimation(L); + if (!luax_istable(L, 2)) + { + luax_typerror(L, 2, "sprites table"); + return 1; + } + int n = luax_tableidxlen(L, 2); + for (int i = 1; i <= n; ++i) + { + luax_rawgeti(L, 2, i); + Proxy* pxySprite = (Proxy*)luax_checktype(L, -1, Jin_Lua_Sprite); + Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>(); + shrAnimation->addFrame(shrSprite.getObject()); + int index = shrAnimation->getFrameCount() - 1; + shrAnimation.setDependency((int)AnimationDependency::DEP_SPRITES + index, &shrSprite); + } + return 0; + } + + LUA_IMPLEMENT int l_isLoop(lua_State* L) + { + SharedAnimation shrAnimation = checkAnimation(L); + bool loop = shrAnimation->isLoop(); + luax_pushboolean(L, loop); + return 1; + } + + LUA_IMPLEMENT int l_getSpeed(lua_State* L) + { + SharedAnimation shrAnimation = checkAnimation(L); + float speed = shrAnimation->getSpeed(); + luax_pushnumber(L, speed); return 1; } LUA_EXPORT void luaopen_Animation(lua_State* L) { luaL_Reg methods[] = { - { "__gc", l_gc }, - { "render", l_render }, - { "getSize", l_getSize }, - { 0, 0 } + { "__gc", l_gc }, + { "addFrame", l_addFrame }, + { "addFrames", l_addFrames }, + { "isLoop", l_isLoop }, + { "getSpeed", l_getSpeed }, + { "getFrameCount", l_getSpeed }, + //{ "getFrame", l_getFrame }, + { 0, 0 } }; luax_newtype(L, Jin_Lua_Animation, methods); } |