mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 03:32:48 +00:00
Convert the tileset serialization format in its own type
To match the new SerialFormat enum (uint16_t), we now have TilesetSerialFormat enum (uint8_t).
This commit is contained in:
parent
cdea6004bd
commit
abe872aeb2
@ -523,9 +523,9 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tileset* readTileset(std::ifstream& s) {
|
Tileset* readTileset(std::ifstream& s) {
|
||||||
uint32_t tilesetVer;
|
TilesetSerialFormat tilesetVer = TilesetSerialFormat::Ver0;
|
||||||
Tileset* tileset = read_tileset(s, m_sprite, false, &tilesetVer, m_serial);
|
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());
|
m_updateOldTilemapWithTileset.insert(tileset->id());
|
||||||
return tileset;
|
return tileset;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ bool write_tileset(std::ostream& os,
|
|||||||
write_image(os, tileset->get(ti).get(), cancel);
|
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_user_data(os, tileset->userData());
|
||||||
write_string(os, tileset->name());
|
write_string(os, tileset->name());
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ bool write_tileset(std::ostream& os,
|
|||||||
Tileset* read_tileset(std::istream& is,
|
Tileset* read_tileset(std::istream& is,
|
||||||
Sprite* sprite,
|
Sprite* sprite,
|
||||||
const bool setId,
|
const bool setId,
|
||||||
uint32_t* tilesetVer,
|
TilesetSerialFormat* tilesetVer,
|
||||||
const SerialFormat serial)
|
const SerialFormat serial)
|
||||||
{
|
{
|
||||||
const ObjectId id = read32(is);
|
const ObjectId id = read32(is);
|
||||||
@ -74,17 +74,17 @@ Tileset* read_tileset(std::istream& is,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read extra version byte after tiles
|
// Read extra version byte after tiles
|
||||||
const uint32_t ver = read8(is);
|
const auto ver = TilesetSerialFormat(read8(is));
|
||||||
if (tilesetVer)
|
if (tilesetVer)
|
||||||
*tilesetVer = ver;
|
*tilesetVer = ver;
|
||||||
if (ver >= TILESET_VER1) {
|
if (ver >= TilesetSerialFormat::Ver1) {
|
||||||
tileset->setBaseIndex(1);
|
tileset->setBaseIndex(1);
|
||||||
|
|
||||||
if (ver >= TILESET_VER2) {
|
if (ver >= TilesetSerialFormat::Ver2) {
|
||||||
const UserData userData = read_user_data(is, serial);
|
const UserData userData = read_user_data(is, serial);
|
||||||
tileset->setUserData(userData);
|
tileset->setUserData(userData);
|
||||||
|
|
||||||
if (ver >= TILESET_VER3) {
|
if (ver >= TilesetSerialFormat::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) {
|
||||||
|
@ -13,19 +13,27 @@
|
|||||||
|
|
||||||
#include <iosfwd>
|
#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
|
|
||||||
|
|
||||||
// Tileset has UserData now
|
|
||||||
#define TILESET_VER2 2
|
|
||||||
|
|
||||||
// Tileset name (was missing originally) + each tileset's tile has
|
|
||||||
// UserData now
|
|
||||||
#define TILESET_VER3 3
|
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
|
||||||
|
// Extra BYTE with special flags to check the tileset version.
|
||||||
|
Ver1 = 1,
|
||||||
|
|
||||||
|
// 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 CancelIO;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Tileset;
|
class Tileset;
|
||||||
@ -37,7 +45,7 @@ namespace doc {
|
|||||||
Tileset* read_tileset(std::istream& is,
|
Tileset* read_tileset(std::istream& is,
|
||||||
Sprite* sprite,
|
Sprite* sprite,
|
||||||
bool setId = true,
|
bool setId = true,
|
||||||
uint32_t* tilesetVer = nullptr,
|
TilesetSerialFormat* tilesetSerial = nullptr,
|
||||||
SerialFormat serial = SerialFormat::LastVer);
|
SerialFormat serial = SerialFormat::LastVer);
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user