1 | // Aseprite |
2 | // Copyright (C) 2018 Igara Studio S.A. |
3 | // Copyright (C) 2018 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifdef HAVE_CONFIG_H |
9 | #include "config.h" |
10 | #endif |
11 | |
12 | #include "app/app.h" |
13 | #include "app/console.h" |
14 | #include "app/context.h" |
15 | #include "app/context_observer.h" |
16 | #include "app/script/docobj.h" |
17 | #include "app/script/engine.h" |
18 | #include "app/script/luacpp.h" |
19 | #include "app/site.h" |
20 | #include "doc/cel.h" |
21 | #include "doc/layer.h" |
22 | #include "doc/sprite.h" |
23 | |
24 | namespace app { |
25 | namespace script { |
26 | |
27 | namespace { |
28 | |
29 | int Site_get_sprite(lua_State* L) |
30 | { |
31 | auto site = get_obj<Site>(L, 1); |
32 | if (site->sprite()) |
33 | push_docobj(L, site->sprite()); |
34 | else |
35 | lua_pushnil(L); |
36 | return 1; |
37 | } |
38 | |
39 | int Site_get_layer(lua_State* L) |
40 | { |
41 | auto site = get_obj<Site>(L, 1); |
42 | if (site->layer()) |
43 | push_docobj<Layer>(L, site->layer()); |
44 | else |
45 | lua_pushnil(L); |
46 | return 1; |
47 | } |
48 | |
49 | int Site_get_cel(lua_State* L) |
50 | { |
51 | auto site = get_obj<Site>(L, 1); |
52 | if (site->cel()) |
53 | push_docobj<Cel>(L, site->cel()); |
54 | else |
55 | lua_pushnil(L); |
56 | return 1; |
57 | } |
58 | |
59 | int Site_get_frame(lua_State* L) |
60 | { |
61 | auto site = get_obj<Site>(L, 1); |
62 | if (site->sprite()) |
63 | push_sprite_frame(L, site->sprite(), site->frame()); |
64 | else |
65 | lua_pushnil(L); |
66 | return 1; |
67 | } |
68 | |
69 | int (lua_State* L) |
70 | { |
71 | auto site = get_obj<Site>(L, 1); |
72 | lua_pushinteger(L, site->frame()+1); |
73 | return 1; |
74 | } |
75 | |
76 | int Site_get_image(lua_State* L) |
77 | { |
78 | auto site = get_obj<Site>(L, 1); |
79 | if (site->cel()) |
80 | push_cel_image(L, site->cel()); |
81 | else |
82 | lua_pushnil(L); |
83 | return 1; |
84 | } |
85 | |
86 | const luaL_Reg Site_methods[] = { |
87 | { nullptr, nullptr } |
88 | }; |
89 | |
90 | const Property Site_properties[] = { |
91 | { "sprite" , Site_get_sprite, nullptr }, |
92 | { "layer" , Site_get_layer, nullptr }, |
93 | { "cel" , Site_get_cel, nullptr }, |
94 | { "frame" , Site_get_frame, nullptr }, |
95 | { "frameNumber" , Site_get_frameNumber, nullptr }, |
96 | { "image" , Site_get_image, nullptr }, |
97 | { nullptr, nullptr, nullptr } |
98 | }; |
99 | |
100 | } // anonymous namespace |
101 | |
102 | DEF_MTNAME(app::Site); |
103 | |
104 | void register_site_class(lua_State* L) |
105 | { |
106 | REG_CLASS(L, Site); |
107 | REG_CLASS_PROPERTIES(L, Site); |
108 | } |
109 | |
110 | } // namespace script |
111 | } // namespace app |
112 | |