[nostalgia/core/studio] Make TileSheets use UUIDs to refer to Palettes

This commit is contained in:
Gary Talent 2023-02-14 00:45:40 -06:00
parent 71354fcbbc
commit b53e8626d7
2 changed files with 21 additions and 6 deletions

View File

@ -507,11 +507,11 @@ class PaletteChangeCommand: public TileSheetCommand {
ox::FileAddress m_newPalette; ox::FileAddress m_newPalette;
public: public:
PaletteChangeCommand(const TileSheet::SubSheetIdx &idx, TileSheet *img, const ox::String &newPalette) noexcept { PaletteChangeCommand(const TileSheet::SubSheetIdx &idx, TileSheet *img, ox::CRStringView newPalette) noexcept {
m_idx = idx; m_idx = idx;
m_img = img; m_img = img;
m_oldPalette = m_img->defaultPalette; m_oldPalette = m_img->defaultPalette;
m_newPalette = ox::FileAddress(newPalette); m_newPalette = ox::FileAddress(ox::sfmt<ox::BString<43>>("uuid://{}", newPalette));
} }
void redo() noexcept final { void redo() noexcept final {
@ -597,12 +597,27 @@ void TileSheetEditorModel::paste() {
pushCommand(ox::make<CutPasteCommand<CommandId::Paste>>(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb)); pushCommand(ox::make<CutPasteCommand<CommandId::Paste>>(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb));
} }
const ox::FileAddress &TileSheetEditorModel::palPath() const noexcept { ox::StringView TileSheetEditorModel::palPath() const noexcept {
return m_img.defaultPalette; auto [path, err] = m_img.defaultPalette.getPath();
if (err) {
return {};
}
constexpr ox::StringView uuidPrefix = "uuid://";
if (ox::beginsWith(path, uuidPrefix)) {
auto uuid = ox::StringView(path + uuidPrefix.bytes(), ox_strlen(path) - uuidPrefix.bytes());
auto out = m_ctx->uuidToPath.at(uuid);
if (out.error) {
return {};
}
return *out.value;
} else {
return path;
}
} }
ox::Error TileSheetEditorModel::setPalette(const ox::String &path) noexcept { ox::Error TileSheetEditorModel::setPalette(const ox::String &path) noexcept {
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), &m_img, path)); oxRequire(uuid, m_ctx->pathToUuid.at(path));
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), &m_img, uuid->toString()));
return OxError(0); return OxError(0);
} }

View File

@ -54,7 +54,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
constexpr const Palette *pal() const noexcept; constexpr const Palette *pal() const noexcept;
[[nodiscard]] [[nodiscard]]
const ox::FileAddress &palPath() const noexcept; ox::StringView palPath() const noexcept;
ox::Error setPalette(const ox::String &path) noexcept; ox::Error setPalette(const ox::String &path) noexcept;