mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Merge branch 'master'
This commit is contained in:
commit
ab0c447be4
@ -435,7 +435,9 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context,
|
||||
.filename(fn)
|
||||
.innerTagName(innerTag ? innerTag->name(): "")
|
||||
.outerTagName(outerTag ? outerTag->name(): "")
|
||||
.frame(start_from+frame);
|
||||
.frame(start_from+frame)
|
||||
.tagFrame(innerTag ? frame-innerTag->fromFrame():
|
||||
start_from+frame);
|
||||
|
||||
std::string frame_fn =
|
||||
filename_formatter(fn_format, fnInfo);
|
||||
|
@ -16,10 +16,38 @@
|
||||
#include "base/replace_string.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace app {
|
||||
|
||||
static bool replace_frame(const char* frameKey, // E.g. = "{frame"
|
||||
int frameBase,
|
||||
std::string& str)
|
||||
{
|
||||
size_t i = str.find(frameKey);
|
||||
if (i != std::string::npos) {
|
||||
int keyLen = std::strlen(frameKey);
|
||||
|
||||
size_t j = str.find("}", i+keyLen);
|
||||
if (j != std::string::npos) {
|
||||
std::string from = str.substr(i, j - i + 1);
|
||||
if (frameBase >= 0) {
|
||||
std::vector<char> to(32);
|
||||
int offset = std::strtol(from.c_str()+keyLen, NULL, 10);
|
||||
|
||||
std::sprintf(&to[0], "%0*d", (int(j)-int(i+keyLen)), frameBase + offset);
|
||||
base::replace_string(str, from, &to[0]);
|
||||
}
|
||||
else
|
||||
base::replace_string(str, from, "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string filename_formatter(
|
||||
const std::string& format,
|
||||
FilenameInfo& info,
|
||||
@ -37,27 +65,13 @@ std::string filename_formatter(
|
||||
base::replace_string(output, "{title}", base::get_file_title(filename));
|
||||
base::replace_string(output, "{extension}", base::get_file_extension(filename));
|
||||
base::replace_string(output, "{layer}", info.layerName());
|
||||
base::replace_string(output, "{tag}", info.innerTagName());
|
||||
base::replace_string(output, "{innertag}", info.innerTagName());
|
||||
base::replace_string(output, "{outertag}", info.outerTagName());
|
||||
|
||||
if (replaceFrame) {
|
||||
size_t i = output.find("{frame");
|
||||
if (i != std::string::npos) {
|
||||
size_t j = output.find("}", i+6);
|
||||
if (j != std::string::npos) {
|
||||
std::string from = output.substr(i, j - i + 1);
|
||||
if (info.frame() >= 0) {
|
||||
std::vector<char> to(32);
|
||||
int offset = std::strtol(from.c_str()+6, NULL, 10);
|
||||
|
||||
std::sprintf(&to[0], "%0*d", (int(j)-int(i+6)), info.frame() + offset);
|
||||
base::replace_string(output, from, &to[0]);
|
||||
}
|
||||
else
|
||||
base::replace_string(output, from, "");
|
||||
}
|
||||
}
|
||||
base::replace_string(output, "{tag}", info.innerTagName());
|
||||
base::replace_string(output, "{innertag}", info.innerTagName());
|
||||
base::replace_string(output, "{outertag}", info.outerTagName());
|
||||
replace_frame("{frame", info.frame(), output);
|
||||
replace_frame("{tagframe", info.tagFrame(), output);
|
||||
}
|
||||
|
||||
return output;
|
||||
@ -87,7 +101,9 @@ std::string add_frame_format(
|
||||
std::string output = format;
|
||||
|
||||
size_t i = output.find("{frame");
|
||||
if (i == std::string::npos) {
|
||||
size_t j = output.find("{tagframe");
|
||||
if (i == std::string::npos &&
|
||||
j == std::string::npos) {
|
||||
output =
|
||||
base::join_path(
|
||||
base::get_file_path(format),
|
||||
|
@ -15,13 +15,14 @@ namespace app {
|
||||
|
||||
class FilenameInfo {
|
||||
public:
|
||||
FilenameInfo() : m_frame(-1) { }
|
||||
FilenameInfo() : m_frame(-1), m_tagFrame(-1) { }
|
||||
|
||||
const std::string& filename() const { return m_filename; }
|
||||
const std::string& layerName() const { return m_layerName; }
|
||||
const std::string& innerTagName() const { return m_innerTagName; }
|
||||
const std::string& outerTagName() const { return m_outerTagName; }
|
||||
int frame() const { return m_frame; }
|
||||
int tagFrame() const { return m_tagFrame; }
|
||||
|
||||
FilenameInfo& filename(const std::string& value) {
|
||||
m_filename = value;
|
||||
@ -48,14 +49,23 @@ namespace app {
|
||||
return *this;
|
||||
}
|
||||
|
||||
FilenameInfo& tagFrame(int value) {
|
||||
m_tagFrame = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_filename;
|
||||
std::string m_layerName;
|
||||
std::string m_innerTagName;
|
||||
std::string m_outerTagName;
|
||||
int m_frame;
|
||||
int m_tagFrame;
|
||||
};
|
||||
|
||||
// If "replaceFrame" is false, this function doesn't replace all the
|
||||
// information that depends on the current frame ({frame},
|
||||
// {tagframe}, {tag}, etc.)
|
||||
std::string filename_formatter(
|
||||
const std::string& format,
|
||||
FilenameInfo& info,
|
||||
|
@ -165,3 +165,24 @@ TEST(AddFrameFormat, Tests)
|
||||
"{path}/{title}{frame1}.{extension}",
|
||||
"{frame001}"));
|
||||
}
|
||||
|
||||
TEST(FilenameFormatter, WithTagFrame)
|
||||
{
|
||||
EXPECT_EQ(
|
||||
"./file_2_0.png",
|
||||
filename_formatter(
|
||||
"{path}/{title}_{frame}_{tagframe}.{extension}",
|
||||
FilenameInfo().filename("./file.png").frame(2).tagFrame(0)));
|
||||
|
||||
EXPECT_EQ(
|
||||
"./file_2_1.png",
|
||||
filename_formatter(
|
||||
"{path}/{title}_{frame}_{tagframe1}.{extension}",
|
||||
FilenameInfo().filename("./file.png").frame(2).tagFrame(0)));
|
||||
|
||||
EXPECT_EQ(
|
||||
"./file_2_25.png",
|
||||
filename_formatter(
|
||||
"{path}/{title}_{frame}_{tagframe24}.{extension}",
|
||||
FilenameInfo().filename("./file.png").frame(2).tagFrame(1)));
|
||||
}
|
||||
|
@ -195,6 +195,7 @@ Editor::Editor(Document* document, EditorFlags flags)
|
||||
m_tiledConn = docPref.tiled.AfterChange.connect(base::Bind<void>(&Editor::invalidate, this));
|
||||
m_gridConn = docPref.grid.AfterChange.connect(base::Bind<void>(&Editor::invalidate, this));
|
||||
m_pixelGridConn = docPref.pixelGrid.AfterChange.connect(base::Bind<void>(&Editor::invalidate, this));
|
||||
m_bgConn = docPref.bg.AfterChange.connect(base::Bind<void>(&Editor::invalidate, this));
|
||||
m_onionskinConn = docPref.onionskin.AfterChange.connect(base::Bind<void>(&Editor::invalidate, this));
|
||||
|
||||
m_document->addObserver(this);
|
||||
|
@ -296,6 +296,7 @@ namespace app {
|
||||
base::ScopedConnection m_tiledConn;
|
||||
base::ScopedConnection m_gridConn;
|
||||
base::ScopedConnection m_pixelGridConn;
|
||||
base::ScopedConnection m_bgConn;
|
||||
base::ScopedConnection m_onionskinConn;
|
||||
|
||||
EditorObservers m_observers;
|
||||
|
Loading…
x
Reference in New Issue
Block a user