[nostalgia/gfx] Make TileSheetV5::defaultPalette a string instead of FileAddress

This commit is contained in:
Gary Talent 2025-01-21 22:44:55 -06:00
parent cda23ac4af
commit 9fda2763ba
5 changed files with 12 additions and 11 deletions

View File

@ -339,9 +339,13 @@ struct TileSheetV5 {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.TileSheet"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.TileSheet";
static constexpr auto TypeVersion = 5; static constexpr auto TypeVersion = 5;
/**
* bpp is unused for TileSheet, but it does get used in CompactTileSheet.
* All pixel in TileSheet are 8 bpp, regardless of what the bpp field says.
*/
int8_t bpp = 4; int8_t bpp = 4;
SubSheetId idIt = 0; SubSheetId idIt = 0;
ox::FileAddress defaultPalette; ox::String defaultPalette;
SubSheet subsheet{0, "Root", 1, 1}; SubSheet subsheet{0, "Root", 1, 1};
}; };

View File

@ -185,7 +185,7 @@ ox::Error TileSheetV4ToTileSheetV5Converter::convert(
TileSheetV5 &dst) const noexcept { TileSheetV5 &dst) const noexcept {
dst.bpp = src.bpp; dst.bpp = src.bpp;
dst.idIt = src.idIt; dst.idIt = src.idIt;
dst.defaultPalette = std::move(src.defaultPalette); OX_RETURN_ERROR(src.defaultPalette.getPath().moveTo(dst.defaultPalette));
convertSubsheet(dst.bpp, src.subsheet, dst.subsheet); convertSubsheet(dst.bpp, src.subsheet, dst.subsheet);
return {}; return {};
} }
@ -196,7 +196,7 @@ ox::Error TileSheetToCompactTileSheetConverter::convert(
TileSheet &src, TileSheet &src,
CompactTileSheet &dst) const noexcept { CompactTileSheet &dst) const noexcept {
dst.bpp = src.bpp; dst.bpp = src.bpp;
dst.defaultPalette = std::move(src.defaultPalette); dst.defaultPalette = ox::FileAddress{src.defaultPalette};
dst.pixels = pixels(src); dst.pixels = pixels(src);
return {}; return {};
} }

View File

@ -13,7 +13,7 @@ gfx::PaletteChangeCommand::PaletteChangeCommand(
m_img(img), m_img(img),
m_idx(std::move(idx)), m_idx(std::move(idx)),
m_oldPalette(m_img.defaultPalette), m_oldPalette(m_img.defaultPalette),
m_newPalette(ox::FileAddress(ox::sfmt<ox::IString<43>>("uuid://{}", newPalette))) { m_newPalette(ox::sfmt<ox::IString<43>>("uuid://{}", newPalette)) {
} }
ox::Error PaletteChangeCommand::redo() noexcept { ox::Error PaletteChangeCommand::redo() noexcept {

View File

@ -12,8 +12,8 @@ class PaletteChangeCommand: public TileSheetCommand {
private: private:
TileSheet &m_img; TileSheet &m_img;
TileSheet::SubSheetIdx m_idx; TileSheet::SubSheetIdx m_idx;
ox::FileAddress m_oldPalette; ox::String m_oldPalette;
ox::FileAddress m_newPalette; ox::String m_newPalette;
public: public:
PaletteChangeCommand( PaletteChangeCommand(

View File

@ -118,13 +118,10 @@ bool TileSheetEditorModel::acceptsClipboardPayload() const noexcept {
} }
ox::StringView TileSheetEditorModel::palPath() const noexcept { ox::StringView TileSheetEditorModel::palPath() const noexcept {
auto [path, err] = m_img.defaultPalette.getPath(); auto &path = m_img.defaultPalette;
if (err) {
return {};
}
constexpr ox::StringView uuidPrefix = "uuid://"; constexpr ox::StringView uuidPrefix = "uuid://";
if (ox::beginsWith(path, uuidPrefix)) { if (ox::beginsWith(path, uuidPrefix)) {
auto const uuid = ox::StringView(&path[uuidPrefix.bytes()], path.bytes() - uuidPrefix.bytes()); auto const uuid = substr(path, uuidPrefix.bytes());
auto const out = keelCtx(m_tctx).uuidToPath.at(uuid); auto const out = keelCtx(m_tctx).uuidToPath.at(uuid);
if (out.error) { if (out.error) {
return {}; return {};