[aseprite] 98/196: New cmdl parameters --range and --shrink-to
Tobias Hansen
thansen at moszumanska.debian.org
Wed Apr 20 18:50:06 UTC 2016
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit 34c1af0a1b21ce870c9ff24a4823b2b36ce7f0e9
Author: Gabriel Rauter <rauter.gabriel at gmail.com>
Date: Wed Mar 23 21:27:35 2016 +0100
New cmdl parameters --range and --shrink-to
--frame-range <from:to> lets the user define a range from frame to frame
instead of a frame tag. example --frame-range "0:1" exports 2 frame. frame 0
and frame 1.
--shrink-to <widthxheight> shrinks the sprite into the boundarys of
width and height keeping the original aspect ratio.
---
src/app/app.cpp | 36 ++++++++++++++++++++++++++++++++++--
src/app/app_options.cpp | 2 ++
src/app/app_options.h | 4 ++++
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/src/app/app.cpp b/src/app/app.cpp
index b91cf37..869542e 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -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;
diff --git a/src/app/app_options.cpp b/src/app/app_options.cpp
index 72fd919..cd5f1a0 100644
--- a/src/app/app_options.cpp
+++ b/src/app/app_options.cpp
@@ -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"))
diff --git a/src/app/app_options.h b/src/app/app_options.h
index 921ccbf..5c0ccc8 100644
--- a/src/app/app_options.h
+++ b/src/app/app_options.h
@@ -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;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list