diff --git a/src/nostalgia/modules/core/src/tilesheet.cpp b/src/nostalgia/modules/core/src/tilesheet.cpp index 67b2c2e0..58ebc156 100644 --- a/src/nostalgia/modules/core/src/tilesheet.cpp +++ b/src/nostalgia/modules/core/src/tilesheet.cpp @@ -14,6 +14,7 @@ std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept { return ptToIdx(pt, ss.columns); } +[[nodiscard]] static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSheetId const id) noexcept { if (ss.id == id) { return &ss; @@ -26,6 +27,24 @@ static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSh return {}; } +[[nodiscard]] +static size_t getTileCnt(TileSheet::SubSheet const&ss, int const bpp) noexcept { + if (ss.subsheets.empty()) { + auto const bytesPerTile = bpp == 4 ? 32u : 64u; + return ss.pixels.size() / bytesPerTile; + } else { + size_t out{}; + for (auto const&child : ss.subsheets) { + out += getTileCnt(child, bpp); + } + return out; + } +} + +size_t getTileCnt(TileSheet const&ts) noexcept { + return getTileCnt(ts.subsheet, ts.bpp); +} + TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept { return getSubsheet(ts.subsheet, id); } @@ -42,7 +61,7 @@ static ox::Optional getPixelIdx( if (auto out = getPixelIdx(child, id, idx, bpp)) { return out; } - idx += pixelCnt(ss, bpp); + idx += pixelCnt(child, bpp); } return {}; }