Split layers/tags explicitly on export sprite sheet when the options to split layers/tags are used

This is mainly useful when we want to include the "{tag}" in the JSON
data but we don't want to split tags in the sprite sheet
layout (e.g. using a fixed # of rows in "By Rows" sprite sheet type
without breaking rows when the tag change between a couple of
samples).
This commit is contained in:
David Capello 2019-10-24 08:55:11 -03:00
parent 446e7055e9
commit 926accf7c7
4 changed files with 27 additions and 9 deletions

View File

@ -258,10 +258,14 @@ void CliProcessor::process(Context* ctx)
// --split-layers
else if (opt == &m_options.splitLayers()) {
cof.splitLayers = true;
if (m_exporter)
m_exporter->setSplitLayers(true);
}
// --split-tags
else if (opt == &m_options.splitTags()) {
cof.splitTags = true;
if (m_exporter)
m_exporter->setSplitTags(true);
}
// --split-slice
else if (opt == &m_options.splitSlices()) {

View File

@ -238,6 +238,8 @@ void update_doc_exporter_from_params(DocExporter& exporter,
exporter.setTrimCels(trimCels);
exporter.setTrimByGrid(trimByGrid);
exporter.setExtrude(extrude);
exporter.setSplitLayers(splitLayers);
exporter.setSplitTags(splitTags);
exporter.setIgnoreEmptyCels(ignoreEmpty);
exporter.setMergeDuplicates(mergeDuplicates);
if (listLayers) exporter.setListLayers(true);

View File

@ -353,10 +353,13 @@ public:
class DocExporter::SimpleLayoutSamples : public DocExporter::LayoutSamples {
public:
SimpleLayoutSamples(SpriteSheetType type,
int maxCols, int maxRows)
int maxCols, int maxRows,
bool splitLayers, bool splitTags)
: m_type(type)
, m_maxCols(maxCols)
, m_maxRows(maxRows) {
, m_maxRows(maxRows)
, m_splitLayers(splitLayers)
, m_splitTags(splitTags) {
}
void layoutSamples(Samples& samples,
@ -410,10 +413,10 @@ public:
if (breakBands && oldSprite) {
const bool nextBand =
(oldSprite != sprite ||
oldLayer != layer ||
oldTag != tag ||
itemInBand == itemsPerBand);
((oldSprite != sprite) ||
(m_splitLayers && oldLayer != layer) ||
(m_splitTags && oldTag != tag) ||
(itemInBand == itemsPerBand));
if (m_type == SpriteSheetType::Columns) {
// If the user didn't specify a height for the texture, we
@ -490,6 +493,8 @@ private:
SpriteSheetType m_type;
int m_maxCols;
int m_maxRows;
bool m_splitLayers;
bool m_splitTags;
};
class DocExporter::BestFitLayoutSamples : public DocExporter::LayoutSamples {
@ -585,6 +590,8 @@ void DocExporter::reset()
m_trimCels = false;
m_trimByGrid = false;
m_extrude = false;
m_splitLayers = false;
m_splitTags = false;
m_listTags = false;
m_listLayers = false;
m_listSlices = false;
@ -874,8 +881,7 @@ void DocExporter::captureSamples(Samples& samples,
std::string filename = filename_formatter(format, fnInfo);
Sample sample(
doc, sprite, item.selLayers, frame,
(innerTag && is_tag_in_filename_format(format) ? innerTag: nullptr),
doc, sprite, item.selLayers, frame, innerTag,
filename, m_innerPadding, m_extrude);
Cel* cel = nullptr;
Cel* link = nullptr;
@ -1006,7 +1012,9 @@ void DocExporter::layoutSamples(Samples& samples,
}
default: {
SimpleLayoutSamples layout(
m_sheetType, m_textureColumns, m_textureRows);
m_sheetType,
m_textureColumns, m_textureRows,
m_splitLayers, m_splitTags);
layout.layoutSamples(
samples, m_borderPadding, m_shapePadding,
width, height, token);

View File

@ -70,6 +70,8 @@ namespace app {
void setTrimByGrid(bool trimByGrid) { m_trimByGrid = trimByGrid; }
void setExtrude(bool extrude) { m_extrude = extrude; }
void setFilenameFormat(const std::string& format) { m_filenameFormat = format; }
void setSplitLayers(bool splitLayers) { m_splitLayers = splitLayers; }
void setSplitTags(bool splitTags) { m_splitTags = splitTags; }
void setListTags(bool value) { m_listTags = value; }
void setListLayers(bool value) { m_listLayers = value; }
void setListSlices(bool value) { m_listSlices = value; }
@ -155,6 +157,8 @@ namespace app {
bool m_trimCels;
bool m_trimByGrid;
bool m_extrude;
bool m_splitLayers;
bool m_splitTags;
bool m_listTags;
bool m_listLayers;
bool m_listSlices;