Merge pull request #3682 from aseprite/tile-set-image

[lua] Add Tile_set_image method
This commit is contained in:
Martín Capello 2023-01-27 10:01:25 -03:00 committed by GitHub
commit 45ce79e594
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@
#include "config.h"
#endif
#include "app/cmd/replace_image.h"
#include "app/cmd/set_tile_data.h"
#include "app/cmd/set_tile_data_properties.h"
#include "app/script/docobj.h"
@ -55,6 +56,23 @@ int Tile_get_image(lua_State* L)
return 1;
}
int Tile_set_image(lua_State* L)
{
auto tile = get_obj<Tile>(L, 1);
auto ts = doc::get<Tileset>(tile->id);
auto srcImage = get_image_from_arg(L, 2);
ImageRef newImage(Image::createCopy(srcImage));
if (ts && ts->sprite()) {
Tx tx;
tx(new cmd::ReplaceImage(ts->sprite(),
ts->get(tile->ti),
newImage));
tx.commit();
}
return 0;
}
int Tile_get_data(lua_State* L)
{
auto tile = get_obj<Tile>(L, 1);
@ -173,7 +191,7 @@ const luaL_Reg Tile_methods[] = {
const Property Tile_properties[] = {
{ "index", Tile_get_index, nullptr },
{ "image", Tile_get_image, nullptr }, // TODO Tile_set_image
{ "image", Tile_get_image, Tile_set_image },
{ "data", Tile_get_data, Tile_set_data },
{ "color", Tile_get_color, Tile_set_color },
{ "properties", Tile_get_properties, Tile_set_properties },