mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-03 05:29:13 +00:00
[lua] Add a way to set the tileset associated to a layer tilemap
This commit is contained in:
parent
822357869a
commit
a6c1b2bc88
@ -511,6 +511,7 @@ add_library(app-lib
|
||||
cmd/set_layer_flags.cpp
|
||||
cmd/set_layer_name.cpp
|
||||
cmd/set_layer_opacity.cpp
|
||||
cmd/set_layer_tileset.cpp
|
||||
cmd/set_mask.cpp
|
||||
cmd/set_mask_position.cpp
|
||||
cmd/set_palette.cpp
|
||||
|
43
src/app/cmd/set_layer_tileset.cpp
Normal file
43
src/app/cmd/set_layer_tileset.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2023 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/set_layer_tileset.h"
|
||||
|
||||
#include "app/doc.h"
|
||||
#include "doc/layer_tilemap.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
SetLayerTileset::SetLayerTileset(doc::LayerTilemap* layer,
|
||||
doc::tileset_index newTsi)
|
||||
: WithLayer(layer)
|
||||
, m_oldTsi(layer->tilesetIndex())
|
||||
, m_newTsi(newTsi)
|
||||
{
|
||||
}
|
||||
|
||||
void SetLayerTileset::onExecute()
|
||||
{
|
||||
auto layer = static_cast<LayerTilemap*>(this->layer());
|
||||
layer->setTilesetIndex(m_newTsi);
|
||||
layer->incrementVersion();
|
||||
}
|
||||
|
||||
void SetLayerTileset::onUndo()
|
||||
{
|
||||
auto layer = static_cast<LayerTilemap*>(this->layer());
|
||||
layer->setTilesetIndex(m_oldTsi);
|
||||
layer->incrementVersion();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
44
src/app/cmd/set_layer_tileset.h
Normal file
44
src/app/cmd/set_layer_tileset.h
Normal file
@ -0,0 +1,44 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2023 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
|
||||
#ifndef APP_CMD_SET_LAYER_TILESET_H_INCLUDED
|
||||
#define APP_CMD_SET_LAYER_TILESET_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_layer.h"
|
||||
#include "doc/tile.h"
|
||||
|
||||
namespace doc {
|
||||
class LayerTilemap;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetLayerTileset : public Cmd
|
||||
, public WithLayer {
|
||||
public:
|
||||
SetLayerTileset(doc::LayerTilemap* layer,
|
||||
doc::tileset_index tsi);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
doc::tileset_index m_oldTsi;
|
||||
doc::tileset_index m_newTsi;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -12,6 +12,7 @@
|
||||
#include "app/cmd/set_layer_blend_mode.h"
|
||||
#include "app/cmd/set_layer_name.h"
|
||||
#include "app/cmd/set_layer_opacity.h"
|
||||
#include "app/cmd/set_layer_tileset.h"
|
||||
#include "app/doc.h"
|
||||
#include "app/doc_api.h"
|
||||
#include "app/script/docobj.h"
|
||||
@ -22,6 +23,8 @@
|
||||
#include "doc/layer.h"
|
||||
#include "doc/layer_tilemap.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "doc/tileset.h"
|
||||
#include "doc/tilesets.h"
|
||||
|
||||
namespace app {
|
||||
namespace script {
|
||||
@ -383,6 +386,27 @@ int Layer_set_parent(lua_State* L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
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()) {
|
||||
Tx tx;
|
||||
tx(new cmd::SetLayerTileset(tilemap, tsi));
|
||||
tx.commit();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg Layer_methods[] = {
|
||||
{ "__eq", Layer_eq },
|
||||
{ "cel", Layer_cel },
|
||||
@ -415,7 +439,7 @@ const Property Layer_properties[] = {
|
||||
{ "color", UserData_get_color<Layer>, UserData_set_color<Layer> },
|
||||
{ "data", UserData_get_text<Layer>, UserData_set_text<Layer> },
|
||||
{ "properties", UserData_get_properties<Layer>, UserData_set_properties<Layer> },
|
||||
{ "tileset", Layer_get_tileset, nullptr },
|
||||
{ "tileset", Layer_get_tileset, Layer_set_tileset },
|
||||
{ nullptr, nullptr, nullptr }
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user