Fix bug undoing tileset deletion wasn't restoring its name correctly

Actually it looks like a long-standing bug in the write/read_tileset()
functions where tileset names aren't saved (so another bug fixed with
this change is that restoring a tileset from a crashes session/file,
will restore the tileset name correctly).
This commit is contained in:
David Capello 2023-01-13 18:54:31 -03:00
parent 705cc3af50
commit 11a3e634b1
2 changed files with 15 additions and 7 deletions

View File

@ -1,5 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2019-2023 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.
@ -14,6 +14,7 @@
#include "doc/cancel_io.h" #include "doc/cancel_io.h"
#include "doc/grid_io.h" #include "doc/grid_io.h"
#include "doc/image_io.h" #include "doc/image_io.h"
#include "doc/string_io.h"
#include "doc/subobjects_io.h" #include "doc/subobjects_io.h"
#include "doc/tileset.h" #include "doc/tileset.h"
#include "doc/user_data_io.h" #include "doc/user_data_io.h"
@ -28,6 +29,9 @@
// Tileset has UserData now // Tileset has UserData now
#define TILESET_VER2 2 #define TILESET_VER2 2
// Tileset name (was missing originally)
#define TILESET_VER3 3
namespace doc { namespace doc {
using namespace base::serialization; using namespace base::serialization;
@ -48,8 +52,9 @@ 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_VER2); write8(os, TILESET_VER3);
write_user_data(os, tileset->userData()); write_user_data(os, tileset->userData());
write_string(os, tileset->name());
return true; return true;
} }
@ -72,16 +77,18 @@ Tileset* read_tileset(std::istream& is,
// Read extra version byte after tiles // Read extra version byte after tiles
uint32_t ver = read8(is); uint32_t ver = read8(is);
if (ver == TILESET_VER1 || if (ver >= TILESET_VER1) {
ver == TILESET_VER2) {
if (isOldVersion) if (isOldVersion)
*isOldVersion = false; *isOldVersion = false;
tileset->setBaseIndex(1); tileset->setBaseIndex(1);
if (ver == TILESET_VER2) { if (ver >= TILESET_VER2) {
UserData userData = read_user_data(is); UserData userData = read_user_data(is);
tileset->setUserData(userData); tileset->setUserData(userData);
if (ver >= TILESET_VER3)
tileset->setName(read_string(is));
} }
} }
// Old tileset used in internal versions (this was added to recover // Old tileset used in internal versions (this was added to recover

View File

@ -67,12 +67,13 @@ do
-- Create a tileset passing a grid -- Create a tileset passing a grid
local tileset2 = spr:newTileset(Grid{0, 0 ,32, 32}) local tileset2 = spr:newTileset(Grid{0, 0 ,32, 32})
tileset2.name = "Tileset 2"
assert(#tileset2 == 1) assert(#tileset2 == 1)
assert(tileset2.grid.origin.x == 0) assert(tileset2.grid.origin.x == 0)
assert(tileset2.grid.origin.y == 0) assert(tileset2.grid.origin.y == 0)
assert(tileset2.grid.tileSize.width == 32) assert(tileset2.grid.tileSize.width == 32)
assert(tileset2.grid.tileSize.height == 32) assert(tileset2.grid.tileSize.height == 32)
assert(tileset2.name == "") assert(tileset2.name == "Tileset 2")
assert(#spr.tilesets == 2) assert(#spr.tilesets == 2)
-- Create a tileset passing a table and a number of tiles -- Create a tileset passing a table and a number of tiles
@ -114,7 +115,7 @@ do
assert(tileset2.grid.origin.y == 0) assert(tileset2.grid.origin.y == 0)
assert(tileset2.grid.tileSize.width == 32) assert(tileset2.grid.tileSize.width == 32)
assert(tileset2.grid.tileSize.height == 32) assert(tileset2.grid.tileSize.height == 32)
assert(tileset2.name == "") assert(tileset2.name == "Tileset 2")
end end
do do