diff --git a/src/app/script/tile_class.cpp b/src/app/script/tile_class.cpp index 2299296f7..7db7f5660 100644 --- a/src/app/script/tile_class.cpp +++ b/src/app/script/tile_class.cpp @@ -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(L, 1); + auto ts = doc::get(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(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 },