1 // Aseprite 2 // Copyright (C) 2001-2017 David Capello 3 // 4 // This program is distributed under the terms of 5 // the End-User License Agreement for Aseprite. 6 7 #ifndef APP_FILENAME_FORMATTER_H_INCLUDED 8 #define APP_FILENAME_FORMATTER_H_INCLUDED 9 #pragma once 10 11 #include <string> 12 13 namespace app { 14 15 class FilenameInfo { 16 public: FilenameInfo()17 FilenameInfo() : m_frame(-1), m_tagFrame(-1) { } 18 filename()19 const std::string& filename() const { return m_filename; } layerName()20 const std::string& layerName() const { return m_layerName; } groupName()21 const std::string& groupName() const { return m_groupName; } innerTagName()22 const std::string& innerTagName() const { return m_innerTagName; } outerTagName()23 const std::string& outerTagName() const { return m_outerTagName; } sliceName()24 const std::string& sliceName() const { return m_sliceName; } frame()25 int frame() const { return m_frame; } tagFrame()26 int tagFrame() const { return m_tagFrame; } 27 filename(const std::string & value)28 FilenameInfo& filename(const std::string& value) { 29 m_filename = value; 30 return *this; 31 } 32 layerName(const std::string & value)33 FilenameInfo& layerName(const std::string& value) { 34 m_layerName = value; 35 return *this; 36 } 37 groupName(const std::string & value)38 FilenameInfo& groupName(const std::string& value) { 39 m_groupName = value; 40 return *this; 41 } 42 innerTagName(const std::string & value)43 FilenameInfo& innerTagName(const std::string& value) { 44 m_innerTagName = value; 45 return *this; 46 } 47 outerTagName(const std::string & value)48 FilenameInfo& outerTagName(const std::string& value) { 49 m_outerTagName = value; 50 return *this; 51 } 52 sliceName(const std::string & value)53 FilenameInfo& sliceName(const std::string& value) { 54 m_sliceName = value; 55 return *this; 56 } 57 frame(int value)58 FilenameInfo& frame(int value) { 59 m_frame = value; 60 return *this; 61 } 62 tagFrame(int value)63 FilenameInfo& tagFrame(int value) { 64 m_tagFrame = value; 65 return *this; 66 } 67 68 private: 69 std::string m_filename; 70 std::string m_layerName; 71 std::string m_groupName; 72 std::string m_innerTagName; 73 std::string m_outerTagName; 74 std::string m_sliceName; 75 int m_frame; 76 int m_tagFrame; 77 }; 78 79 // Returns the information inside {frame} tag. 80 // E.g. For {frame001} returns width=3 and startFrom=1 81 bool get_frame_info_from_filename_format( 82 const std::string& format, int* startFrom, int* width); 83 84 // Returns true if the given filename format contains {tag}, {layer} or {group} 85 bool is_tag_in_filename_format(const std::string& format); 86 bool is_layer_in_filename_format(const std::string& format); 87 bool is_group_in_filename_format(const std::string& format); 88 bool is_slice_in_filename_format(const std::string& format); 89 90 // If "replaceFrame" is false, this function doesn't replace all the 91 // information that depends on the current frame ({frame}, 92 // {tagframe}, {tag}, etc.) 93 std::string filename_formatter( 94 const std::string& format, 95 FilenameInfo& info, 96 const bool replaceFrame = true); 97 98 std::string get_default_filename_format( 99 std::string& filename, 100 const bool withPath, 101 const bool hasFrames, 102 const bool hasLayer, 103 const bool hasFrameTag); 104 105 std::string get_default_filename_format_for_sheet( 106 const std::string& filename, 107 const bool hasFrames, 108 const bool hasLayer, 109 const bool hasFrameTag); 110 111 } // namespace app 112 113 #endif 114