Update save-as option to use format elements (#2442)

This commit is contained in:
anGie44 2020-09-10 18:18:37 -04:00 committed by David Capello
parent 822a309724
commit 4dc579c386
3 changed files with 47 additions and 19 deletions

View File

@ -401,29 +401,31 @@ int CliProcessor::process(Context* ctx)
if (lastDoc) {
std::string fn = value.value();
// Automatic --split-layer, --split-tags, --split-slices
// in case the output filename already contains {layer},
// {tag}, or {slice} template elements.
bool hasLayerTemplate = (is_layer_in_filename_format(fn) ||
is_group_in_filename_format(fn));
bool hasTagTemplate = is_tag_in_filename_format(fn);
bool hasSliceTemplate = is_slice_in_filename_format(fn);
// Automatic --filename-format
// in case the output filename already contains template elements.
bool hasTemplateElement = is_template_in_filename(fn);
if (hasLayerTemplate || hasTagTemplate || hasSliceTemplate) {
cof.splitLayers = (cof.splitLayers || hasLayerTemplate);
cof.splitTags = (cof.splitTags || hasTagTemplate);
cof.splitSlices = (cof.splitSlices || hasSliceTemplate);
cof.filenameFormat =
get_default_filename_format(
fn,
true, // With path
(lastDoc->sprite()->totalFrames() > 1), // Has frames
false, // Has layer
false); // Has frame tag
if (hasTemplateElement) {
cof.filenameFormat = fn;
// Automatic --split-layer, --split-tags, --split-slices
// in case the output filename already contains {layer},
// {tag}, or {slice} template elements.
bool hasLayerTemplate = (is_layer_in_filename_format(fn) ||
is_group_in_filename_format(fn));
bool hasTagTemplate = is_tag_in_filename_format(fn);
bool hasSliceTemplate = is_slice_in_filename_format(fn);
if (hasLayerTemplate || hasTagTemplate || hasSliceTemplate) {
cof.splitLayers = (cof.splitLayers || hasLayerTemplate);
cof.splitTags = (cof.splitTags || hasTagTemplate);
cof.splitSlices = (cof.splitSlices || hasSliceTemplate);
}
}
else {
cof.filename = fn;
}
cof.document = lastDoc;
cof.filename = fn;
saveFile(ctx, cof);
}
else

View File

@ -74,6 +74,29 @@ bool get_frame_info_from_filename_format(
return false;
}
bool is_template_in_filename(const std::string& format)
{
std::vector<std::string> formats{
"{fullname}",
"{path}",
"{name}",
"{title}",
"{extension}",
"{layer}",
"{tag}",
"{innertag}",
"{outertag}",
"{frame}",
"{tagframe}"
};
for (int i = 0; i < formats.size(); i++) {
if (format.find(formats[i]) != std::string::npos) {
return true;
}
}
return false;
}
bool is_tag_in_filename_format(const std::string& format)
{
return (format.find("{tag}") != std::string::npos);

View File

@ -87,6 +87,9 @@ namespace app {
bool get_frame_info_from_filename_format(
const std::string& format, int* startFrom, int* width);
// Returns true if the given filename contains a format element
bool is_template_in_filename(const std::string& format);
// Returns true if the given filename format contains {tag}, {layer} or {group}
bool is_tag_in_filename_format(const std::string& format);
bool is_layer_in_filename_format(const std::string& format);