mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-24 03:40:14 +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
|
||||
#pragma once
|
||||
|
||||
#include "doc/frame.h"
|
||||
#include "gfx/rect.h"
|
||||
|
||||
#include <string>
|
||||
@ -22,8 +23,8 @@ namespace app {
|
||||
std::string filename;
|
||||
std::string filenameFormat;
|
||||
std::string frameTagName;
|
||||
std::string frameRange;
|
||||
std::string importLayer;
|
||||
doc::frame_t frameFrom, frameTo;
|
||||
bool splitLayers;
|
||||
bool allLayers;
|
||||
bool listLayers;
|
||||
@ -34,6 +35,8 @@ namespace app {
|
||||
|
||||
CliOpenFile() {
|
||||
document = nullptr;
|
||||
frameFrom = -1;
|
||||
frameTo = -1;
|
||||
splitLayers = false;
|
||||
allLayers = false;
|
||||
listLayers = false;
|
||||
@ -43,6 +46,14 @@ namespace app {
|
||||
crop = gfx::Rect();
|
||||
}
|
||||
|
||||
bool hasFrameTagName() const {
|
||||
return (!frameTagName.empty());
|
||||
}
|
||||
|
||||
bool hasFrameRange() const {
|
||||
return (frameFrom >= 0 && frameTo >= 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -133,7 +133,15 @@ void CliProcessor::process()
|
||||
}
|
||||
// --frame-range from,to
|
||||
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
|
||||
else if (opt == &m_options.ignoreEmpty()) {
|
||||
@ -309,19 +317,11 @@ bool CliProcessor::openFile(CliOpenFile& cof)
|
||||
FrameTag* frameTag = nullptr;
|
||||
bool isTemporalTag = false;
|
||||
|
||||
if (!cof.frameTagName.empty()) {
|
||||
if (cof.hasFrameTagName()) {
|
||||
frameTag = doc->sprite()->frameTags().getByName(cof.frameTagName);
|
||||
}
|
||||
else if (!cof.frameRange.empty()) {
|
||||
std::vector<std::string> splitRange;
|
||||
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]));
|
||||
else if (cof.hasFrameRange()) {
|
||||
frameTag = new FrameTag(cof.frameFrom, cof.frameTo);
|
||||
isTemporalTag = true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user