Merge branch '1.0'

This commit is contained in:
David Capello 2014-11-09 20:12:57 -03:00
commit 1ed34660e4
3 changed files with 52 additions and 17 deletions

View File

@ -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 <layer-name>
else if (opt == &options.importLayer()) {
importLayer = value.value();
importLayerSaveAs = value.value();
}
// --save-as <filename>
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<SaveFileBaseCommand*>(command)->setFilename(value.value());
ctx->executeCommand(command);
if (splitLayersSaveAs) {
std::vector<Layer*> 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<SaveFileBaseCommand*>(command)->setFilename(fn);
ctx->executeCommand(command);
}
}
else {
std::vector<Layer*> layers;
doc->sprite()->getLayersList(layers);
// Show only one layer
if (!importLayerSaveAs.empty()) {
for (Layer* layer : layers)
layer->setReadable(layer->name() == importLayerSaveAs);
}
static_cast<SaveFileBaseCommand*>(command)->setFilename(value.value());
ctx->executeCommand(command);
}
}
}
// --scale <factor>
@ -304,8 +344,9 @@ void App::initialize(int argc, const char* argv[])
if (m_exporter != NULL) {
if (!importLayer.empty()) {
std::vector<Layer*> layers;
Layer* foundLayer = NULL;
doc->sprite()->getLayersList(layers);
Layer* foundLayer = NULL;
for (Layer* layer : layers) {
if (layer->name() == importLayer) {
foundLayer = layer;

View File

@ -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<std::string>((int)frame + 1)
+ "." + base::get_file_extension(filename));
}
samples.addSample(Sample(doc, sprite, layer, frame, filename));

View File

@ -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); frame<fop->document->sprite()->totalFrames(); ++frame) {