From 11417c56acfc5c5f4a27f9b23a639ade241632f6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 7 Apr 2022 19:48:39 -0300 Subject: [PATCH] [lua] Add Cel.frame setter to move a cel quickly --- src/app/script/cel_class.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/app/script/cel_class.cpp b/src/app/script/cel_class.cpp index c51327287..37dee013c 100644 --- a/src/app/script/cel_class.cpp +++ b/src/app/script/cel_class.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2018 David Capello // // This program is distributed under the terms of @@ -12,6 +12,7 @@ #include "app/cmd/replace_image.h" #include "app/cmd/set_cel_opacity.h" #include "app/cmd/set_cel_position.h" +#include "app/doc_api.h" #include "app/script/docobj.h" #include "app/script/engine.h" #include "app/script/luacpp.h" @@ -93,6 +94,23 @@ int Cel_get_opacity(lua_State* L) return 1; } +int Cel_set_frame(lua_State* L) +{ + const auto cel = get_docobj(L, 1); + doc::frame_t frame = get_frame_number_from_arg(L, 2); + + if (cel->frame() == frame) + return 0; + + Tx tx; + Doc* doc = static_cast(cel->document()); + DocApi api = doc->getApi(tx); + api.moveCel(cel->layer(), cel->frame(), + cel->layer(), frame); + tx.commit(); + return 0; +} + int Cel_set_image(lua_State* L) { auto cel = get_docobj(L, 1); @@ -134,8 +152,8 @@ const luaL_Reg Cel_methods[] = { const Property Cel_properties[] = { { "sprite", Cel_get_sprite, nullptr }, { "layer", Cel_get_layer, nullptr }, - { "frame", Cel_get_frame, nullptr }, - { "frameNumber", Cel_get_frameNumber, nullptr }, + { "frame", Cel_get_frame, Cel_set_frame }, + { "frameNumber", Cel_get_frameNumber, Cel_set_frame }, { "image", Cel_get_image, Cel_set_image }, { "bounds", Cel_get_bounds, nullptr }, { "position", Cel_get_position, Cel_set_position },