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