| 1 | // Aseprite |
| 2 | // Copyright (C) 2019-2020 Igara Studio S.A. |
| 3 | // Copyright (C) 2016-2018 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifndef APP_APP_CLI_PROCESSOR_H_INCLUDED |
| 9 | #define APP_APP_CLI_PROCESSOR_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/cli/cli_delegate.h" |
| 13 | #include "app/cli/cli_open_file.h" |
| 14 | #include "app/doc_exporter.h" |
| 15 | #include "app/util/open_batch.h" |
| 16 | #include "doc/selected_layers.h" |
| 17 | |
| 18 | #include <memory> |
| 19 | #include <set> |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
| 23 | namespace doc { |
| 24 | class Sprite; |
| 25 | } |
| 26 | |
| 27 | namespace app { |
| 28 | |
| 29 | class AppOptions; |
| 30 | class Context; |
| 31 | class DocExporter; |
| 32 | |
| 33 | class CliProcessor { |
| 34 | public: |
| 35 | CliProcessor(CliDelegate* delegate, |
| 36 | const AppOptions& options); |
| 37 | int process(Context* ctx); |
| 38 | |
| 39 | // Public so it can be tested |
| 40 | static void FilterLayers(const doc::Sprite* sprite, |
| 41 | // By value because these vectors will be modified inside |
| 42 | std::vector<std::string> includes, |
| 43 | std::vector<std::string> excludes, |
| 44 | doc::SelectedLayers& filteredLayers); |
| 45 | |
| 46 | private: |
| 47 | bool openFile(Context* ctx, CliOpenFile& cof); |
| 48 | void saveFile(Context* ctx, const CliOpenFile& cof); |
| 49 | |
| 50 | void filterLayers(const doc::Sprite* sprite, |
| 51 | const CliOpenFile& cof, |
| 52 | doc::SelectedLayers& filteredLayers) { |
| 53 | CliProcessor::FilterLayers( |
| 54 | sprite, |
| 55 | cof.includeLayers, |
| 56 | cof.excludeLayers, |
| 57 | filteredLayers); |
| 58 | } |
| 59 | |
| 60 | CliDelegate* m_delegate; |
| 61 | const AppOptions& m_options; |
| 62 | std::unique_ptr<DocExporter> m_exporter; |
| 63 | |
| 64 | // Files already used in the CLI processing (e.g. when used to |
| 65 | // load a sequence of files) so we don't ask for them again. |
| 66 | std::set<std::string> m_usedFiles; |
| 67 | OpenBatchOfFiles m_batch; |
| 68 | }; |
| 69 | |
| 70 | } // namespace app |
| 71 | |
| 72 | #endif |
| 73 | |