aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/je_lua_animator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/je_lua_animator.cpp')
-rw-r--r--src/lua/modules/graphics/je_lua_animator.cpp157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/lua/modules/graphics/je_lua_animator.cpp b/src/lua/modules/graphics/je_lua_animator.cpp
new file mode 100644
index 0000000..2c835be
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_animator.cpp
@@ -0,0 +1,157 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_sprite.h"
+#include "je_lua_canvas.h"
+#include "je_lua_texture.h"
+#include "je_lua_shader.h"
+#include "je_lua_animator.h"
+#include "je_lua_animation.h"
+
+using namespace JinEngine::Math;
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Shaders;
+using namespace JinEngine::Graphics::Animations;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+ const char* Jin_Lua_Animator = "Animator";
+
+ typedef Shared<Animator>& SharedAnimator;
+
+ LUA_IMPLEMENT inline SharedAnimator checkAnimator(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Animator);
+ return proxy->getShared<Animator>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Animation);
+ p->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_update(lua_State* L)
+ {
+ SharedAnimator animator = checkAnimator(L);
+ float dt = luax_checknumber(L, 2);
+ animator->update(dt);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ SharedAnimator animator = checkAnimator(L);
+ animator->play();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ SharedAnimator animator = checkAnimator(L);
+ animator->pause();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ SharedAnimator animator = checkAnimator(L);
+ animator->resume();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rewind(lua_State* L)
+ {
+ SharedAnimator animator = checkAnimator(L);
+ animator->rewind();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_render(lua_State* L)
+ {
+ SharedAnimator animator = checkAnimator(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);
+ animator->render(x, y, sx, sy, r);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setAnimation(lua_State* L)
+ {
+ SharedAnimator shrAnimator = checkAnimator(L);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Animation);
+ Shared<Animation>& shrAnimation = proxy->getShared<Animation>();
+ shrAnimator.setDependency((int)AnimatorDependency::DEP_ANIMATION, &shrAnimation);
+ shrAnimator->setAnimation(shrAnimation.getObject());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_forceToFrame(lua_State* L)
+ {
+ SharedAnimator shrAnimator = checkAnimator(L);
+ int index = luax_checkinteger(L, 2);
+ shrAnimator->forceToFrame(index);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setSpeed(lua_State* L)
+ {
+ SharedAnimator shrAnimator = checkAnimator(L);
+ float fps = luax_checknumber(L, 2);
+ shrAnimator->setSpeed(fps);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setDefaultSpeed(lua_State* L)
+ {
+ SharedAnimator shrAnimator = checkAnimator(L);
+ shrAnimator->setDefaultSpeed();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setLoop(lua_State* L)
+ {
+ SharedAnimator shrAnimator = checkAnimator(L);
+ bool loop = luax_checkbool(L, 2);
+ shrAnimator->setLoop(loop);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setDefaultLoop(lua_State* L)
+ {
+ SharedAnimator shrAnimator = checkAnimator(L);
+ shrAnimator->setDefaultLoop();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Animator(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "update", l_update },
+ { "play", l_play },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "rewind", l_rewind },
+ { "render", l_render },
+ { "setAnimation", l_setAnimation },
+ { "forceToFrame", l_forceToFrame },
+ { "setSpeed", l_setSpeed },
+ { "setDefaultSpeed", l_setDefaultSpeed },
+ { "setLoop", l_setLoop },
+ { "setDefaultLoop", l_setDefaultLoop },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Animator, methods);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file