Merge commit '0d61e5a064382a7076b62d32b25c70298ee0706e'
This commit is contained in:
commit
dbcd37d7ea
@ -73,7 +73,7 @@ struct TileSheetSetEntrySection {
|
||||
|
||||
oxModelBegin(TileSheetSetEntrySection)
|
||||
oxModelField(begin)
|
||||
oxModelField(size)
|
||||
oxModelField(tiles)
|
||||
oxModelEnd()
|
||||
|
||||
struct TileSheetSetEntry {
|
||||
@ -92,7 +92,7 @@ struct TileSheetSet {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSet";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
static constexpr auto Preloadable = true;
|
||||
int bpp = 0;
|
||||
int32_t bpp = 0;
|
||||
ox::Vector<TileSheetSetEntry> entries;
|
||||
};
|
||||
|
||||
@ -101,6 +101,8 @@ oxModelBegin(TileSheetSet)
|
||||
oxModelField(entries)
|
||||
oxModelEnd()
|
||||
|
||||
void addEntry(TileSheetSet &set, ox::FileAddress path, int32_t begin = 0, int32_t size = -1) noexcept;
|
||||
|
||||
ox::Error loadBgPalette(
|
||||
Context &ctx,
|
||||
size_t palBank,
|
||||
|
@ -60,6 +60,15 @@ constexpr size_t colors(Palette const&pal, size_t page = 0) noexcept {
|
||||
return 0;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr size_t largestPage(Palette const&pal) noexcept {
|
||||
size_t out{};
|
||||
for (auto const&page : pal.pages) {
|
||||
out = ox::max(out, page.size());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
oxModelBegin(NostalgiaPalette)
|
||||
oxModelField(colors)
|
||||
oxModelEnd()
|
||||
|
@ -159,7 +159,10 @@ struct TileSheet {
|
||||
std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept;
|
||||
size_t getTileCnt(TileSheet const&ts) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId id) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
size_t getTileIdx(TileSheet const&ts, SubSheetId id) noexcept;
|
||||
|
@ -30,6 +30,17 @@ Palette const TileSheetEditorModel::s_defaultPalette = {
|
||||
.pages = {ox::Vector<Color16>(128)},
|
||||
};
|
||||
|
||||
// delete pixels of all non-leaf nodes
|
||||
static void normalizeSubsheets(TileSheet::SubSheet &ss) noexcept {
|
||||
if (ss.subsheets.empty()) {
|
||||
for (auto &child : ss.subsheets) {
|
||||
normalizeSubsheets(child);
|
||||
}
|
||||
} else {
|
||||
ss.pixels.clear();
|
||||
}
|
||||
}
|
||||
|
||||
TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack):
|
||||
m_ctx(ctx),
|
||||
m_path(path),
|
||||
@ -37,6 +48,7 @@ TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView
|
||||
// ignore failure to load palette
|
||||
m_pal(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).value),
|
||||
m_undoStack(undoStack) {
|
||||
normalizeSubsheets(m_img.subsheet);
|
||||
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
|
||||
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
|
||||
}
|
||||
|
@ -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<size_t> getPixelIdx(
|
||||
if (auto out = getPixelIdx(child, id, idx, bpp)) {
|
||||
return out;
|
||||
}
|
||||
idx += pixelCnt(ss, bpp);
|
||||
idx += pixelCnt(child, bpp);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@ -284,10 +284,6 @@ class AssetRef {
|
||||
return *m_obj;
|
||||
}
|
||||
|
||||
constexpr T const&&operator*() const && noexcept {
|
||||
return *m_obj;
|
||||
}
|
||||
|
||||
constexpr T const*operator->() const noexcept {
|
||||
return m_obj;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user