mirror of https://github.com/aseprite/aseprite.git
Refactor DocExporter::DataFormat -> SpriteSheetDataFormat
This commit is contained in:
parent
fa246d9c60
commit
aa66ff35a2
|
@ -450,7 +450,7 @@
|
||||||
<option id="best_fit" type="bool" default="false" />
|
<option id="best_fit" type="bool" default="false" />
|
||||||
<option id="texture_filename" type="std::string" />
|
<option id="texture_filename" type="std::string" />
|
||||||
<option id="data_filename" type="std::string" />
|
<option id="data_filename" type="std::string" />
|
||||||
<option id="data_format" type="DocExporter::DataFormat" default="DocExporter::DefaultDataFormat" />
|
<option id="data_format" type="SpriteSheetDataFormat" default="SpriteSheetDataFormat::Default" />
|
||||||
<option id="border_padding" type="int" default="0" />
|
<option id="border_padding" type="int" default="0" />
|
||||||
<option id="shape_padding" type="int" default="0" />
|
<option id="shape_padding" type="int" default="0" />
|
||||||
<option id="inner_padding" type="int" default="0" />
|
<option id="inner_padding" type="int" default="0" />
|
||||||
|
|
|
@ -213,12 +213,12 @@ void CliProcessor::process(Context* ctx)
|
||||||
// --format <format>
|
// --format <format>
|
||||||
else if (opt == &m_options.format()) {
|
else if (opt == &m_options.format()) {
|
||||||
if (m_exporter) {
|
if (m_exporter) {
|
||||||
DocExporter::DataFormat format = DocExporter::DefaultDataFormat;
|
SpriteSheetDataFormat format = SpriteSheetDataFormat::Default;
|
||||||
|
|
||||||
if (value.value() == "json-hash")
|
if (value.value() == "json-hash")
|
||||||
format = DocExporter::JsonHashDataFormat;
|
format = SpriteSheetDataFormat::JsonHash;
|
||||||
else if (value.value() == "json-array")
|
else if (value.value() == "json-array")
|
||||||
format = DocExporter::JsonArrayDataFormat;
|
format = SpriteSheetDataFormat::JsonArray;
|
||||||
|
|
||||||
m_exporter->setDataFormat(format);
|
m_exporter->setDataFormat(format);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "app/cli/cli_delegate.h"
|
#include "app/cli/cli_delegate.h"
|
||||||
#include "app/cli/cli_open_file.h"
|
#include "app/cli/cli_open_file.h"
|
||||||
|
#include "app/doc_exporter.h"
|
||||||
#include "doc/selected_layers.h"
|
#include "doc/selected_layers.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
|
@ -200,8 +200,8 @@ void PreviewCliDelegate::exportFiles(Context* ctx, DocExporter& exporter)
|
||||||
if (!exporter.dataFilename().empty()) {
|
if (!exporter.dataFilename().empty()) {
|
||||||
std::string format = "Unknown";
|
std::string format = "Unknown";
|
||||||
switch (exporter.dataFormat()) {
|
switch (exporter.dataFormat()) {
|
||||||
case DocExporter::JsonHashDataFormat: format = "JSON Hash"; break;
|
case SpriteSheetDataFormat::JsonHash: format = "JSON Hash"; break;
|
||||||
case DocExporter::JsonArrayDataFormat: format = "JSON Array"; break;
|
case SpriteSheetDataFormat::JsonArray: format = "JSON Array"; break;
|
||||||
}
|
}
|
||||||
std::cout << " - Save data file: '" << exporter.dataFilename() << "'\n"
|
std::cout << " - Save data file: '" << exporter.dataFilename() << "'\n"
|
||||||
<< " - Data format: " << format << "\n";
|
<< " - Data format: " << format << "\n";
|
||||||
|
|
|
@ -184,7 +184,7 @@ struct ExportSpriteSheetParams : public NewParams {
|
||||||
Param<bool> bestFit { this, false, "bestFit" };
|
Param<bool> bestFit { this, false, "bestFit" };
|
||||||
Param<std::string> textureFilename { this, std::string(), "textureFilename" };
|
Param<std::string> textureFilename { this, std::string(), "textureFilename" };
|
||||||
Param<std::string> dataFilename { this, std::string(), "dataFilename" };
|
Param<std::string> dataFilename { this, std::string(), "dataFilename" };
|
||||||
Param<DocExporter::DataFormat> dataFormat { this, DocExporter::DefaultDataFormat, "dataFormat" };
|
Param<SpriteSheetDataFormat> dataFormat { this, SpriteSheetDataFormat::Default, "dataFormat" };
|
||||||
Param<int> borderPadding { this, 0, "borderPadding" };
|
Param<int> borderPadding { this, 0, "borderPadding" };
|
||||||
Param<int> shapePadding { this, 0, "shapePadding" };
|
Param<int> shapePadding { this, 0, "shapePadding" };
|
||||||
Param<int> innerPadding { this, 0, "innerPadding" };
|
Param<int> innerPadding { this, 0, "innerPadding" };
|
||||||
|
@ -212,7 +212,7 @@ void update_doc_exporter_from_params(const Site& site,
|
||||||
const bool bestFit = params.bestFit();
|
const bool bestFit = params.bestFit();
|
||||||
const std::string filename = params.textureFilename();
|
const std::string filename = params.textureFilename();
|
||||||
const std::string dataFilename = params.dataFilename();
|
const std::string dataFilename = params.dataFilename();
|
||||||
const DocExporter::DataFormat dataFormat = params.dataFormat();
|
const SpriteSheetDataFormat dataFormat = params.dataFormat();
|
||||||
const std::string layerName = params.layer();
|
const std::string layerName = params.layer();
|
||||||
const std::string tagName = params.tag();
|
const std::string tagName = params.tag();
|
||||||
const int borderPadding = base::clamp(params.borderPadding(), 0, 100);
|
const int borderPadding = base::clamp(params.borderPadding(), 0, 100);
|
||||||
|
@ -547,11 +547,11 @@ private:
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
DocExporter::DataFormat dataFormatValue() const {
|
SpriteSheetDataFormat dataFormatValue() const {
|
||||||
if (dataEnabled()->isSelected())
|
if (dataEnabled()->isSelected())
|
||||||
return DocExporter::DataFormat(dataFormat()->getSelectedItemIndex());
|
return SpriteSheetDataFormat(dataFormat()->getSelectedItemIndex());
|
||||||
else
|
else
|
||||||
return DocExporter::DefaultDataFormat;
|
return SpriteSheetDataFormat::Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
int borderPaddingValue() const {
|
int borderPaddingValue() const {
|
||||||
|
|
|
@ -87,15 +87,15 @@ void Param<app::SpriteSheetType>::fromString(const std::string& value)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void Param<app::DocExporter::DataFormat>::fromString(const std::string& value)
|
void Param<app::SpriteSheetDataFormat>::fromString(const std::string& value)
|
||||||
{
|
{
|
||||||
// JsonArray, json-array, json_array, etc.
|
// JsonArray, json-array, json_array, etc.
|
||||||
if (base::utf8_icmp(value, "JsonArray") == 0 ||
|
if (base::utf8_icmp(value, "JsonArray") == 0 ||
|
||||||
base::utf8_icmp(value, "json-array") == 0 ||
|
base::utf8_icmp(value, "json-array") == 0 ||
|
||||||
base::utf8_icmp(value, "json_array") == 0)
|
base::utf8_icmp(value, "json_array") == 0)
|
||||||
setValue(app::DocExporter::JsonArrayDataFormat);
|
setValue(app::SpriteSheetDataFormat::JsonArray);
|
||||||
else
|
else
|
||||||
setValue(app::DocExporter::JsonHashDataFormat);
|
setValue(app::SpriteSheetDataFormat::JsonHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
@ -231,12 +231,12 @@ void Param<app::SpriteSheetType>::fromLua(lua_State* L, int index)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void Param<app::DocExporter::DataFormat>::fromLua(lua_State* L, int index)
|
void Param<app::SpriteSheetDataFormat>::fromLua(lua_State* L, int index)
|
||||||
{
|
{
|
||||||
if (lua_type(L, index) == LUA_TSTRING)
|
if (lua_type(L, index) == LUA_TSTRING)
|
||||||
fromString(lua_tostring(L, index));
|
fromString(lua_tostring(L, index));
|
||||||
else
|
else
|
||||||
setValue((app::DocExporter::DataFormat)lua_tointeger(L, index));
|
setValue((app::SpriteSheetDataFormat)lua_tointeger(L, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -480,7 +480,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
DocExporter::DocExporter()
|
DocExporter::DocExporter()
|
||||||
: m_dataFormat(DefaultDataFormat)
|
: m_dataFormat(SpriteSheetDataFormat::Default)
|
||||||
, m_textureWidth(0)
|
, m_textureWidth(0)
|
||||||
, m_textureHeight(0)
|
, m_textureHeight(0)
|
||||||
, m_sheetType(SpriteSheetType::None)
|
, m_sheetType(SpriteSheetType::None)
|
||||||
|
@ -885,13 +885,13 @@ void DocExporter::createDataFile(const Samples& samples, std::ostream& os, Image
|
||||||
|
|
||||||
// TODO we should use some string templates system here
|
// TODO we should use some string templates system here
|
||||||
switch (m_dataFormat) {
|
switch (m_dataFormat) {
|
||||||
case JsonHashDataFormat:
|
case SpriteSheetDataFormat::JsonHash:
|
||||||
frames_begin = "{";
|
frames_begin = "{";
|
||||||
frames_end = "}";
|
frames_end = "}";
|
||||||
filename_as_key = true;
|
filename_as_key = true;
|
||||||
filename_as_attr = false;
|
filename_as_attr = false;
|
||||||
break;
|
break;
|
||||||
case JsonArrayDataFormat:
|
case SpriteSheetDataFormat::JsonArray:
|
||||||
frames_begin = "[";
|
frames_begin = "[";
|
||||||
frames_end = "]";
|
frames_end = "]";
|
||||||
filename_as_key = false;
|
filename_as_key = false;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#define APP_DOC_EXPORTER_H_INCLUDED
|
#define APP_DOC_EXPORTER_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "app/sprite_sheet_data_format.h"
|
||||||
#include "app/sprite_sheet_type.h"
|
#include "app/sprite_sheet_type.h"
|
||||||
#include "base/disable_copying.h"
|
#include "base/disable_copying.h"
|
||||||
#include "doc/frame.h"
|
#include "doc/frame.h"
|
||||||
|
@ -36,15 +37,9 @@ namespace app {
|
||||||
|
|
||||||
class DocExporter {
|
class DocExporter {
|
||||||
public:
|
public:
|
||||||
enum DataFormat {
|
|
||||||
JsonHashDataFormat,
|
|
||||||
JsonArrayDataFormat,
|
|
||||||
DefaultDataFormat = JsonHashDataFormat
|
|
||||||
};
|
|
||||||
|
|
||||||
DocExporter();
|
DocExporter();
|
||||||
|
|
||||||
DataFormat dataFormat() const { return m_dataFormat; }
|
SpriteSheetDataFormat dataFormat() const { return m_dataFormat; }
|
||||||
const std::string& dataFilename() { return m_dataFilename; }
|
const std::string& dataFilename() { return m_dataFilename; }
|
||||||
const std::string& textureFilename() { return m_textureFilename; }
|
const std::string& textureFilename() { return m_textureFilename; }
|
||||||
int textureWidth() const { return m_textureWidth; }
|
int textureWidth() const { return m_textureWidth; }
|
||||||
|
@ -61,7 +56,7 @@ namespace app {
|
||||||
bool listTags() const { return m_listTags; }
|
bool listTags() const { return m_listTags; }
|
||||||
bool listLayers() const { return m_listLayers; }
|
bool listLayers() const { return m_listLayers; }
|
||||||
|
|
||||||
void setDataFormat(DataFormat format) { m_dataFormat = format; }
|
void setDataFormat(SpriteSheetDataFormat format) { m_dataFormat = format; }
|
||||||
void setDataFilename(const std::string& filename) { m_dataFilename = filename; }
|
void setDataFilename(const std::string& filename) { m_dataFilename = filename; }
|
||||||
void setTextureFilename(const std::string& filename) { m_textureFilename = filename; }
|
void setTextureFilename(const std::string& filename) { m_textureFilename = filename; }
|
||||||
void setTextureWidth(int width) { m_textureWidth = width; }
|
void setTextureWidth(int width) { m_textureWidth = width; }
|
||||||
|
@ -126,7 +121,7 @@ namespace app {
|
||||||
};
|
};
|
||||||
typedef std::vector<Item> Items;
|
typedef std::vector<Item> Items;
|
||||||
|
|
||||||
DataFormat m_dataFormat;
|
SpriteSheetDataFormat m_dataFormat;
|
||||||
std::string m_dataFilename;
|
std::string m_dataFilename;
|
||||||
std::string m_textureFilename;
|
std::string m_textureFilename;
|
||||||
int m_textureWidth;
|
int m_textureWidth;
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
|
|
||||||
#include "app/color.h"
|
#include "app/color.h"
|
||||||
#include "app/commands/filters/cels_target.h"
|
#include "app/commands/filters/cels_target.h"
|
||||||
#include "app/doc_exporter.h"
|
|
||||||
#include "app/docs_observer.h"
|
#include "app/docs_observer.h"
|
||||||
#include "app/pref/option.h"
|
#include "app/pref/option.h"
|
||||||
|
#include "app/sprite_sheet_data_format.h"
|
||||||
#include "app/sprite_sheet_type.h"
|
#include "app/sprite_sheet_type.h"
|
||||||
#include "app/tools/freehand_algorithm.h"
|
#include "app/tools/freehand_algorithm.h"
|
||||||
#include "app/tools/ink_type.h"
|
#include "app/tools/ink_type.h"
|
||||||
|
|
|
@ -299,8 +299,8 @@ Engine::Engine()
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
lua_setglobal(L, "SpriteSheetDataFormat");
|
lua_setglobal(L, "SpriteSheetDataFormat");
|
||||||
setfield_integer(L, "JSON_HASH", DocExporter::JsonHashDataFormat);
|
setfield_integer(L, "JSON_HASH", SpriteSheetDataFormat::JsonHash);
|
||||||
setfield_integer(L, "JSON_ARRAY", DocExporter::JsonArrayDataFormat);
|
setfield_integer(L, "JSON_ARRAY", SpriteSheetDataFormat::JsonArray);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|
|
@ -142,7 +142,7 @@ gfx::Rect get_value_from_lua(lua_State* L, int index) {
|
||||||
|
|
||||||
FOR_ENUM(app::CelsTarget)
|
FOR_ENUM(app::CelsTarget)
|
||||||
FOR_ENUM(app::ColorBar::ColorSelector)
|
FOR_ENUM(app::ColorBar::ColorSelector)
|
||||||
FOR_ENUM(app::DocExporter::DataFormat)
|
FOR_ENUM(app::SpriteSheetDataFormat)
|
||||||
FOR_ENUM(app::SpriteSheetType)
|
FOR_ENUM(app::SpriteSheetType)
|
||||||
FOR_ENUM(app::gen::BgType)
|
FOR_ENUM(app::gen::BgType)
|
||||||
FOR_ENUM(app::gen::BrushPreview)
|
FOR_ENUM(app::gen::BrushPreview)
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2019 Igara Studio S.A.
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifndef APP_SPRITE_SHEET_DATA_FORMAT_H_INCLUDED
|
||||||
|
#define APP_SPRITE_SHEET_DATA_FORMAT_H_INCLUDED
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
|
||||||
|
enum class SpriteSheetDataFormat {
|
||||||
|
JsonHash,
|
||||||
|
JsonArray,
|
||||||
|
Default = JsonHash
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace app
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue