Include opacity and blend mode for each layer in JSON output

This commit is contained in:
David Capello 2015-12-09 11:00:57 -03:00
parent 9e1626163d
commit e63dea61fd
4 changed files with 49 additions and 1 deletions

View File

@ -729,7 +729,12 @@ void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os,
firstLayer = false;
else
os << ",";
os << "\n { \"name\": \"" << escape_for_json(layer->name()) << "\" }";
os << "\n { \"name\": \"" << escape_for_json(layer->name()) << "\"";
if (LayerImage* layerImg = dynamic_cast<LayerImage*>(layer)) {
os << ", \"opacity\": " << layerImg->opacity()
<< ", \"blendMode\": \"" << blend_mode_to_string(layerImg->blendMode()) << "\"";
}
os << " }";
}
}
os << "\n ]";

View File

@ -13,6 +13,7 @@ add_library(doc-lib
algorithm/shrink_bounds.cpp
anidir.cpp
blend_funcs.cpp
blend_mode.cpp
brush.cpp
cel.cpp
cel_data.cpp

38
src/doc/blend_mode.cpp Normal file
View File

@ -0,0 +1,38 @@
// Aseprite Document Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/blend_mode.h"
namespace doc {
std::string blend_mode_to_string(BlendMode blendMode)
{
switch (blendMode) {
case BlendMode::NORMAL: return "normal";
case BlendMode::MULTIPLY: return "multiply";
case BlendMode::SCREEN: return "screen";
case BlendMode::OVERLAY: return "overlay";
case BlendMode::DARKEN: return "darken";
case BlendMode::LIGHTEN: return "lighten";
case BlendMode::COLOR_DODGE: return "color_dodge";
case BlendMode::COLOR_BURN: return "color_burn";
case BlendMode::HARD_LIGHT: return "hard_light";
case BlendMode::SOFT_LIGHT: return "soft_light";
case BlendMode::DIFFERENCE: return "difference";
case BlendMode::EXCLUSION: return "exclusion";
case BlendMode::HSL_HUE: return "hsl_hue";
case BlendMode::HSL_SATURATION: return "hsl_saturation";
case BlendMode::HSL_COLOR: return "hsl_color";
case BlendMode::HSL_LUMINOSITY: return "hsl_luminosity";
default: return "unknown";
}
}
} // namespace doc

View File

@ -8,6 +8,8 @@
#define DOC_BLEND_MODE_H_INCLUDED
#pragma once
#include <string>
namespace doc {
enum class BlendMode {
@ -38,6 +40,8 @@ namespace doc {
HSL_LUMINOSITY = 15
};
std::string blend_mode_to_string(BlendMode blendMode);
} // namespace doc
#endif