mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 12:32:52 +00:00
Merge branch range-and-shrink-command-line-options
# Conflicts: # third_party/libpng # third_party/zlib
This commit is contained in:
commit
c6482da761
@ -53,6 +53,7 @@
|
||||
#include "app/ui_context.h"
|
||||
#include "app/util/clipboard.h"
|
||||
#include "app/webserver.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "base/exception.h"
|
||||
#include "base/fs.h"
|
||||
#include "base/path.h"
|
||||
@ -253,6 +254,7 @@ void App::initialize(const AppOptions& options)
|
||||
std::string importLayerSaveAs;
|
||||
std::string filenameFormat;
|
||||
std::string frameTagName;
|
||||
std::string frameRange;
|
||||
|
||||
for (const auto& value : options.values()) {
|
||||
const AppOptions::Option* opt = value.option();
|
||||
@ -327,6 +329,10 @@ void App::initialize(const AppOptions& options)
|
||||
else if (opt == &options.frameTag()) {
|
||||
frameTagName = value.value();
|
||||
}
|
||||
// --frame-range <range>
|
||||
else if (opt == &options.frameRange()) {
|
||||
frameRange = value.value();
|
||||
}
|
||||
// --ignore-empty
|
||||
else if (opt == &options.ignoreEmpty()) {
|
||||
ignoreEmpty = true;
|
||||
@ -489,6 +495,27 @@ void App::initialize(const AppOptions& options)
|
||||
ctx->executeCommand(command);
|
||||
}
|
||||
}
|
||||
// --shrink-to <widthxheight>
|
||||
else if (opt == &options.shrinkTo()) {
|
||||
std::vector<std::string> dimensions;
|
||||
base::split_string(value.value(), dimensions, "x");
|
||||
double maxWidth = base::convert_to<double>(dimensions.at(0));
|
||||
double maxHeight = base::convert_to<double>(dimensions.at(1));
|
||||
double scaleWidth, scaleHeight, scale;
|
||||
|
||||
// Shrink all sprites if needed
|
||||
for (auto doc : ctx->documents()) {
|
||||
ctx->setActiveDocument(static_cast<app::Document*>(doc));
|
||||
scaleWidth = doc->width() > maxWidth ? maxWidth / doc->width() : 1.0;
|
||||
scaleHeight = doc->height() > maxHeight ? maxHeight / doc->height() : 1.0;
|
||||
if (scaleWidth < 1.0 || scaleHeight < 1.0) {
|
||||
scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight;
|
||||
Command* command = CommandsModule::instance()->getCommandByName(CommandId::SpriteSize);
|
||||
static_cast<SpriteSizeCommand*>(command)->setScale(scale, scale);
|
||||
ctx->executeCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
// --script <filename>
|
||||
else if (opt == &options.script()) {
|
||||
std::string script = value.value();
|
||||
@ -549,11 +576,16 @@ void App::initialize(const AppOptions& options)
|
||||
for (FrameTag* tag : doc->sprite()->frameTags())
|
||||
std::cout << tag->name() << "\n";
|
||||
}
|
||||
|
||||
if (m_exporter) {
|
||||
FrameTag* frameTag = nullptr;
|
||||
if (!frameTagName.empty())
|
||||
if (!frameTagName.empty()) {
|
||||
frameTag = doc->sprite()->frameTags().getByName(frameTagName);
|
||||
} else if (!frameRange.empty()) {
|
||||
std::vector<std::string> splitRange;
|
||||
base::split_string(frameRange, splitRange, ":");
|
||||
frameTag = new FrameTag(base::convert_to<frame_t>(splitRange.at(0)),
|
||||
base::convert_to<frame_t>(splitRange.at(1)));
|
||||
}
|
||||
|
||||
if (!importLayer.empty()) {
|
||||
Layer* foundLayer = NULL;
|
||||
|
@ -30,6 +30,7 @@ AppOptions::AppOptions(int argc, const char* argv[])
|
||||
, m_batch(m_po.add("batch").mnemonic('b').description("Do not start the UI"))
|
||||
, m_saveAs(m_po.add("save-as").requiresValue("<filename>").description("Save the last given document with other format"))
|
||||
, m_scale(m_po.add("scale").requiresValue("<factor>").description("Resize all previous opened documents"))
|
||||
, m_shrinkTo(m_po.add("shrink-to").requiresValue("<widthxheight>").description("Shrink to size if the Sprite is larger than width or height"))
|
||||
, m_data(m_po.add("data").requiresValue("<filename.json>").description("File to store the sprite sheet metadata"))
|
||||
, m_format(m_po.add("format").requiresValue("<format>").description("Format to export the data file (json-hash, json-array)"))
|
||||
, m_sheet(m_po.add("sheet").requiresValue("<filename.png>").description("Image file to save the texture"))
|
||||
@ -41,6 +42,7 @@ AppOptions::AppOptions(int argc, const char* argv[])
|
||||
, m_layer(m_po.add("layer").alias("import-layer").requiresValue("<name>").description("Include just the given layer in the sheet"))
|
||||
, m_allLayers(m_po.add("all-layers").description("Make all layers visible\nBy default hidden layers will be ignored"))
|
||||
, m_frameTag(m_po.add("frame-tag").requiresValue("<name>").description("Include tagged frames in the sheet"))
|
||||
, m_frameRange(m_po.add("frame-range").requiresValue("<from:to>").description("Include frames from:to in the sheet"))
|
||||
, m_ignoreEmpty(m_po.add("ignore-empty").description("Do not export empty frames/cels"))
|
||||
, m_borderPadding(m_po.add("border-padding").requiresValue("<value>").description("Add padding on the texture borders"))
|
||||
, m_shapePadding(m_po.add("shape-padding").requiresValue("<value>").description("Add padding between frames"))
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
// Export options
|
||||
const Option& saveAs() const { return m_saveAs; }
|
||||
const Option& scale() const { return m_scale; }
|
||||
const Option& shrinkTo() const { return m_shrinkTo; }
|
||||
const Option& data() const { return m_data; }
|
||||
const Option& format() const { return m_format; }
|
||||
const Option& sheet() const { return m_sheet; }
|
||||
@ -55,6 +56,7 @@ public:
|
||||
const Option& layer() const { return m_layer; }
|
||||
const Option& allLayers() const { return m_allLayers; }
|
||||
const Option& frameTag() const { return m_frameTag; }
|
||||
const Option& frameRange() const { return m_frameRange; }
|
||||
const Option& ignoreEmpty() const { return m_ignoreEmpty; }
|
||||
const Option& borderPadding() const { return m_borderPadding; }
|
||||
const Option& shapePadding() const { return m_shapePadding; }
|
||||
@ -84,6 +86,7 @@ private:
|
||||
Option& m_batch;
|
||||
Option& m_saveAs;
|
||||
Option& m_scale;
|
||||
Option& m_shrinkTo;
|
||||
Option& m_data;
|
||||
Option& m_format;
|
||||
Option& m_sheet;
|
||||
@ -95,6 +98,7 @@ private:
|
||||
Option& m_layer;
|
||||
Option& m_allLayers;
|
||||
Option& m_frameTag;
|
||||
Option& m_frameRange;
|
||||
Option& m_ignoreEmpty;
|
||||
Option& m_borderPadding;
|
||||
Option& m_shapePadding;
|
||||
|
Loading…
x
Reference in New Issue
Block a user