diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index dd082365..5c0f9359 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -39,6 +39,13 @@ struct Palette { static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.Palette"; static constexpr auto TypeVersion = 1; ox::Vector colors = {}; + [[nodiscard]] + constexpr Color16 color(auto idx) const noexcept { + if (idx < colors.size()) [[likely]] { + return colors[idx]; + } + return 0; + } }; // Predecessor to TileSheet, kept for backward compatibility diff --git a/src/nostalgia/core/studio/tilesheetpixels.cpp b/src/nostalgia/core/studio/tilesheetpixels.cpp index 9bc0675b..f6d759b5 100644 --- a/src/nostalgia/core/studio/tilesheetpixels.cpp +++ b/src/nostalgia/core/studio/tilesheetpixels.cpp @@ -93,7 +93,7 @@ void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize) noexcept { m_bufferSet.elements.resize(pixels * VertexEboLength); // set pixels subSheet->walkPixels(m_model->img().bpp, [&](std::size_t i, uint8_t p) { - auto color = pal->colors[p]; + auto color = pal->color(p); const auto pt = idxToPt(static_cast(i), subSheet->columns); const auto fx = static_cast(pt.x); const auto fy = static_cast(pt.y);