mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-05 21:57:20 +00:00
lua: Use active cel info in Range when there is no timeline range enabled
With this change we can always use app.range collections (e.g. app.range.editableImages) for our filters in the scripts.
This commit is contained in:
parent
2f76cbe15c
commit
165cd3bdf0
@ -301,7 +301,7 @@ int App_get_range(lua_State* L)
|
||||
app::Context* ctx = App::instance()->context();
|
||||
Site site = ctx->activeSite();
|
||||
if (site.sprite() && App::instance()->timeline()) {
|
||||
push_doc_range(L, site.sprite(), App::instance()->timeline()->range());
|
||||
push_doc_range(L, site, App::instance()->timeline()->range());
|
||||
}
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
|
@ -101,7 +101,7 @@ namespace app {
|
||||
void push_cels(lua_State* L, const doc::ObjectIds& cels);
|
||||
void push_cels(lua_State* L, doc::Layer* layer);
|
||||
void push_cels(lua_State* L, doc::Sprite* sprite);
|
||||
void push_doc_range(lua_State* L, doc::Sprite* sprite, const DocRange& docRange);
|
||||
void push_doc_range(lua_State* L, Site& site, const DocRange& docRange);
|
||||
void push_images(lua_State* L, const doc::ObjectIds& images);
|
||||
void push_layers(lua_State* L, const doc::ObjectIds& layers);
|
||||
void push_sprite_cel(lua_State* L, doc::Cel* cel);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "app/script/docobj.h"
|
||||
#include "app/script/engine.h"
|
||||
#include "app/script/luacpp.h"
|
||||
#include "app/site.h"
|
||||
#include "app/util/range_utils.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/layer.h"
|
||||
@ -34,21 +35,30 @@ struct RangeObj { // This is like DocRange but referencing objects with IDs
|
||||
std::vector<frame_t> frames;
|
||||
std::set<ObjectId> cels;
|
||||
|
||||
RangeObj(Sprite* sprite, const DocRange& docRange) {
|
||||
spriteId = sprite->id();
|
||||
RangeObj(Site& site, const DocRange& docRange) {
|
||||
spriteId = site.sprite()->id();
|
||||
type = docRange.type();
|
||||
for (const Layer* layer : docRange.selectedLayers())
|
||||
layers.insert(layer->id());
|
||||
for (const frame_t frame : docRange.selectedFrames())
|
||||
frames.push_back(frame);
|
||||
|
||||
// TODO improve this, in the best case we should defer layers,
|
||||
// frames, and cels vectors when the properties are accessed, but
|
||||
// it might not be possible because we have to save the IDs of the
|
||||
// objects (and we cannot store the DocRange because it contains
|
||||
// pointers instead of IDs).
|
||||
for (Cel* cel : get_cels(sprite, docRange))
|
||||
cels.insert(cel->id());
|
||||
if (docRange.enabled()) {
|
||||
for (const Layer* layer : docRange.selectedLayers())
|
||||
layers.insert(layer->id());
|
||||
for (const frame_t frame : docRange.selectedFrames())
|
||||
frames.push_back(frame);
|
||||
|
||||
// TODO improve this, in the best case we should defer layers,
|
||||
// frames, and cels vectors when the properties are accessed, but
|
||||
// it might not be possible because we have to save the IDs of the
|
||||
// objects (and we cannot store the DocRange because it contains
|
||||
// pointers instead of IDs).
|
||||
for (Cel* cel : get_cels(site.sprite(), docRange))
|
||||
cels.insert(cel->id());
|
||||
}
|
||||
else {
|
||||
// Put the active frame/layer/cel information in the range
|
||||
frames.push_back(site.frame());
|
||||
if (site.layer()) layers.insert(site.layer()->id());
|
||||
if (site.cel()) cels.insert(site.cel()->id());
|
||||
}
|
||||
}
|
||||
RangeObj(const RangeObj&) = delete;
|
||||
RangeObj& operator=(const RangeObj&) = delete;
|
||||
@ -200,9 +210,9 @@ void register_range_class(lua_State* L)
|
||||
REG_CLASS_PROPERTIES(L, Range);
|
||||
}
|
||||
|
||||
void push_doc_range(lua_State* L, Sprite* sprite, const DocRange& docRange)
|
||||
void push_doc_range(lua_State* L, Site& site, const DocRange& docRange)
|
||||
{
|
||||
push_new<RangeObj>(L, sprite, docRange);
|
||||
push_new<RangeObj>(L, site, docRange);
|
||||
}
|
||||
|
||||
} // namespace script
|
||||
|
Loading…
Reference in New Issue
Block a user