Skip to content

Commit

Permalink
Convert the tileset serialization format in its own type
Browse files Browse the repository at this point in the history
To match the new SerialFormat enum (uint16_t), we now have
TilesetSerialFormat enum (uint8_t).
  • Loading branch information
dacap committed Jun 26, 2024
1 parent cdea600 commit abe872a
Showing 3 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/app/crash/read_document.cpp
Original file line number Diff line number Diff line change
@@ -523,9 +523,9 @@ class Reader : public SubObjectsIO {
}

Tileset* readTileset(std::ifstream& s) {
uint32_t tilesetVer;
TilesetSerialFormat tilesetVer = TilesetSerialFormat::Ver0;
Tileset* tileset = read_tileset(s, m_sprite, false, &tilesetVer, m_serial);
if (tileset && tilesetVer < TILESET_VER1)
if (tileset && tilesetVer < TilesetSerialFormat::Ver1)
m_updateOldTilemapWithTileset.insert(tileset->id());
return tileset;
}
12 changes: 6 additions & 6 deletions src/doc/tileset_io.cpp
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ bool write_tileset(std::ostream& os,
write_image(os, tileset->get(ti).get(), cancel);
}

write8(os, TILESET_VER3);
write8(os, uint8_t(TilesetSerialFormat::LastVer));
write_user_data(os, tileset->userData());
write_string(os, tileset->name());

@@ -58,7 +58,7 @@ bool write_tileset(std::ostream& os,
Tileset* read_tileset(std::istream& is,
Sprite* sprite,
const bool setId,
uint32_t* tilesetVer,
TilesetSerialFormat* tilesetVer,
const SerialFormat serial)
{
const ObjectId id = read32(is);
@@ -74,17 +74,17 @@ Tileset* read_tileset(std::istream& is,
}

// Read extra version byte after tiles
const uint32_t ver = read8(is);
const auto ver = TilesetSerialFormat(read8(is));
if (tilesetVer)
*tilesetVer = ver;
if (ver >= TILESET_VER1) {
if (ver >= TilesetSerialFormat::Ver1) {
tileset->setBaseIndex(1);

if (ver >= TILESET_VER2) {
if (ver >= TilesetSerialFormat::Ver2) {
const UserData userData = read_user_data(is, serial);
tileset->setUserData(userData);

if (ver >= TILESET_VER3) {
if (ver >= TilesetSerialFormat::Ver3) {
tileset->setName(read_string(is));

for (tileset_index ti=0; ti<ntiles; ++ti) {
28 changes: 18 additions & 10 deletions src/doc/tileset_io.h
Original file line number Diff line number Diff line change
@@ -13,18 +13,26 @@

#include <iosfwd>

// Extra BYTE with special flags to check the tileset version. This
// field didn't exist in Aseprite v1.3-alpha3 (so read8() fails = 0)
#define TILESET_VER1 1
namespace doc {

// Tileset has UserData now
#define TILESET_VER2 2
// Tileset serialization format. This field didn't exist in Aseprite
// v1.3-alpha3 (so read8() fails = 0)
enum class TilesetSerialFormat : uint8_t {
// Without version field.
Ver0 = 0,

// Tileset name (was missing originally) + each tileset's tile has
// UserData now
#define TILESET_VER3 3
// Extra BYTE with special flags to check the tileset version.
Ver1 = 1,

namespace doc {
// Tileset has UserData now.
Ver2 = 2,

// Tileset name (was missing originally) + each tileset's tile has
// UserData now.
Ver3 = 3,

LastVer = Ver3
};

class CancelIO;
class Sprite;
@@ -37,7 +45,7 @@ namespace doc {
Tileset* read_tileset(std::istream& is,
Sprite* sprite,
bool setId = true,
uint32_t* tilesetVer = nullptr,
TilesetSerialFormat* tilesetSerial = nullptr,
SerialFormat serial = SerialFormat::LastVer);

} // namespace doc

0 comments on commit abe872a

Please sign in to comment.