diff --git a/src/app/cli/app_options.cpp b/src/app/cli/app_options.cpp index 6e1a1981f..c640d94c6 100644 --- a/src/app/cli/app_options.cpp +++ b/src/app/cli/app_options.cpp @@ -74,6 +74,7 @@ AppOptions::AppOptions(int argc, const char* argv[]) , m_scriptParam(m_po.add("script-param").requiresValue("name=value").description("Parameter for a script executed from the\nCLI that you can access with app.params")) #endif , m_listLayers(m_po.add("list-layers").description("List layers of the next given sprite\nor include layers in JSON data")) + , m_listLayerHierarchy(m_po.add("list-layer-hierarchy").description("List layers with groups of the next given sprite\nor include layers hierarchy in JSON data")) , m_listTags(m_po.add("list-tags").description("List tags of the next given sprite\nor include frame tags in JSON data")) , m_listSlices(m_po.add("list-slices").description("List slices of the next given sprite\nor include slices in JSON data")) , m_oneFrame(m_po.add("oneframe").description("Load just the first frame")) diff --git a/src/app/cli/app_options.h b/src/app/cli/app_options.h index eee082639..ffe5ab6b2 100644 --- a/src/app/cli/app_options.h +++ b/src/app/cli/app_options.h @@ -90,6 +90,7 @@ public: const Option& scriptParam() const { return m_scriptParam; } #endif const Option& listLayers() const { return m_listLayers; } + const Option& listLayerHierarchy() const { return m_listLayerHierarchy; } const Option& listTags() const { return m_listTags; } const Option& listSlices() const { return m_listSlices; } const Option& oneFrame() const { return m_oneFrame; } @@ -164,6 +165,7 @@ private: Option& m_scriptParam; #endif Option& m_listLayers; + Option& m_listLayerHierarchy; Option& m_listTags; Option& m_listSlices; Option& m_oneFrame; diff --git a/src/app/cli/cli_open_file.h b/src/app/cli/cli_open_file.h index 003bcb030..1649c0048 100644 --- a/src/app/cli/cli_open_file.h +++ b/src/app/cli/cli_open_file.h @@ -37,6 +37,7 @@ namespace app { bool splitGrid = false; bool allLayers = false; bool listLayers = false; + bool listLayerHierarchy = false; bool listTags = false; bool listSlices = false; bool ignoreEmpty = false; diff --git a/src/app/cli/cli_processor.cpp b/src/app/cli/cli_processor.cpp index 498efc2c1..ffa25ae15 100644 --- a/src/app/cli/cli_processor.cpp +++ b/src/app/cli/cli_processor.cpp @@ -587,6 +587,13 @@ int CliProcessor::process(Context* ctx) else cof.listLayers = true; } + // --list-layer-hierarchy + else if (opt == &m_options.listLayerHierarchy()) { + if (m_exporter) + m_exporter->setListLayerHierarchy(true); + else + cof.listLayerHierarchy = true; + } // --list-tags else if (opt == &m_options.listTags()) { if (m_exporter) diff --git a/src/app/cli/default_cli_delegate.cpp b/src/app/cli/default_cli_delegate.cpp index 0ab323827..89d32db46 100644 --- a/src/app/cli/default_cli_delegate.cpp +++ b/src/app/cli/default_cli_delegate.cpp @@ -67,6 +67,10 @@ void DefaultCliDelegate::afterOpenFile(const CliOpenFile& cof) std::cout << layer->name() << "\n"; } + if (cof.listLayerHierarchy) { + std::cout << cof.document->sprite()->visibleLayerHierarchyAsString() << "\n"; + } + if (cof.listTags) { for (doc::Tag* tag : cof.document->sprite()->tags()) std::cout << tag->name() << "\n"; diff --git a/src/app/cli/preview_cli_delegate.cpp b/src/app/cli/preview_cli_delegate.cpp index 464675033..875794a38 100644 --- a/src/app/cli/preview_cli_delegate.cpp +++ b/src/app/cli/preview_cli_delegate.cpp @@ -67,6 +67,9 @@ void PreviewCliDelegate::afterOpenFile(const CliOpenFile& cof) if (cof.listLayers) std::cout << " - List layers\n"; + if (cof.listLayerHierarchy) + std::cout << " - List layer hierarchy\n"; + if (cof.listTags) std::cout << " - List tags\n"; diff --git a/src/app/doc_exporter.cpp b/src/app/doc_exporter.cpp index 9eb62541a..1f682c11e 100644 --- a/src/app/doc_exporter.cpp +++ b/src/app/doc_exporter.cpp @@ -623,6 +623,7 @@ void DocExporter::reset() m_splitTags = false; m_listTags = false; m_listLayers = false; + m_listLayerHierarchy = false; m_listSlices = false; m_documents.clear(); } @@ -1487,7 +1488,7 @@ void DocExporter::createDataFile(const Samples& samples, } // meta.layers - if (m_listLayers) { + if (m_listLayers || m_listLayerHierarchy) { LayerList metaLayers; for (auto& item : m_documents) { if (item.isOneImageOnly()) diff --git a/src/app/doc_exporter.h b/src/app/doc_exporter.h index d238c9ca6..7a8bba329 100644 --- a/src/app/doc_exporter.h +++ b/src/app/doc_exporter.h @@ -77,6 +77,7 @@ namespace app { void setSplitTags(bool splitTags) { m_splitTags = splitTags; } void setListTags(bool value) { m_listTags = value; } void setListLayers(bool value) { m_listLayers = value; } + void setListLayerHierarchy(bool value) { m_listLayerHierarchy = value; } void setListSlices(bool value) { m_listSlices = value; } void addImage( @@ -180,6 +181,7 @@ namespace app { bool m_splitTags; bool m_listTags; bool m_listLayers; + bool m_listLayerHierarchy; bool m_listSlices; Items m_documents; diff --git a/src/doc/layer.cpp b/src/doc/layer.cpp index 734b93c43..44db9d760 100644 --- a/src/doc/layer.cpp +++ b/src/doc/layer.cpp @@ -540,6 +540,20 @@ void LayerGroup::allTilemaps(LayerList& list) const } } +std::string LayerGroup::visibleLayerHierarchyAsString(const std::string& indent) const +{ + std::string str; + for (Layer* child : m_layers) { + if (!child->isVisible()) + continue; + + str += indent + child->name() + (child->isGroup() ? "/" : "") + "\n"; + if (child->isGroup()) + str += static_cast(child)->visibleLayerHierarchyAsString(indent+" "); + } + return str; +} + void LayerGroup::getCels(CelList& cels) const { for (const Layer* layer : m_layers) diff --git a/src/doc/layer.h b/src/doc/layer.h index facbfd97b..aa34db90b 100644 --- a/src/doc/layer.h +++ b/src/doc/layer.h @@ -215,6 +215,7 @@ namespace doc { void allVisibleReferenceLayers(LayerList& list) const; void allBrowsableLayers(LayerList& list) const; void allTilemaps(LayerList& list) const; + std::string visibleLayerHierarchyAsString(const std::string& indent) const; void getCels(CelList& cels) const override; void displaceFrames(frame_t fromThis, frame_t delta) override; diff --git a/src/doc/sprite.cpp b/src/doc/sprite.cpp index 8b30f79f9..8ec340651 100644 --- a/src/doc/sprite.cpp +++ b/src/doc/sprite.cpp @@ -773,6 +773,11 @@ LayerList Sprite::allTilemaps() const return list; } +std::string Sprite::visibleLayerHierarchyAsString() const +{ + return m_root->visibleLayerHierarchyAsString(""); +} + CelsRange Sprite::cels() const { SelectedFrames selFrames; diff --git a/src/doc/sprite.h b/src/doc/sprite.h index b2831ea58..6c7ea9de3 100644 --- a/src/doc/sprite.h +++ b/src/doc/sprite.h @@ -219,6 +219,7 @@ namespace doc { LayerList allVisibleReferenceLayers() const; LayerList allBrowsableLayers() const; LayerList allTilemaps() const; + std::string visibleLayerHierarchyAsString() const; CelsRange cels() const; CelsRange cels(frame_t frame) const;