aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/je_lua_animation.cpp
blob: 1db66f189ccf485a2c87ffb9b7f8f46f533ad76e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#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_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_Animation = "Animation";

        typedef Shared<Animation>& SharedAnimation;

        LUA_IMPLEMENT inline SharedAnimation checkAnimation(lua_State* L)
        {
            Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Animation);
            return proxy->getShared<Animation>();
        }

        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_render(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);
            return 0;
        }

        LUA_IMPLEMENT int l_getSize(lua_State* L)
        {
            SharedAnimation sprite = checkAnimation(L);
            //Vector2<int> size = sprite->getSize();
            //luax_pushinteger(L, size.x);
            //luax_pushinteger(L, size.y);
            return 1;
        }

        LUA_EXPORT void luaopen_Animation(lua_State* L)
        {
            luaL_Reg methods[] = {
                { "__gc",    l_gc },
                { "render",  l_render },
                { "getSize", l_getSize },
                { 0,         0 }
            };
            luax_newtype(L, Jin_Lua_Animation, methods);
        }

    } // namespace Lua
} // namespace JinEngine