Added cli option --tagname-format

This commit is contained in:
Nathan Pannell 2022-04-29 05:21:49 -07:00 committed by David Capello
parent 8eacee4c98
commit bc9e201255
11 changed files with 71 additions and 1 deletions

View File

@ -529,6 +529,7 @@
<option id="data_filename" type="std::string" />
<option id="data_format" type="SpriteSheetDataFormat" default="SpriteSheetDataFormat::Default" />
<option id="filename_format" type="std::string" />
<option id="tagname_format" type="std::string" />
<option id="border_padding" type="int" default="0" />
<option id="shape_padding" type="int" default="0" />
<option id="inner_padding" type="int" default="0" />

View File

@ -861,6 +861,12 @@ Each frame in the JSON data will contain a filename
how to build each frame. You can use special marks
like {layer}, {frame}, {tag}, {tagframe}, etc.
END
data_tagname_format = Item Tagname:
data_tagname_format_tooltip = <<<END
Each frame tag in the JSON data will have a name
field, formatted with the {filename}, {title},
{path}, {tag}, etc.
END
preview = Preview
open_sprite_sheet = Open Sprite Sheet
export = &Export

View File

@ -135,6 +135,12 @@
tooltip="@.data_filename_format_tooltip" />
<link text="(?)" url="https://www.aseprite.org/docs/cli/#filename-format" />
</hbox>
<hbox id="data_tagname_format_placeholder" cell_hspan="3" cell_align="horizontal">
<label text="@.data_tagname_format" />
<entry id="data_tagname_format" maxsize="1024" maxwidth="256" expansive="true"
tooltip="@.data_tagname_format_tooltip" />
<link text="(?)" url="https://www.aseprite.org/docs/cli/#filename-format" />
</hbox>
</grid>
</panel>

View File

@ -67,6 +67,7 @@ AppOptions::AppOptions(int argc, const char* argv[])
, m_crop(m_po.add("crop").requiresValue("x,y,width,height").description("Crop all the images to the given rectangle"))
, m_slice(m_po.add("slice").requiresValue("<name>").description("Crop the sprite to the given slice area"))
, m_filenameFormat(m_po.add("filename-format").requiresValue("<fmt>").description("Special format to generate filenames"))
, m_tagnameFormat(m_po.add("tagname-format").requiresValue("<fmt>").description("Special format to generate tagnames"))
#ifdef ENABLE_SCRIPTING
, m_script(m_po.add("script").requiresValue("<filename>").description("Execute a specific script"))
, m_scriptParam(m_po.add("script-param").requiresValue("name=value").description("Parameter for a script executed from the\nCLI that you can access with app.params"))

View File

@ -83,6 +83,7 @@ public:
const Option& crop() const { return m_crop; }
const Option& slice() const { return m_slice; }
const Option& filenameFormat() const { return m_filenameFormat; }
const Option& tagnameFormat() const { return m_tagnameFormat; }
#ifdef ENABLE_SCRIPTING
const Option& script() const { return m_script; }
const Option& scriptParam() const { return m_scriptParam; }
@ -152,6 +153,7 @@ private:
Option& m_crop;
Option& m_slice;
Option& m_filenameFormat;
Option& m_tagnameFormat;
#ifdef ENABLE_SCRIPTING
Option& m_script;
Option& m_scriptParam;

View File

@ -24,6 +24,7 @@ namespace app {
Doc* document = nullptr;
std::string filename;
std::string filenameFormat;
std::string tagnameFormat;
std::string tag;
std::string slice;
std::vector<std::string> includeLayers;

View File

@ -390,6 +390,12 @@ int CliProcessor::process(Context* ctx)
if (m_exporter)
m_exporter->setFilenameFormat(cof.filenameFormat);
}
// --tagname-format
else if (opt == &m_options.tagnameFormat()) {
cof.tagnameFormat = value.value();
if (m_exporter)
m_exporter->setTagnameFormat(cof.tagnameFormat);
}
// --save-as <filename>
else if (opt == &m_options.saveAs()) {
if (lastDoc) {

View File

@ -158,6 +158,7 @@ Doc* generate_sprite_sheet_from_params(
const std::string dataFilename = params.dataFilename();
const SpriteSheetDataFormat dataFormat = params.dataFormat();
const std::string filenameFormat = params.filenameFormat();
const std::string tagnameFormat = params.tagnameFormat();
const std::string layerName = params.layer();
const int layerIndex = params.layerIndex();
const std::string tagName = params.tag();
@ -235,6 +236,9 @@ Doc* generate_sprite_sheet_from_params(
if (!filenameFormat.empty())
exporter.setFilenameFormat(filenameFormat);
if (!tagnameFormat.empty())
exporter.setTagnameFormat(tagnameFormat);
exporter.setTextureWidth(width);
exporter.setTextureHeight(height);
exporter.setTextureColumns(columns);
@ -308,6 +312,7 @@ public:
, m_genTimer(100, nullptr)
, m_executionID(0)
, m_filenameFormat(params.filenameFormat())
, m_tagnameFormat(params.tagnameFormat())
{
sectionTabs()->ItemChange.connect([this]{ onChangeSection(); });
expandSections()->Click.connect([this]{ onExpandSections(); });
@ -414,6 +419,7 @@ public:
listSlices()->setSelected(params.listSlices());
updateDefaultDataFilenameFormat();
updateDefaultDataTagnameFormat();
updateDataFields();
std::string base = site.document()->filename();
@ -457,6 +463,7 @@ public:
splitTags()->Click.connect([this]{ onSplitLayersOrFrames(); });
frames()->Change.connect([this]{ generatePreview(); });
dataFilenameFormat()->Change.connect([this]{ onDataFilenameFormatChange(); });
dataTagnameFormat()->Change.connect([this]{ onDataTagnameFormatChange(); });
openGenerated()->Click.connect([this]{ onOpenGeneratedChange(); });
preview()->Click.connect([this]{ generatePreview(); });
m_genTimer.Tick.connect([this]{ onGenTimerTick(); });
@ -525,6 +532,7 @@ public:
params.dataFilename (dataFilenameValue());
params.dataFormat (dataFormatValue());
params.filenameFormat (filenameFormatValue());
params.tagnameFormat (tagnameFormatValue());
params.borderPadding (borderPaddingValue());
params.shapePadding (shapePaddingValue());
params.innerPadding (innerPaddingValue());
@ -666,6 +674,14 @@ private:
return std::string();
}
std::string tagnameFormatValue() const {
if (!m_tagnameFormat.empty() &&
m_tagnameFormat != m_tagnameFormatDefault)
return m_tagnameFormat;
else
return std::string();
}
SpriteSheetDataFormat dataFormatValue() const {
if (dataEnabled()->isSelected())
return SpriteSheetDataFormat(dataFormat()->getSelectedItemIndex());
@ -910,6 +926,7 @@ private:
void onSplitLayersOrFrames() {
updateDefaultDataFilenameFormat();
updateDefaultDataTagnameFormat();
generatePreview();
}
@ -919,6 +936,12 @@ private:
updateDefaultDataFilenameFormat();
}
void onDataTagnameFormatChange() {
m_tagnameFormat = dataTagnameFormat()->text();
if (m_tagnameFormat.empty())
updateDefaultDataTagnameFormat();
}
void onOpenGeneratedChange() {
updateExportButton();
}
@ -950,11 +973,16 @@ private:
}
}
void updateDefaultDataTagnameFormat() {
m_tagnameFormatDefault = "{tag}";
}
void updateDataFields() {
bool state = dataEnabled()->isSelected();
dataFilename()->setVisible(state);
dataMeta()->setVisible(state);
dataFilenameFormatPlaceholder()->setVisible(state);
dataTagnameFormatPlaceholder()->setVisible(state);
}
void onGenTimerTick() {
@ -1142,6 +1170,8 @@ private:
int m_executionID;
std::string m_filenameFormat;
std::string m_filenameFormatDefault;
std::string m_tagnameFormat;
std::string m_tagnameFormatDefault;
};
class ExportSpriteSheetJob : public Job {
@ -1235,6 +1265,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
if (!params.dataFilename.isSet()) params.dataFilename( defPref.spriteSheet.dataFilename());
if (!params.dataFormat.isSet()) params.dataFormat( defPref.spriteSheet.dataFormat());
if (!params.filenameFormat.isSet()) params.filenameFormat( defPref.spriteSheet.filenameFormat());
if (!params.tagnameFormat.isSet()) params.tagnameFormat( defPref.spriteSheet.tagnameFormat());
if (!params.borderPadding.isSet()) params.borderPadding( defPref.spriteSheet.borderPadding());
if (!params.shapePadding.isSet()) params.shapePadding( defPref.spriteSheet.shapePadding());
if (!params.innerPadding.isSet()) params.innerPadding( defPref.spriteSheet.innerPadding());
@ -1283,6 +1314,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
docPref.spriteSheet.dataFilename (params.dataFilename());
docPref.spriteSheet.dataFormat (params.dataFormat());
docPref.spriteSheet.filenameFormat (params.filenameFormat());
docPref.spriteSheet.tagnameFormat (params.tagnameFormat());
docPref.spriteSheet.borderPadding (params.borderPadding());
docPref.spriteSheet.shapePadding (params.shapePadding());
docPref.spriteSheet.innerPadding (params.innerPadding());

View File

@ -29,6 +29,7 @@ struct ExportSpriteSheetParams : public NewParams {
Param<std::string> dataFilename { this, std::string(), "dataFilename" };
Param<SpriteSheetDataFormat> dataFormat { this, SpriteSheetDataFormat::Default, "dataFormat" };
Param<std::string> filenameFormat { this, std::string(), "filenameFormat" };
Param<std::string> tagnameFormat { this, std::string(), "tagnameFormat" };
Param<int> borderPadding { this, 0, "borderPadding" };
Param<int> shapePadding { this, 0, "shapePadding" };
Param<int> innerPadding { this, 0, "innerPadding" };

View File

@ -604,6 +604,7 @@ void DocExporter::reset()
m_dataFilename.clear();
m_textureFilename.clear();
m_filenameFormat.clear();
m_tagnameFormat.clear();
m_textureWidth = 0;
m_textureHeight = 0;
m_textureColumns = 0;
@ -1431,7 +1432,17 @@ void DocExporter::createDataFile(const Samples& samples,
else
os << ",";
os << "\n { \"name\": \"" << escape_for_json(tag->name()) << "\","
std::string format = m_tagnameFormat;
if (format.empty()) {
format = "{tag}";
}
FilenameInfo fnInfo;
fnInfo
.filename(doc->filename())
.innerTagName(tag->name());
std::string tagname = filename_formatter(format, fnInfo);
os << "\n { \"name\": \"" << escape_for_json(tagname) << "\","
<< " \"from\": " << (tag->fromFrame()) << ","
<< " \"to\": " << (tag->toFrame()) << ","
" \"direction\": \"" << escape_for_json(convert_anidir_to_string(tag->aniDir())) << "\"";

View File

@ -52,6 +52,7 @@ namespace app {
const std::string& textureFilename() { return m_textureFilename; }
SpriteSheetType spriteSheetType() { return m_sheetType; }
const std::string& filenameFormat() const { return m_filenameFormat; }
const std::string& tagnameFormat() const { return m_tagnameFormat; }
void setDataFormat(SpriteSheetDataFormat format) { m_dataFormat = format; }
void setDataFilename(const std::string& filename) { m_dataFilename = filename; }
@ -71,6 +72,7 @@ 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 setTagnameFormat(const std::string& format) { m_tagnameFormat = format; }
void setSplitLayers(bool splitLayers) { m_splitLayers = splitLayers; }
void setSplitTags(bool splitTags) { m_splitTags = splitTags; }
void setListTags(bool value) { m_listTags = value; }
@ -160,6 +162,7 @@ namespace app {
std::string m_dataFilename;
std::string m_textureFilename;
std::string m_filenameFormat;
std::string m_tagnameFormat;
int m_textureWidth;
int m_textureHeight;
int m_textureColumns;