mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-24 12:41:08 +00:00
Convert CliOpenFile::frameRange -> frameFrom/To
This change was done to avoid calling split_string() each time we want to know the frame range. (As the frame range will be used in several parts of the code.)
This commit is contained in:
parent
19a43b27ab
commit
fac2997099
@ -9,6 +9,7 @@
|
|||||||
#define APP_CLI_CLI_OPEN_FILE_H_INCLUDED
|
#define APP_CLI_CLI_OPEN_FILE_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "doc/frame.h"
|
||||||
#include "gfx/rect.h"
|
#include "gfx/rect.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -22,8 +23,8 @@ namespace app {
|
|||||||
std::string filename;
|
std::string filename;
|
||||||
std::string filenameFormat;
|
std::string filenameFormat;
|
||||||
std::string frameTagName;
|
std::string frameTagName;
|
||||||
std::string frameRange;
|
|
||||||
std::string importLayer;
|
std::string importLayer;
|
||||||
|
doc::frame_t frameFrom, frameTo;
|
||||||
bool splitLayers;
|
bool splitLayers;
|
||||||
bool allLayers;
|
bool allLayers;
|
||||||
bool listLayers;
|
bool listLayers;
|
||||||
@ -34,6 +35,8 @@ namespace app {
|
|||||||
|
|
||||||
CliOpenFile() {
|
CliOpenFile() {
|
||||||
document = nullptr;
|
document = nullptr;
|
||||||
|
frameFrom = -1;
|
||||||
|
frameTo = -1;
|
||||||
splitLayers = false;
|
splitLayers = false;
|
||||||
allLayers = false;
|
allLayers = false;
|
||||||
listLayers = false;
|
listLayers = false;
|
||||||
@ -43,6 +46,14 @@ namespace app {
|
|||||||
crop = gfx::Rect();
|
crop = gfx::Rect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasFrameTagName() const {
|
||||||
|
return (!frameTagName.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasFrameRange() const {
|
||||||
|
return (frameFrom >= 0 && frameTo >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
@ -133,7 +133,15 @@ void CliProcessor::process()
|
|||||||
}
|
}
|
||||||
// --frame-range from,to
|
// --frame-range from,to
|
||||||
else if (opt == &m_options.frameRange()) {
|
else if (opt == &m_options.frameRange()) {
|
||||||
cof.frameRange = value.value();
|
std::vector<std::string> splitRange;
|
||||||
|
base::split_string(value.value(), splitRange, ",");
|
||||||
|
if (splitRange.size() < 2)
|
||||||
|
throw std::runtime_error("--frame-range needs two parameters separated by comma (,)\n"
|
||||||
|
"Usage: --frame-range from,to\n"
|
||||||
|
"E.g. --frame-range 0,99");
|
||||||
|
|
||||||
|
cof.frameFrom = base::convert_to<frame_t>(splitRange[0]);
|
||||||
|
cof.frameTo = base::convert_to<frame_t>(splitRange[1]);
|
||||||
}
|
}
|
||||||
// --ignore-empty
|
// --ignore-empty
|
||||||
else if (opt == &m_options.ignoreEmpty()) {
|
else if (opt == &m_options.ignoreEmpty()) {
|
||||||
@ -309,19 +317,11 @@ bool CliProcessor::openFile(CliOpenFile& cof)
|
|||||||
FrameTag* frameTag = nullptr;
|
FrameTag* frameTag = nullptr;
|
||||||
bool isTemporalTag = false;
|
bool isTemporalTag = false;
|
||||||
|
|
||||||
if (!cof.frameTagName.empty()) {
|
if (cof.hasFrameTagName()) {
|
||||||
frameTag = doc->sprite()->frameTags().getByName(cof.frameTagName);
|
frameTag = doc->sprite()->frameTags().getByName(cof.frameTagName);
|
||||||
}
|
}
|
||||||
else if (!cof.frameRange.empty()) {
|
else if (cof.hasFrameRange()) {
|
||||||
std::vector<std::string> splitRange;
|
frameTag = new FrameTag(cof.frameFrom, cof.frameTo);
|
||||||
base::split_string(cof.frameRange, splitRange, ",");
|
|
||||||
if (splitRange.size() < 2)
|
|
||||||
throw std::runtime_error("--frame-range needs two parameters separated by comma (,)\n"
|
|
||||||
"Usage: --frame-range from,to\n"
|
|
||||||
"E.g. --frame-range 0,99");
|
|
||||||
|
|
||||||
frameTag = new FrameTag(base::convert_to<frame_t>(splitRange[0]),
|
|
||||||
base::convert_to<frame_t>(splitRange[1]));
|
|
||||||
isTemporalTag = true;
|
isTemporalTag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user