[nostalgia/core] Fix TileSheet validation/repair to ensure pixels gets cleared if there are subsheets
Some checks failed
Build / build (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
This commit is contained in:
parent
db953dd0d1
commit
465fb06f76
@ -233,10 +233,12 @@ struct TileSheetV4 {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool valid(TileSheetV4::SubSheet const&ss, int bpp) noexcept {
|
constexpr bool valid(TileSheetV4::SubSheet const&ss, int bpp) noexcept {
|
||||||
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
||||||
return ox::all_of(ss.subsheets.begin(), ss.subsheets.end(),
|
return
|
||||||
[bpp, bytes](TileSheetV4::SubSheet const&s) {
|
(ss.pixels.empty() || ss.subsheets.empty()) &&
|
||||||
return bytes == s.pixels.size() && valid(s, bpp);
|
ox::all_of(ss.subsheets.begin(), ss.subsheets.end(),
|
||||||
});
|
[bpp, bytes](TileSheetV4::SubSheet const&s) {
|
||||||
|
return bytes == s.pixels.size() && valid(s, bpp);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
@ -245,8 +247,14 @@ constexpr bool valid(TileSheetV4 const&ts) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr void repair(TileSheetV4::SubSheet &ss, int bpp) noexcept {
|
constexpr void repair(TileSheetV4::SubSheet &ss, int bpp) noexcept {
|
||||||
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
if (ss.subsheets.empty()) {
|
||||||
ss.pixels.resize(bytes);
|
auto const bytes = static_cast<size_t>(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1);
|
||||||
|
ss.pixels.resize(bytes);
|
||||||
|
} else {
|
||||||
|
ss.pixels.clear();
|
||||||
|
ss.columns = -1;
|
||||||
|
ss.rows = -1;
|
||||||
|
}
|
||||||
for (auto &s : ss.subsheets) {
|
for (auto &s : ss.subsheets) {
|
||||||
repair(s, bpp);
|
repair(s, bpp);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user