2018-09-05 03:10:32 +08:00
|
|
|
// Aseprite
|
2025-03-12 04:17:22 +08:00
|
|
|
// Copyright (C) 2018-2025 Igara Studio S.A.
|
2018-09-05 03:10:32 +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
|
|
|
|
|
2018-09-11 02:11:59 +08:00
|
|
|
#include "app/cmd/set_layer_blend_mode.h"
|
2018-09-05 03:10:32 +08:00
|
|
|
#include "app/cmd/set_layer_name.h"
|
|
|
|
#include "app/cmd/set_layer_opacity.h"
|
2023-01-11 21:48:39 +08:00
|
|
|
#include "app/cmd/set_layer_tileset.h"
|
2019-08-28 06:57:49 +08:00
|
|
|
#include "app/doc.h"
|
|
|
|
#include "app/doc_api.h"
|
2024-06-04 06:00:04 +08:00
|
|
|
#include "app/pref/preferences.h"
|
2023-03-14 08:17:51 +08:00
|
|
|
#include "app/script/blend_mode.h"
|
2018-11-21 05:12:43 +08:00
|
|
|
#include "app/script/docobj.h"
|
2018-09-05 03:10:32 +08:00
|
|
|
#include "app/script/engine.h"
|
|
|
|
#include "app/script/luacpp.h"
|
2018-09-05 20:22:59 +08:00
|
|
|
#include "app/script/userdata.h"
|
2018-09-05 03:10:32 +08:00
|
|
|
#include "app/tx.h"
|
|
|
|
#include "doc/layer.h"
|
2019-03-30 02:57:10 +08:00
|
|
|
#include "doc/layer_tilemap.h"
|
2018-09-05 03:10:32 +08:00
|
|
|
#include "doc/sprite.h"
|
2023-01-11 21:48:39 +08:00
|
|
|
#include "doc/tileset.h"
|
|
|
|
#include "doc/tilesets.h"
|
2018-09-05 03:10:32 +08:00
|
|
|
|
|
|
|
namespace app { namespace script {
|
|
|
|
|
|
|
|
using namespace doc;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-09-05 20:41:44 +08:00
|
|
|
int Layer_eq(lua_State* L)
|
|
|
|
{
|
2022-05-24 04:15:15 +08:00
|
|
|
const auto a = may_get_docobj<Layer>(L, 1);
|
|
|
|
const auto b = may_get_docobj<Layer>(L, 2);
|
|
|
|
lua_pushboolean(L, (!a && !b) || (a && b && a->id() == b->id()));
|
2018-09-05 20:41:44 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-06 23:31:46 +08:00
|
|
|
int Layer_cel(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
auto cel = layer->cel(get_frame_number_from_arg(L, 2));
|
|
|
|
if (cel)
|
|
|
|
push_docobj<Cel>(L, cel);
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-01-06 03:01:42 +08:00
|
|
|
int Layer_get_id(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
lua_pushinteger(L, layer->id());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:10:32 +08:00
|
|
|
int Layer_get_sprite(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
push_docobj<Sprite>(L, layer->sprite());
|
2018-09-05 03:10:32 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-18 20:36:42 +08:00
|
|
|
int Layer_get_parent(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 20:36:42 +08:00
|
|
|
if (layer->parent() == layer->sprite()->root())
|
2018-11-21 05:12:43 +08:00
|
|
|
push_docobj<Sprite>(L, layer->sprite());
|
2018-09-18 20:36:42 +08:00
|
|
|
else
|
2018-11-21 05:12:43 +08:00
|
|
|
push_docobj<Layer>(L, layer->parent());
|
2018-09-18 20:36:42 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-08-28 06:57:49 +08:00
|
|
|
int Layer_get_layers(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
if (layer->isGroup())
|
|
|
|
push_group_layers(L, static_cast<LayerGroup*>(layer));
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_get_stackIndex(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
const auto& layers = layer->parent()->layers();
|
|
|
|
auto it = std::find(layers.begin(), layers.end(), layer);
|
|
|
|
ASSERT(it != layers.end());
|
|
|
|
if (it != layers.end())
|
|
|
|
lua_pushinteger(L, it - layers.begin() + 1);
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-18 20:36:42 +08:00
|
|
|
int Layer_get_previous(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 20:36:42 +08:00
|
|
|
if (auto previous = layer->getPrevious())
|
2018-11-21 05:12:43 +08:00
|
|
|
push_docobj<Layer>(L, previous);
|
2018-09-18 20:36:42 +08:00
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_get_next(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 20:36:42 +08:00
|
|
|
if (auto next = layer->getNext())
|
2018-11-21 05:12:43 +08:00
|
|
|
push_docobj<Layer>(L, next);
|
2018-09-18 20:36:42 +08:00
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:10:32 +08:00
|
|
|
int Layer_get_name(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-05 03:10:32 +08:00
|
|
|
lua_pushstring(L, layer->name().c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_get_opacity(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2024-06-04 06:00:04 +08:00
|
|
|
if (layer->isImage() ||
|
|
|
|
(layer->isGroup() && app::Preferences::instance().experimental.composeGroups())) {
|
2018-09-05 03:10:32 +08:00
|
|
|
lua_pushinteger(L, static_cast<LayerImage*>(layer)->opacity());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-11 02:11:59 +08:00
|
|
|
int Layer_get_blendMode(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2024-06-04 06:00:04 +08:00
|
|
|
if (layer->isImage() ||
|
|
|
|
(layer->isGroup() && app::Preferences::instance().experimental.composeGroups())) {
|
2023-03-14 08:17:51 +08:00
|
|
|
lua_pushinteger(
|
|
|
|
L,
|
|
|
|
int(base::convert_to<app::script::BlendMode>(static_cast<LayerImage*>(layer)->blendMode())));
|
2018-09-11 02:11:59 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-05 04:30:18 +08:00
|
|
|
int Layer_get_isImage(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-05 04:30:18 +08:00
|
|
|
lua_pushboolean(L, layer->isImage());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_get_isGroup(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-05 04:30:18 +08:00
|
|
|
lua_pushboolean(L, layer->isGroup());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-03-30 02:57:10 +08:00
|
|
|
int Layer_get_isTilemap(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
lua_pushboolean(L, layer->isTilemap());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-07 00:02:50 +08:00
|
|
|
int Layer_get_isTransparent(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-07 00:02:50 +08:00
|
|
|
lua_pushboolean(L, layer->isTransparent());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_get_isBackground(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-07 00:02:50 +08:00
|
|
|
lua_pushboolean(L, layer->isBackground());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-18 11:21:40 +08:00
|
|
|
int Layer_get_isEditable(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 11:21:40 +08:00
|
|
|
lua_pushboolean(L, layer->isEditable());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_get_isVisible(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 11:21:40 +08:00
|
|
|
lua_pushboolean(L, layer->isVisible());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_get_isContinuous(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 11:21:40 +08:00
|
|
|
lua_pushboolean(L, layer->isContinuous());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_get_isCollapsed(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 11:21:40 +08:00
|
|
|
lua_pushboolean(L, layer->isCollapsed());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_get_isExpanded(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 11:21:40 +08:00
|
|
|
lua_pushboolean(L, layer->isExpanded());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-10-07 03:04:54 +08:00
|
|
|
int Layer_get_isReference(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
lua_pushboolean(L, layer->isReference());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-12 05:29:15 +08:00
|
|
|
int Layer_get_cels(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-11-23 23:56:30 +08:00
|
|
|
push_cels(L, layer);
|
2018-09-12 05:29:15 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-03-30 02:57:10 +08:00
|
|
|
int Layer_get_tileset(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
if (layer->isTilemap())
|
|
|
|
push_tileset(L, static_cast<doc::LayerTilemap*>(layer)->tileset());
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2025-03-12 04:17:22 +08:00
|
|
|
int Layer_get_uuid(lua_State* L)
|
|
|
|
{
|
|
|
|
auto* layer = get_docobj<Layer>(L, 1);
|
|
|
|
push_obj(L, layer->uuid());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:10:32 +08:00
|
|
|
int Layer_set_name(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-05 03:10:32 +08:00
|
|
|
const char* name = lua_tostring(L, 2);
|
|
|
|
if (name) {
|
2023-12-13 08:34:30 +08:00
|
|
|
Tx tx(layer->sprite());
|
2018-09-05 03:10:32 +08:00
|
|
|
tx(new cmd::SetLayerName(layer, name));
|
|
|
|
tx.commit();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_set_opacity(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-05 03:10:32 +08:00
|
|
|
const int opacity = lua_tointeger(L, 2);
|
2024-06-04 06:00:04 +08:00
|
|
|
if (layer->isImage() || layer->isGroup()) {
|
2023-12-13 08:34:30 +08:00
|
|
|
Tx tx(layer->sprite());
|
2018-09-05 03:10:32 +08:00
|
|
|
tx(new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), opacity));
|
|
|
|
tx.commit();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-11 02:11:59 +08:00
|
|
|
int Layer_set_blendMode(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2023-03-14 08:17:51 +08:00
|
|
|
auto blendMode = app::script::BlendMode(lua_tointeger(L, 2));
|
2024-06-04 06:00:04 +08:00
|
|
|
if (layer->isImage() || layer->isGroup()) {
|
2023-12-13 08:34:30 +08:00
|
|
|
Tx tx(layer->sprite());
|
2018-09-11 02:11:59 +08:00
|
|
|
tx(new cmd::SetLayerBlendMode(static_cast<LayerImage*>(layer),
|
2023-03-14 08:17:51 +08:00
|
|
|
base::convert_to<doc::BlendMode>(blendMode)));
|
2018-09-11 02:11:59 +08:00
|
|
|
tx.commit();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-28 06:57:49 +08:00
|
|
|
int Layer_set_stackIndex(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2019-11-29 22:08:18 +08:00
|
|
|
const auto& layers = layer->parent()->layers();
|
|
|
|
int newStackIndex = lua_tointeger(L, 2);
|
|
|
|
int stackIndex = 1;
|
2019-08-28 06:57:49 +08:00
|
|
|
auto parent = layer->parent();
|
|
|
|
|
2019-11-29 22:08:18 +08:00
|
|
|
// First we need to know this layer stackIndex because we'll use
|
|
|
|
auto it = std::find(layers.begin(), layers.end(), layer);
|
|
|
|
ASSERT(it != layers.end());
|
|
|
|
if (it != layers.end())
|
|
|
|
stackIndex = it - layers.begin() + 1;
|
|
|
|
|
2019-08-28 06:57:49 +08:00
|
|
|
Layer* beforeThis = nullptr;
|
2019-11-29 22:08:18 +08:00
|
|
|
if (newStackIndex > stackIndex) {
|
|
|
|
++newStackIndex;
|
2019-08-28 06:57:49 +08:00
|
|
|
}
|
2019-11-29 22:08:18 +08:00
|
|
|
|
|
|
|
if (newStackIndex - 1 < int(parent->layers().size())) {
|
2022-06-10 05:28:06 +08:00
|
|
|
beforeThis = parent->layers()[std::clamp(newStackIndex - 1, 0, (int)parent->layers().size())];
|
2019-11-29 22:08:18 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
beforeThis = nullptr;
|
2019-08-28 06:57:49 +08:00
|
|
|
}
|
|
|
|
|
2019-11-29 22:08:18 +08:00
|
|
|
// Do nothing
|
|
|
|
if (beforeThis == layer)
|
|
|
|
return 0;
|
|
|
|
|
2019-08-28 06:57:49 +08:00
|
|
|
Doc* doc = static_cast<Doc*>(layer->sprite()->document());
|
2023-12-13 08:34:30 +08:00
|
|
|
Tx tx(doc);
|
2019-08-28 06:57:49 +08:00
|
|
|
DocApi(doc, tx).restackLayerBefore(layer, parent, beforeThis);
|
|
|
|
tx.commit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-18 11:21:40 +08:00
|
|
|
int Layer_set_isEditable(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 11:21:40 +08:00
|
|
|
layer->setEditable(lua_toboolean(L, 2));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_set_isVisible(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2024-02-27 00:11:26 +08:00
|
|
|
const bool newState = lua_toboolean(L, 2);
|
|
|
|
Doc* doc = static_cast<Doc*>(layer->sprite()->document());
|
|
|
|
doc->setLayerVisibilityWithNotifications(layer, newState);
|
2018-09-18 11:21:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_set_isContinuous(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 11:21:40 +08:00
|
|
|
layer->setContinuous(lua_toboolean(L, 2));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_set_isCollapsed(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 11:21:40 +08:00
|
|
|
layer->setCollapsed(lua_toboolean(L, 2));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Layer_set_isExpanded(lua_State* L)
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
2018-09-18 11:21:40 +08:00
|
|
|
layer->setCollapsed(!lua_toboolean(L, 2));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-28 06:57:49 +08:00
|
|
|
int Layer_set_parent(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
LayerGroup* parent = nullptr;
|
|
|
|
if (auto sprite = may_get_docobj<Sprite>(L, 2)) {
|
|
|
|
parent = sprite->root();
|
|
|
|
}
|
|
|
|
else if (auto parentLayer = may_get_docobj<Layer>(L, 2)) {
|
|
|
|
if (parentLayer->isGroup())
|
|
|
|
parent = static_cast<LayerGroup*>(parentLayer);
|
2020-05-29 01:24:10 +08:00
|
|
|
else
|
|
|
|
return luaL_error(L, "the given parent is not a layer group or sprite");
|
2019-08-28 06:57:49 +08:00
|
|
|
}
|
|
|
|
|
2020-05-29 02:12:26 +08:00
|
|
|
if (!parent)
|
|
|
|
return luaL_error(L, "parent cannot be nil");
|
|
|
|
else if (parent == layer)
|
2019-08-28 06:57:49 +08:00
|
|
|
return luaL_error(L, "the parent of a layer cannot be the layer itself");
|
|
|
|
|
|
|
|
// TODO Why? should we be able to do this? It would require some hard work:
|
|
|
|
// 1. convert color modes
|
|
|
|
// 2. multiple transactions for both modified sprites?
|
|
|
|
if (parent->sprite() != layer->sprite())
|
|
|
|
return luaL_error(L, "you cannot move layers between sprites");
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
Doc* doc = static_cast<Doc*>(layer->sprite()->document());
|
2023-12-13 08:34:30 +08:00
|
|
|
Tx tx(doc);
|
2019-08-28 06:57:49 +08:00
|
|
|
DocApi(doc, tx).restackLayerAfter(layer, parent, parent->lastLayer());
|
|
|
|
tx.commit();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-11 21:48:39 +08:00
|
|
|
int Layer_set_tileset(lua_State* L)
|
|
|
|
{
|
|
|
|
auto layer = get_docobj<Layer>(L, 1);
|
|
|
|
if (layer->isTilemap()) {
|
|
|
|
auto tilemap = static_cast<doc::LayerTilemap*>(layer);
|
|
|
|
doc::tileset_index tsi = tilemap->tilesetIndex();
|
|
|
|
|
|
|
|
if (auto tileset = may_get_docobj<Tileset>(L, 2))
|
|
|
|
tsi = layer->sprite()->tilesets()->getIndex(tileset);
|
|
|
|
else if (lua_isinteger(L, 2))
|
|
|
|
tsi = lua_tointeger(L, 2);
|
|
|
|
|
|
|
|
if (tsi != tilemap->tilesetIndex()) {
|
2023-12-13 08:34:30 +08:00
|
|
|
Tx tx(layer->sprite());
|
2023-01-11 21:48:39 +08:00
|
|
|
tx(new cmd::SetLayerTileset(tilemap, tsi));
|
|
|
|
tx.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:10:32 +08:00
|
|
|
const luaL_Reg Layer_methods[] = {
|
2018-09-05 20:41:44 +08:00
|
|
|
{ "__eq", Layer_eq },
|
2018-12-06 23:31:46 +08:00
|
|
|
{ "cel", Layer_cel },
|
2018-09-05 03:10:32 +08:00
|
|
|
{ nullptr, nullptr }
|
|
|
|
};
|
|
|
|
|
|
|
|
const Property Layer_properties[] = {
|
2023-01-06 03:01:42 +08:00
|
|
|
{ "id", Layer_get_id, nullptr },
|
2018-09-05 03:10:32 +08:00
|
|
|
{ "sprite", Layer_get_sprite, nullptr },
|
2019-08-28 06:57:49 +08:00
|
|
|
{ "parent", Layer_get_parent, Layer_set_parent },
|
|
|
|
{ "layers", Layer_get_layers, nullptr },
|
|
|
|
{ "stackIndex", Layer_get_stackIndex, Layer_set_stackIndex },
|
2018-09-18 20:36:42 +08:00
|
|
|
{ "previous", Layer_get_previous, nullptr },
|
|
|
|
{ "next", Layer_get_next, nullptr },
|
2018-09-05 03:10:32 +08:00
|
|
|
{ "name", Layer_get_name, Layer_set_name },
|
|
|
|
{ "opacity", Layer_get_opacity, Layer_set_opacity },
|
2018-09-11 02:11:59 +08:00
|
|
|
{ "blendMode", Layer_get_blendMode, Layer_set_blendMode },
|
2018-09-05 04:30:18 +08:00
|
|
|
{ "isImage", Layer_get_isImage, nullptr },
|
|
|
|
{ "isGroup", Layer_get_isGroup, nullptr },
|
2019-03-30 02:57:10 +08:00
|
|
|
{ "isTilemap", Layer_get_isTilemap, nullptr },
|
2018-09-07 00:02:50 +08:00
|
|
|
{ "isTransparent", Layer_get_isTransparent, nullptr },
|
|
|
|
{ "isBackground", Layer_get_isBackground, nullptr },
|
2018-09-18 11:21:40 +08:00
|
|
|
{ "isEditable", Layer_get_isEditable, Layer_set_isEditable },
|
|
|
|
{ "isVisible", Layer_get_isVisible, Layer_set_isVisible },
|
|
|
|
{ "isContinuous", Layer_get_isContinuous, Layer_set_isContinuous },
|
|
|
|
{ "isCollapsed", Layer_get_isCollapsed, Layer_set_isCollapsed },
|
|
|
|
{ "isExpanded", Layer_get_isExpanded, Layer_set_isExpanded },
|
2021-10-07 03:04:54 +08:00
|
|
|
{ "isReference", Layer_get_isReference, nullptr },
|
2018-09-12 05:29:15 +08:00
|
|
|
{ "cels", Layer_get_cels, nullptr },
|
2018-09-05 20:22:59 +08:00
|
|
|
{ "color", UserData_get_color<Layer>, UserData_set_color<Layer> },
|
|
|
|
{ "data", UserData_get_text<Layer>, UserData_set_text<Layer> },
|
2023-01-03 20:00:58 +08:00
|
|
|
{ "properties", UserData_get_properties<Layer>, UserData_set_properties<Layer> },
|
2023-01-11 21:48:39 +08:00
|
|
|
{ "tileset", Layer_get_tileset, Layer_set_tileset },
|
2025-03-12 04:17:22 +08:00
|
|
|
{ "uuid", Layer_get_uuid, nullptr },
|
2018-09-05 03:10:32 +08:00
|
|
|
{ nullptr, nullptr, nullptr }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
DEF_MTNAME(Layer);
|
|
|
|
|
|
|
|
void register_layer_class(lua_State* L)
|
|
|
|
{
|
|
|
|
using Layer = doc::Layer;
|
|
|
|
REG_CLASS(L, Layer);
|
|
|
|
REG_CLASS_PROPERTIES(L, Layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
}} // namespace app::script
|