2018-08-21 02:15:38 +08:00
|
|
|
// Aseprite
|
2024-09-02 04:59:55 +08:00
|
|
|
// Copyright (C) 2018-2024 Igara Studio S.A.
|
2018-08-21 02:15:38 +08:00
|
|
|
// Copyright (C) 2018 David Capello
|
|
|
|
//
|
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2021-10-02 21:09:35 +08:00
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/console.h"
|
|
|
|
#include "app/context.h"
|
|
|
|
#include "app/context_observer.h"
|
2025-07-23 21:11:57 +08:00
|
|
|
#include "app/doc.h"
|
|
|
|
#include "app/doc_undo.h"
|
2018-11-21 05:12:43 +08:00
|
|
|
#include "app/script/docobj.h"
|
2018-08-20 22:25:08 +08:00
|
|
|
#include "app/script/engine.h"
|
|
|
|
#include "app/script/luacpp.h"
|
2018-08-21 02:15:38 +08:00
|
|
|
#include "app/site.h"
|
2018-11-21 05:12:43 +08:00
|
|
|
#include "doc/cel.h"
|
|
|
|
#include "doc/layer.h"
|
|
|
|
#include "doc/sprite.h"
|
2018-08-21 02:15:38 +08:00
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
namespace app { namespace script {
|
2018-08-21 02:15:38 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
int Site_get_sprite(lua_State* L)
|
2018-08-21 02:15:38 +08:00
|
|
|
{
|
2018-08-20 22:25:08 +08:00
|
|
|
auto site = get_obj<Site>(L, 1);
|
2018-08-21 02:15:38 +08:00
|
|
|
if (site->sprite())
|
2018-11-21 05:12:43 +08:00
|
|
|
push_docobj(L, site->sprite());
|
2018-08-21 02:15:38 +08:00
|
|
|
else
|
2018-08-20 22:25:08 +08:00
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
2018-08-21 02:15:38 +08:00
|
|
|
}
|
|
|
|
|
2018-09-05 03:10:32 +08:00
|
|
|
int Site_get_layer(lua_State* L)
|
|
|
|
{
|
|
|
|
auto site = get_obj<Site>(L, 1);
|
|
|
|
if (site->layer())
|
2018-11-21 05:12:43 +08:00
|
|
|
push_docobj<Layer>(L, site->layer());
|
2018-09-05 03:10:32 +08:00
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Site_get_cel(lua_State* L)
|
|
|
|
{
|
|
|
|
auto site = get_obj<Site>(L, 1);
|
|
|
|
if (site->cel())
|
2018-11-21 05:12:43 +08:00
|
|
|
push_docobj<Cel>(L, site->cel());
|
2018-09-05 03:10:32 +08:00
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Site_get_frame(lua_State* L)
|
2018-11-23 02:05:21 +08:00
|
|
|
{
|
|
|
|
auto site = get_obj<Site>(L, 1);
|
|
|
|
if (site->sprite())
|
|
|
|
push_sprite_frame(L, site->sprite(), site->frame());
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Site_get_frameNumber(lua_State* L)
|
2018-09-05 03:10:32 +08:00
|
|
|
{
|
|
|
|
auto site = get_obj<Site>(L, 1);
|
|
|
|
lua_pushinteger(L, site->frame() + 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
int Site_get_image(lua_State* L)
|
2018-08-21 02:15:38 +08:00
|
|
|
{
|
2018-08-20 22:25:08 +08:00
|
|
|
auto site = get_obj<Site>(L, 1);
|
2018-08-31 07:47:11 +08:00
|
|
|
if (site->cel())
|
|
|
|
push_cel_image(L, site->cel());
|
2018-08-21 02:15:38 +08:00
|
|
|
else
|
2018-08-20 22:25:08 +08:00
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
2018-08-21 02:15:38 +08:00
|
|
|
}
|
|
|
|
|
2024-09-02 04:59:55 +08:00
|
|
|
int Site_get_tilemapMode(lua_State* L)
|
|
|
|
{
|
|
|
|
auto site = get_obj<Site>(L, 1);
|
|
|
|
if (site)
|
|
|
|
lua_pushinteger(L, (int)site->tilemapMode());
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Site_get_tilesetMode(lua_State* L)
|
|
|
|
{
|
|
|
|
auto site = get_obj<Site>(L, 1);
|
|
|
|
if (site)
|
|
|
|
lua_pushinteger(L, (int)site->tilesetMode());
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
const luaL_Reg Site_methods[] = {
|
|
|
|
{ nullptr, nullptr }
|
2018-08-21 02:15:38 +08:00
|
|
|
};
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
const Property Site_properties[] = {
|
2018-08-21 02:15:38 +08:00
|
|
|
{ "sprite", Site_get_sprite, nullptr },
|
2018-09-05 03:10:32 +08:00
|
|
|
{ "layer", Site_get_layer, nullptr },
|
|
|
|
{ "cel", Site_get_cel, nullptr },
|
|
|
|
{ "frame", Site_get_frame, nullptr },
|
2018-11-23 02:05:21 +08:00
|
|
|
{ "frameNumber", Site_get_frameNumber, nullptr },
|
2018-08-21 02:15:38 +08:00
|
|
|
{ "image", Site_get_image, nullptr },
|
2024-09-02 04:59:55 +08:00
|
|
|
{ "tilemapMode", Site_get_tilemapMode, nullptr },
|
|
|
|
{ "tilesetMode", Site_get_tilesetMode, nullptr },
|
2018-08-20 22:25:08 +08:00
|
|
|
{ nullptr, nullptr, nullptr }
|
2018-08-21 02:15:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
DEF_MTNAME(app::Site);
|
2018-08-21 02:15:38 +08:00
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
void register_site_class(lua_State* L)
|
2018-08-21 02:15:38 +08:00
|
|
|
{
|
2018-08-20 22:25:08 +08:00
|
|
|
REG_CLASS(L, Site);
|
|
|
|
REG_CLASS_PROPERTIES(L, Site);
|
2018-08-21 02:15:38 +08:00
|
|
|
}
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
}} // namespace app::script
|