diff --git a/src/app/app.cpp b/src/app/app.cpp index cddcae106..b34856524 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -214,7 +214,9 @@ void App::initialize(int argc, const char* argv[]) if (!options.values().empty()) { Console console; bool splitLayers = false; + bool splitLayersSaveAs = false; std::string importLayer; + std::string importLayerSaveAs; for (const auto& value : options.values()) { const AppOptions::Option* opt = value.option(); @@ -249,10 +251,12 @@ void App::initialize(int argc, const char* argv[]) // --split-layers else if (opt == &options.splitLayers()) { splitLayers = true; + splitLayersSaveAs = true; } // --import-layer else if (opt == &options.importLayer()) { importLayer = value.value(); + importLayerSaveAs = value.value(); } // --save-as else if (opt == &options.saveAs()) { @@ -267,8 +271,44 @@ void App::initialize(int argc, const char* argv[]) ctx->setActiveDocument(doc); Command* command = CommandsModule::instance()->getCommandByName(CommandId::SaveFileCopyAs); - static_cast(command)->setFilename(value.value()); - ctx->executeCommand(command); + if (splitLayersSaveAs) { + std::vector layers; + doc->sprite()->getLayersList(layers); + + // For each layer, hide other ones and save the sprite. + for (Layer* show : layers) { + for (Layer* hide : layers) + hide->setReadable(hide == show); + + std::string frameStr; + if (doc->sprite()->totalFrames() > FrameNumber(1)) + frameStr += " 1"; + + std::string fn = value.value(); + fn = + base::join_path( + base::get_file_path(fn), + base::get_file_title(fn)) + + " (" + show->name() + ")" + frameStr + "." + + base::get_file_extension(fn); + + static_cast(command)->setFilename(fn); + ctx->executeCommand(command); + } + } + else { + std::vector layers; + doc->sprite()->getLayersList(layers); + + // Show only one layer + if (!importLayerSaveAs.empty()) { + for (Layer* layer : layers) + layer->setReadable(layer->name() == importLayerSaveAs); + } + + static_cast(command)->setFilename(value.value()); + ctx->executeCommand(command); + } } } // --scale @@ -304,8 +344,9 @@ void App::initialize(int argc, const char* argv[]) if (m_exporter != NULL) { if (!importLayer.empty()) { std::vector layers; - Layer* foundLayer = NULL; doc->sprite()->getLayersList(layers); + + Layer* foundLayer = NULL; for (Layer* layer : layers) { if (layer->name() == importLayer) { foundLayer = layer; diff --git a/src/app/document_exporter.cpp b/src/app/document_exporter.cpp index 0443a9973..ca1a153d9 100644 --- a/src/app/document_exporter.cpp +++ b/src/app/document_exporter.cpp @@ -27,6 +27,7 @@ #include "app/document_api.h" #include "app/file/file.h" #include "app/ui_context.h" +#include "base/convert_to.h" #include "base/path.h" #include "base/unique_ptr.h" #include "doc/cel.h" @@ -275,21 +276,17 @@ void DocumentExporter::captureSamples(Samples& samples) std::string filename = doc->filename(); if (sprite->totalFrames() > FrameNumber(1)) { - int frameNumWidth = - (sprite->totalFrames() < 10)? 1: - (sprite->totalFrames() < 100)? 2: - (sprite->totalFrames() < 1000)? 3: 4; - std::sprintf(&buf[0], "%0*d", frameNumWidth, (int)frame); - std::string path = base::get_file_path(filename); std::string title = base::get_file_title(filename); if (layer) { - title += "-"; + title += " ("; title += layer->name(); + title += ") "; } - std::string ext = base::get_file_extension(filename); - filename = base::join_path(path, title + &buf[0] + "." + ext); + filename = base::join_path(path, title + + base::convert_to((int)frame + 1) + + "." + base::get_file_extension(filename)); } samples.addSample(Sample(doc, sprite, layer, frame, filename)); diff --git a/src/app/file/file.cpp b/src/app/file/file.cpp index cc4868218..a91186fdb 100644 --- a/src/app/file/file.cpp +++ b/src/app/file/file.cpp @@ -369,11 +369,8 @@ FileOp* fop_to_save_document(Context* context, Document* document) start_from = split_filename(fop->document->filename().c_str(), left, right, width); if (start_from < 0) { - start_from = 0; - width = - (fop->document->sprite()->totalFrames() < 10)? 1: - (fop->document->sprite()->totalFrames() < 100)? 2: - (fop->document->sprite()->totalFrames() < 1000)? 3: 4; + start_from = 1; + width = 1; } for (FrameNumber frame(0); framedocument->sprite()->totalFrames(); ++frame) {