mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-06 06:50:07 +00:00
Refactor app::DocFormat to doc::SerialFormat
This fixes a violation of module layers (circular dependency)
introduced in e6cd13d7e1
where doc-lib
started to depend on app-lib (which cannot happen, as app-lib depends
on doc-lib).
This DocFormat/SerialFormat was used only from app-lib previously, but
when properties were introduced in user data, the serialization format
version was needed to read user properties too. So now it makes sense
to move this type/its values to the doc-lib.
A couple of extra issues were found in this refactor:
1) The recursive call inside read_layer() didn't receive this "serial"
argument
2) read_grid() doesn't need the setId parameter
This commit is contained in:
parent
32a099dcb6
commit
cdea6004bd
@ -1,16 +0,0 @@
|
|||||||
// Aseprite
|
|
||||||
// Copyright (c) 2020 Igara Studio S.A.
|
|
||||||
//
|
|
||||||
// This program is distributed under the terms of
|
|
||||||
// the End-User License Agreement for Aseprite.
|
|
||||||
|
|
||||||
#ifndef APP_CRASH_DOC_FORMAT_H_INCLUDED
|
|
||||||
#define APP_CRASH_DOC_FORMAT_H_INCLUDED
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#define DOC_FORMAT_VERSION_0 0 // Old version
|
|
||||||
#define DOC_FORMAT_VERSION_1 1 // New version with tilesets
|
|
||||||
#define DOC_FORMAT_VERSION_2 2 // Version 2 adds custom properties to user data
|
|
||||||
#define DOC_FORMAT_VERSION_LAST 2
|
|
||||||
|
|
||||||
#endif
|
|
@ -12,7 +12,6 @@
|
|||||||
#include "app/crash/read_document.h"
|
#include "app/crash/read_document.h"
|
||||||
|
|
||||||
#include "app/console.h"
|
#include "app/console.h"
|
||||||
#include "app/crash/doc_format.h"
|
|
||||||
#include "app/crash/internals.h"
|
#include "app/crash/internals.h"
|
||||||
#include "app/crash/log.h"
|
#include "app/crash/log.h"
|
||||||
#include "app/doc.h"
|
#include "app/doc.h"
|
||||||
@ -32,6 +31,7 @@
|
|||||||
#include "doc/layer_tilemap.h"
|
#include "doc/layer_tilemap.h"
|
||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
#include "doc/palette_io.h"
|
#include "doc/palette_io.h"
|
||||||
|
#include "doc/serial_format.h"
|
||||||
#include "doc/slice.h"
|
#include "doc/slice.h"
|
||||||
#include "doc/slice_io.h"
|
#include "doc/slice_io.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
@ -70,7 +70,7 @@ class Reader : public SubObjectsIO {
|
|||||||
public:
|
public:
|
||||||
Reader(const std::string& dir,
|
Reader(const std::string& dir,
|
||||||
base::task_token* t)
|
base::task_token* t)
|
||||||
: m_docFormatVer(DOC_FORMAT_VERSION_0)
|
: m_serial(SerialFormat::Ver0)
|
||||||
, m_sprite(nullptr)
|
, m_sprite(nullptr)
|
||||||
, m_dir(dir)
|
, m_dir(dir)
|
||||||
, m_docId(0)
|
, m_docId(0)
|
||||||
@ -198,10 +198,11 @@ private:
|
|||||||
Doc* readDocument(std::ifstream& s) {
|
Doc* readDocument(std::ifstream& s) {
|
||||||
ObjectId sprId = read32(s);
|
ObjectId sprId = read32(s);
|
||||||
std::string filename = read_string(s);
|
std::string filename = read_string(s);
|
||||||
m_docFormatVer = read16(s);
|
m_serial = SerialFormat(read16(s));
|
||||||
if (s.eof()) m_docFormatVer = DOC_FORMAT_VERSION_0;
|
if (s.eof())
|
||||||
|
m_serial = SerialFormat::Ver0;
|
||||||
|
|
||||||
RECO_TRACE("RECO: internal format version=%d\n", m_docFormatVer);
|
RECO_TRACE("RECO: internal format version=%d\n", int(m_serial));
|
||||||
|
|
||||||
// Load DocumentInfo only
|
// Load DocumentInfo only
|
||||||
if (m_loadInfo) {
|
if (m_loadInfo) {
|
||||||
@ -268,7 +269,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IDs of all tilesets
|
// IDs of all tilesets
|
||||||
if (m_docFormatVer >= DOC_FORMAT_VERSION_1) {
|
if (m_serial >= SerialFormat::Ver1) {
|
||||||
int ntilesets = read32(s);
|
int ntilesets = read32(s);
|
||||||
if (ntilesets > 0 && ntilesets < 0xffffff) {
|
if (ntilesets > 0 && ntilesets < 0xffffff) {
|
||||||
for (int i=0; i<ntilesets; ++i) {
|
for (int i=0; i<ntilesets; ++i) {
|
||||||
@ -399,7 +400,7 @@ private:
|
|||||||
|
|
||||||
// Read Sprite User Data
|
// Read Sprite User Data
|
||||||
if (!s.eof()) {
|
if (!s.eof()) {
|
||||||
UserData userData = read_user_data(s, m_docFormatVer);
|
UserData userData = read_user_data(s, m_serial);
|
||||||
if (!userData.isEmpty())
|
if (!userData.isEmpty())
|
||||||
spr->setUserData(userData);
|
spr->setUserData(userData);
|
||||||
}
|
}
|
||||||
@ -497,7 +498,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lay) {
|
if (lay) {
|
||||||
UserData userData = read_user_data(s, m_docFormatVer);
|
UserData userData = read_user_data(s, m_serial);
|
||||||
lay->setUserData(userData);
|
lay->setUserData(userData);
|
||||||
return lay.release();
|
return lay.release();
|
||||||
}
|
}
|
||||||
@ -510,7 +511,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
CelData* readCelData(std::ifstream& s) {
|
CelData* readCelData(std::ifstream& s) {
|
||||||
return read_celdata(s, this, false, m_docFormatVer);
|
return read_celdata(s, this, false, m_serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
Image* readImage(std::ifstream& s) {
|
Image* readImage(std::ifstream& s) {
|
||||||
@ -523,18 +524,18 @@ private:
|
|||||||
|
|
||||||
Tileset* readTileset(std::ifstream& s) {
|
Tileset* readTileset(std::ifstream& s) {
|
||||||
uint32_t tilesetVer;
|
uint32_t tilesetVer;
|
||||||
Tileset* tileset = read_tileset(s, m_sprite, false, &tilesetVer, m_docFormatVer);
|
Tileset* tileset = read_tileset(s, m_sprite, false, &tilesetVer, m_serial);
|
||||||
if (tileset && tilesetVer < TILESET_VER1)
|
if (tileset && tilesetVer < TILESET_VER1)
|
||||||
m_updateOldTilemapWithTileset.insert(tileset->id());
|
m_updateOldTilemapWithTileset.insert(tileset->id());
|
||||||
return tileset;
|
return tileset;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tag* readTag(std::ifstream& s) {
|
Tag* readTag(std::ifstream& s) {
|
||||||
return read_tag(s, false, m_docFormatVer);
|
return read_tag(s, false, m_serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
Slice* readSlice(std::ifstream& s) {
|
Slice* readSlice(std::ifstream& s) {
|
||||||
return read_slice(s, false, m_docFormatVer);
|
return read_slice(s, false, m_serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix issues that the restoration process could produce.
|
// Fix issues that the restoration process could produce.
|
||||||
@ -586,7 +587,7 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_docFormatVer;
|
SerialFormat m_serial;
|
||||||
Sprite* m_sprite; // Used to pass the sprite in LayerImage() ctor
|
Sprite* m_sprite; // Used to pass the sprite in LayerImage() ctor
|
||||||
std::string m_dir;
|
std::string m_dir;
|
||||||
ObjectVersion m_docId;
|
ObjectVersion m_docId;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2023 Igara Studio S.A.
|
// Copyright (C) 2018-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
#include "app/crash/write_document.h"
|
#include "app/crash/write_document.h"
|
||||||
|
|
||||||
#include "app/crash/doc_format.h"
|
|
||||||
#include "app/crash/internals.h"
|
#include "app/crash/internals.h"
|
||||||
#include "app/crash/log.h"
|
#include "app/crash/log.h"
|
||||||
#include "app/doc.h"
|
#include "app/doc.h"
|
||||||
@ -31,6 +30,7 @@
|
|||||||
#include "doc/layer_tilemap.h"
|
#include "doc/layer_tilemap.h"
|
||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
#include "doc/palette_io.h"
|
#include "doc/palette_io.h"
|
||||||
|
#include "doc/serial_format.h"
|
||||||
#include "doc/slice.h"
|
#include "doc/slice.h"
|
||||||
#include "doc/slice_io.h"
|
#include "doc/slice_io.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
@ -152,7 +152,7 @@ private:
|
|||||||
bool writeDocumentFile(std::ofstream& s, Doc* doc) {
|
bool writeDocumentFile(std::ofstream& s, Doc* doc) {
|
||||||
write32(s, doc->sprite()->id());
|
write32(s, doc->sprite()->id());
|
||||||
write_string(s, doc->filename());
|
write_string(s, doc->filename());
|
||||||
write16(s, DOC_FORMAT_VERSION_LAST);
|
write16(s, uint16_t(doc::SerialFormat::LastVer));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,8 @@ namespace doc {
|
|||||||
using namespace base::serialization;
|
using namespace base::serialization;
|
||||||
using namespace base::serialization::little_endian;
|
using namespace base::serialization::little_endian;
|
||||||
|
|
||||||
void write_celdata(std::ostream& os, const CelData* celdata)
|
void write_celdata(std::ostream& os,
|
||||||
|
const CelData* celdata)
|
||||||
{
|
{
|
||||||
write32(os, celdata->id());
|
write32(os, celdata->id());
|
||||||
write32(os, celdata->bounds().x);
|
write32(os, celdata->bounds().x);
|
||||||
@ -50,7 +51,10 @@ void write_celdata(std::ostream& os, const CelData* celdata)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CelData* read_celdata(std::istream& is, SubObjectsIO* subObjects, const bool setId, const int docFormatVer)
|
CelData* read_celdata(std::istream& is,
|
||||||
|
SubObjectsIO* subObjects,
|
||||||
|
const bool setId,
|
||||||
|
const SerialFormat serial)
|
||||||
{
|
{
|
||||||
ObjectId id = read32(is);
|
ObjectId id = read32(is);
|
||||||
int x = read32(is);
|
int x = read32(is);
|
||||||
@ -59,7 +63,7 @@ CelData* read_celdata(std::istream& is, SubObjectsIO* subObjects, const bool set
|
|||||||
int h = read32(is);
|
int h = read32(is);
|
||||||
int opacity = read8(is);
|
int opacity = read8(is);
|
||||||
ObjectId imageId = read32(is);
|
ObjectId imageId = read32(is);
|
||||||
UserData userData = read_user_data(is, docFormatVer);
|
const UserData userData = read_user_data(is, serial);
|
||||||
gfx::RectF boundsF;
|
gfx::RectF boundsF;
|
||||||
|
|
||||||
// Extra fields
|
// Extra fields
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
|
// Copyright (c) 2024 Igara Studio S.A.
|
||||||
// Copyright (c) 2001-2015 David Capello
|
// Copyright (c) 2001-2015 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
@ -8,7 +9,7 @@
|
|||||||
#define DOC_CEL_DATA_IO_H_INCLUDED
|
#define DOC_CEL_DATA_IO_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "app/crash/doc_format.h"
|
#include "doc/serial_format.h"
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
@ -17,8 +18,13 @@ namespace doc {
|
|||||||
class CelData;
|
class CelData;
|
||||||
class SubObjectsIO;
|
class SubObjectsIO;
|
||||||
|
|
||||||
void write_celdata(std::ostream& os, const CelData* cel);
|
void write_celdata(std::ostream& os,
|
||||||
CelData* read_celdata(std::istream& is, SubObjectsIO* subObjects, const bool setId = true, const int read_celdata = DOC_FORMAT_VERSION_LAST);
|
const CelData* cel);
|
||||||
|
|
||||||
|
CelData* read_celdata(std::istream& is,
|
||||||
|
SubObjectsIO* subObjects,
|
||||||
|
bool setId = true,
|
||||||
|
SerialFormat serial = SerialFormat::LastVer);
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ bool write_grid(std::ostream& os, const Grid& grid)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Grid read_grid(std::istream& is, bool setId)
|
Grid read_grid(std::istream& is)
|
||||||
{
|
{
|
||||||
gfx::Size tileSize;
|
gfx::Size tileSize;
|
||||||
gfx::Point origin;
|
gfx::Point origin;
|
||||||
|
@ -15,7 +15,7 @@ namespace doc {
|
|||||||
class Grid;
|
class Grid;
|
||||||
|
|
||||||
bool write_grid(std::ostream& os, const Grid& grid);
|
bool write_grid(std::ostream& os, const Grid& grid);
|
||||||
Grid read_grid(std::istream& is, bool setId = true);
|
Grid read_grid(std::istream& is);
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ bool write_image(std::ostream& os, const Image* image, CancelIO* cancel)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image* read_image(std::istream& is, bool setId)
|
Image* read_image(std::istream& is, const bool setId)
|
||||||
{
|
{
|
||||||
ObjectId id = read32(is);
|
ObjectId id = read32(is);
|
||||||
int pixelFormat = read8(is); // Pixel format
|
int pixelFormat = read8(is); // Pixel format
|
||||||
|
@ -110,7 +110,9 @@ void write_layer(std::ostream& os, const Layer* layer)
|
|||||||
write_user_data(os, layer->userData());
|
write_user_data(os, layer->userData());
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer* read_layer(std::istream& is, SubObjectsFromSprite* subObjects, const int docFormatVer)
|
Layer* read_layer(std::istream& is,
|
||||||
|
SubObjectsFromSprite* subObjects,
|
||||||
|
const SerialFormat serial)
|
||||||
{
|
{
|
||||||
ObjectId id = read32(is);
|
ObjectId id = read32(is);
|
||||||
std::string name = read_string(is);
|
std::string name = read_string(is);
|
||||||
@ -147,7 +149,7 @@ Layer* read_layer(std::istream& is, SubObjectsFromSprite* subObjects, const int
|
|||||||
// Read celdatas
|
// Read celdatas
|
||||||
int celdatas = read16(is);
|
int celdatas = read16(is);
|
||||||
for (int c=0; c<celdatas; ++c) {
|
for (int c=0; c<celdatas; ++c) {
|
||||||
CelDataRef celdata(read_celdata(is, subObjects, true, docFormatVer));
|
CelDataRef celdata(read_celdata(is, subObjects, true, serial));
|
||||||
subObjects->addCelDataRef(celdata);
|
subObjects->addCelDataRef(celdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +178,7 @@ Layer* read_layer(std::istream& is, SubObjectsFromSprite* subObjects, const int
|
|||||||
// Number of sub-layers
|
// Number of sub-layers
|
||||||
int layers = read16(is);
|
int layers = read16(is);
|
||||||
for (int c=0; c<layers; c++) {
|
for (int c=0; c<layers; c++) {
|
||||||
Layer* child = read_layer(is, subObjects);
|
Layer* child = read_layer(is, subObjects, serial);
|
||||||
if (child)
|
if (child)
|
||||||
static_cast<LayerGroup*>(layer.get())->addLayer(child);
|
static_cast<LayerGroup*>(layer.get())->addLayer(child);
|
||||||
else
|
else
|
||||||
@ -190,7 +192,7 @@ Layer* read_layer(std::istream& is, SubObjectsFromSprite* subObjects, const int
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UserData userData = read_user_data(is, docFormatVer);
|
const UserData userData = read_user_data(is, serial);
|
||||||
|
|
||||||
if (layer) {
|
if (layer) {
|
||||||
layer->setName(name);
|
layer->setName(name);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
|
// Copyright (c) 2024 Igara Studio S.A.
|
||||||
// Copyright (c) 2001-2015 David Capello
|
// Copyright (c) 2001-2015 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
@ -8,8 +9,8 @@
|
|||||||
#define DOC_LAYER_IO_H_INCLUDED
|
#define DOC_LAYER_IO_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "app/crash/doc_format.h"
|
|
||||||
#include "base/exception.h"
|
#include "base/exception.h"
|
||||||
|
#include "doc/serial_format.h"
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
@ -23,8 +24,11 @@ namespace doc {
|
|||||||
InvalidLayerType(const char* msg) throw() : base::Exception(msg) { }
|
InvalidLayerType(const char* msg) throw() : base::Exception(msg) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
void write_layer(std::ostream& os, const Layer* layer);
|
void write_layer(std::ostream& os,
|
||||||
Layer* read_layer(std::istream& is, SubObjectsFromSprite* subObjects, const int docFormatVer = DOC_FORMAT_VERSION_LAST);
|
const Layer* layer);
|
||||||
|
Layer* read_layer(std::istream& is,
|
||||||
|
SubObjectsFromSprite* subObjects,
|
||||||
|
SerialFormat serial = SerialFormat::LastVer);
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
|
||||||
|
27
src/doc/serial_format.h
Normal file
27
src/doc/serial_format.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (c) 2020-2024 Igara Studio S.A.
|
||||||
|
//
|
||||||
|
// This file is released under the terms of the MIT license.
|
||||||
|
// Read LICENSE.txt for more information.
|
||||||
|
|
||||||
|
#ifndef DOC_SERIAL_FORMAT_H_INCLUDED
|
||||||
|
#define DOC_SERIAL_FORMAT_H_INCLUDED
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base/ints.h"
|
||||||
|
|
||||||
|
namespace doc {
|
||||||
|
|
||||||
|
// Format version of raw document/sprite data when it's serialized in
|
||||||
|
// IO operations for undo/redo or in recovery data to allow backward
|
||||||
|
// compatibility with old session backups.
|
||||||
|
enum class SerialFormat : uint16_t {
|
||||||
|
Ver0 = 0, // Old version
|
||||||
|
Ver1 = 1, // New version with tilesets
|
||||||
|
Ver2 = 2, // Version 2 adds custom properties to user data
|
||||||
|
LastVer = Ver2
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace doc
|
||||||
|
|
||||||
|
#endif
|
@ -37,11 +37,13 @@ void write_slice(std::ostream& os, const Slice* slice)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Slice* read_slice(std::istream& is, const bool setId, const int docFormatVer)
|
Slice* read_slice(std::istream& is,
|
||||||
|
const bool setId,
|
||||||
|
const SerialFormat serial)
|
||||||
{
|
{
|
||||||
ObjectId id = read32(is);
|
ObjectId id = read32(is);
|
||||||
std::string name = read_string(is);
|
std::string name = read_string(is);
|
||||||
UserData userData = read_user_data(is, docFormatVer);
|
const UserData userData = read_user_data(is, serial);
|
||||||
size_t nkeys = read32(is);
|
size_t nkeys = read32(is);
|
||||||
|
|
||||||
std::unique_ptr<Slice> slice(new Slice);
|
std::unique_ptr<Slice> slice(new Slice);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
|
// Copyright (c) 2024 Igara Studio S.A.
|
||||||
// Copyright (c) 2017 David Capello
|
// Copyright (c) 2017 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
@ -8,7 +9,7 @@
|
|||||||
#define DOC_SLICE_IO_H_INCLUDED
|
#define DOC_SLICE_IO_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "app/crash/doc_format.h"
|
#include "doc/serial_format.h"
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
@ -17,10 +18,14 @@ namespace doc {
|
|||||||
class Slice;
|
class Slice;
|
||||||
class SliceKey;
|
class SliceKey;
|
||||||
|
|
||||||
void write_slice(std::ostream& os, const Slice* slice);
|
void write_slice(std::ostream& os,
|
||||||
Slice* read_slice(std::istream& is, const bool setId = true, const int docFormatVer = DOC_FORMAT_VERSION_LAST);
|
const Slice* slice);
|
||||||
|
Slice* read_slice(std::istream& is,
|
||||||
|
bool setId = true,
|
||||||
|
SerialFormat serial = SerialFormat::LastVer);
|
||||||
|
|
||||||
void write_slicekey(std::ostream& os, const SliceKey& sliceKey);
|
void write_slicekey(std::ostream& os,
|
||||||
|
const SliceKey& sliceKey);
|
||||||
SliceKey read_slicekey(std::istream& is);
|
SliceKey read_slicekey(std::istream& is);
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
@ -39,7 +39,7 @@ void write_tag(std::ostream& os, const Tag* tag)
|
|||||||
|
|
||||||
Tag* read_tag(std::istream& is,
|
Tag* read_tag(std::istream& is,
|
||||||
const bool setId,
|
const bool setId,
|
||||||
const int docFormatVer)
|
const SerialFormat serial)
|
||||||
{
|
{
|
||||||
ObjectId id = read32(is);
|
ObjectId id = read32(is);
|
||||||
frame_t from = read32(is);
|
frame_t from = read32(is);
|
||||||
@ -47,7 +47,7 @@ Tag* read_tag(std::istream& is,
|
|||||||
|
|
||||||
// If we are reading a session from v1.2.x, there is a color field
|
// If we are reading a session from v1.2.x, there is a color field
|
||||||
color_t color;
|
color_t color;
|
||||||
if (docFormatVer < DOC_FORMAT_VERSION_1)
|
if (serial < SerialFormat::Ver1)
|
||||||
color = read32(is);
|
color = read32(is);
|
||||||
|
|
||||||
AniDir aniDir = (AniDir)read8(is);
|
AniDir aniDir = (AniDir)read8(is);
|
||||||
@ -56,15 +56,15 @@ Tag* read_tag(std::istream& is,
|
|||||||
|
|
||||||
// If we are reading the new v1.3.x version, there is a user data with the color + text
|
// If we are reading the new v1.3.x version, there is a user data with the color + text
|
||||||
int repeat = 0;
|
int repeat = 0;
|
||||||
if (docFormatVer >= DOC_FORMAT_VERSION_1) {
|
if (serial >= SerialFormat::Ver1) {
|
||||||
userData = read_user_data(is, docFormatVer);
|
userData = read_user_data(is, serial);
|
||||||
repeat = read32(is);
|
repeat = read32(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tag = std::make_unique<Tag>(from, to);
|
auto tag = std::make_unique<Tag>(from, to);
|
||||||
tag->setAniDir(aniDir);
|
tag->setAniDir(aniDir);
|
||||||
tag->setName(name);
|
tag->setName(name);
|
||||||
if (docFormatVer < DOC_FORMAT_VERSION_1)
|
if (serial < SerialFormat::Ver1)
|
||||||
tag->setColor(color);
|
tag->setColor(color);
|
||||||
else {
|
else {
|
||||||
tag->setUserData(userData);
|
tag->setUserData(userData);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
// Copyright (C) 2019-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2015 David Capello
|
// Copyright (C) 2001-2015 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
@ -9,7 +9,7 @@
|
|||||||
#define DOC_TAG_IO_H_INCLUDED
|
#define DOC_TAG_IO_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "app/crash/doc_format.h"
|
#include "doc/serial_format.h"
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
@ -17,10 +17,12 @@ namespace doc {
|
|||||||
|
|
||||||
class Tag;
|
class Tag;
|
||||||
|
|
||||||
void write_tag(std::ostream& os, const Tag* tag);
|
void write_tag(std::ostream& os,
|
||||||
|
const Tag* tag);
|
||||||
|
|
||||||
Tag* read_tag(std::istream& is,
|
Tag* read_tag(std::istream& is,
|
||||||
const bool setId = true,
|
bool setId = true,
|
||||||
const int docFormatVer = DOC_FORMAT_VERSION_LAST);
|
SerialFormat serial = SerialFormat::LastVer);
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
|
||||||
|
@ -57,13 +57,13 @@ bool write_tileset(std::ostream& os,
|
|||||||
|
|
||||||
Tileset* read_tileset(std::istream& is,
|
Tileset* read_tileset(std::istream& is,
|
||||||
Sprite* sprite,
|
Sprite* sprite,
|
||||||
bool setId,
|
const bool setId,
|
||||||
uint32_t* tilesetVer,
|
uint32_t* tilesetVer,
|
||||||
const int docFormatVer)
|
const SerialFormat serial)
|
||||||
{
|
{
|
||||||
ObjectId id = read32(is);
|
const ObjectId id = read32(is);
|
||||||
tileset_index ntiles = read32(is);
|
const tileset_index ntiles = read32(is);
|
||||||
Grid grid = read_grid(is, setId);
|
const Grid grid = read_grid(is);
|
||||||
auto tileset = new Tileset(sprite, grid, ntiles);
|
auto tileset = new Tileset(sprite, grid, ntiles);
|
||||||
if (setId)
|
if (setId)
|
||||||
tileset->setId(id);
|
tileset->setId(id);
|
||||||
@ -74,21 +74,21 @@ Tileset* read_tileset(std::istream& is,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read extra version byte after tiles
|
// Read extra version byte after tiles
|
||||||
uint32_t ver = read8(is);
|
const uint32_t ver = read8(is);
|
||||||
if (tilesetVer)
|
if (tilesetVer)
|
||||||
*tilesetVer = ver;
|
*tilesetVer = ver;
|
||||||
if (ver >= TILESET_VER1) {
|
if (ver >= TILESET_VER1) {
|
||||||
tileset->setBaseIndex(1);
|
tileset->setBaseIndex(1);
|
||||||
|
|
||||||
if (ver >= TILESET_VER2) {
|
if (ver >= TILESET_VER2) {
|
||||||
UserData userData = read_user_data(is, docFormatVer);
|
const UserData userData = read_user_data(is, serial);
|
||||||
tileset->setUserData(userData);
|
tileset->setUserData(userData);
|
||||||
|
|
||||||
if (ver >= TILESET_VER3) {
|
if (ver >= TILESET_VER3) {
|
||||||
tileset->setName(read_string(is));
|
tileset->setName(read_string(is));
|
||||||
|
|
||||||
for (tileset_index ti=0; ti<ntiles; ++ti) {
|
for (tileset_index ti=0; ti<ntiles; ++ti) {
|
||||||
tileset->setTileData(ti, read_user_data(is, docFormatVer));
|
tileset->setTileData(ti, read_user_data(is, serial));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
// Copyright (C) 2019-2024 Igara Studio S.A.
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -8,8 +8,8 @@
|
|||||||
#define DOC_TILESET_IO_H_INCLUDED
|
#define DOC_TILESET_IO_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "app/crash/doc_format.h"
|
|
||||||
#include "base/ints.h"
|
#include "base/ints.h"
|
||||||
|
#include "doc/serial_format.h"
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ namespace doc {
|
|||||||
Sprite* sprite,
|
Sprite* sprite,
|
||||||
bool setId = true,
|
bool setId = true,
|
||||||
uint32_t* tilesetVer = nullptr,
|
uint32_t* tilesetVer = nullptr,
|
||||||
const int docFormatVer = DOC_FORMAT_VERSION_LAST);
|
SerialFormat serial = SerialFormat::LastVer);
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
|
||||||
|
@ -259,7 +259,8 @@ static UserData::PropertiesMaps read_properties_maps(std::istream& is)
|
|||||||
return propertiesMaps;
|
return propertiesMaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserData read_user_data(std::istream& is, const int docFormatVer)
|
UserData read_user_data(std::istream& is,
|
||||||
|
const SerialFormat serial)
|
||||||
{
|
{
|
||||||
UserData userData;
|
UserData userData;
|
||||||
userData.setText(read_string(is));
|
userData.setText(read_string(is));
|
||||||
@ -273,7 +274,7 @@ UserData read_user_data(std::istream& is, const int docFormatVer)
|
|||||||
// When recovering a session from an old Aseprite version, we need
|
// When recovering a session from an old Aseprite version, we need
|
||||||
// to skip reading the parts that it doesn't contains. Otherwise
|
// to skip reading the parts that it doesn't contains. Otherwise
|
||||||
// it is very likely to fail.
|
// it is very likely to fail.
|
||||||
if (docFormatVer >= DOC_FORMAT_VERSION_2) {
|
if (serial >= SerialFormat::Ver2) {
|
||||||
userData.propertiesMaps() = read_properties_maps(is);
|
userData.propertiesMaps() = read_properties_maps(is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
|
// Copyright (c) 2024 Igara Studio S.A.
|
||||||
// Copyright (c) 2001-2015 David Capello
|
// Copyright (c) 2001-2015 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
@ -8,7 +9,7 @@
|
|||||||
#define DOC_USER_DATA_IO_H_INCLUDED
|
#define DOC_USER_DATA_IO_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "app/crash/doc_format.h"
|
#include "doc/serial_format.h"
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
@ -16,8 +17,11 @@ namespace doc {
|
|||||||
|
|
||||||
class UserData;
|
class UserData;
|
||||||
|
|
||||||
void write_user_data(std::ostream& os, const UserData& userData);
|
void write_user_data(std::ostream& os,
|
||||||
UserData read_user_data(std::istream& is, const int docFormatVer = DOC_FORMAT_VERSION_LAST);
|
const UserData& userData);
|
||||||
|
|
||||||
|
UserData read_user_data(std::istream& is,
|
||||||
|
SerialFormat serial = SerialFormat::LastVer);
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user