mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-07 01:20:22 +00:00
This fixes a violation of module layers (circular dependency) introduced in e6cd13d7e13775de2a687e55e59819cb7f19e7e9 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
85 lines
1.9 KiB
C++
85 lines
1.9 KiB
C++
// Aseprite Document Library
|
|
// Copyright (C) 2019 Igara Studio S.A.
|
|
//
|
|
// This file is released under the terms of the MIT license.
|
|
// Read LICENSE.txt for more information.
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include "doc/grid_io.h"
|
|
|
|
#include "base/serialization.h"
|
|
#include "doc/image.h"
|
|
#include "doc/image_io.h"
|
|
#include "doc/grid.h"
|
|
|
|
#include <iostream>
|
|
|
|
namespace doc {
|
|
|
|
using namespace base::serialization;
|
|
using namespace base::serialization::little_endian;
|
|
|
|
bool write_grid(std::ostream& os, const Grid& grid)
|
|
{
|
|
write32(os, grid.tileSize().w);
|
|
write32(os, grid.tileSize().h);
|
|
write32(os, grid.origin().x);
|
|
write32(os, grid.origin().y);
|
|
write32(os, grid.tileCenter().x);
|
|
write32(os, grid.tileCenter().y);
|
|
write32(os, grid.tileOffset().x);
|
|
write32(os, grid.tileOffset().y);
|
|
write32(os, grid.oddRowOffset().x);
|
|
write32(os, grid.oddRowOffset().y);
|
|
write32(os, grid.oddColOffset().x);
|
|
write32(os, grid.oddColOffset().y);
|
|
write8(os, grid.hasMask());
|
|
if (grid.hasMask())
|
|
return write_image(os, grid.mask().get());
|
|
else
|
|
return true;
|
|
}
|
|
|
|
Grid read_grid(std::istream& is)
|
|
{
|
|
gfx::Size tileSize;
|
|
gfx::Point origin;
|
|
gfx::Point tileCenter;
|
|
gfx::Point tileOffset;
|
|
gfx::Point oddRowOffset;
|
|
gfx::Point oddColOffset;
|
|
tileSize.w = read32(is);
|
|
tileSize.h = read32(is);
|
|
origin.x = read32(is);
|
|
origin.y = read32(is);
|
|
tileCenter.x = read32(is);
|
|
tileCenter.y = read32(is);
|
|
tileOffset.x = read32(is);
|
|
tileOffset.y = read32(is);
|
|
oddRowOffset.x = read32(is);
|
|
oddRowOffset.y = read32(is);
|
|
oddColOffset.x = read32(is);
|
|
oddColOffset.y = read32(is);
|
|
bool hasMask = read8(is);
|
|
|
|
Grid grid;
|
|
grid.tileSize(tileSize);
|
|
grid.origin(origin);
|
|
grid.tileCenter(tileCenter);
|
|
grid.tileOffset(tileOffset);
|
|
grid.oddRowOffset(oddRowOffset);
|
|
grid.oddColOffset(oddColOffset);
|
|
|
|
if (hasMask) {
|
|
ImageRef mask(read_image(is));
|
|
if (mask)
|
|
grid.setMask(mask);
|
|
}
|
|
return grid;
|
|
}
|
|
|
|
} // namespace doc
|