From b53e8626d7af319b11b85a006ffa515911297eac Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 14 Feb 2023 00:45:40 -0600 Subject: [PATCH] [nostalgia/core/studio] Make TileSheets use UUIDs to refer to Palettes --- .../core/studio/tilesheeteditormodel.cpp | 25 +++++++++++++++---- .../core/studio/tilesheeteditormodel.hpp | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index f9592e6f..739d7c13 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.cpp @@ -507,11 +507,11 @@ class PaletteChangeCommand: public TileSheetCommand { ox::FileAddress m_newPalette; 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_img = img; m_oldPalette = m_img->defaultPalette; - m_newPalette = ox::FileAddress(newPalette); + m_newPalette = ox::FileAddress(ox::sfmt>("uuid://{}", newPalette)); } void redo() noexcept final { @@ -597,12 +597,27 @@ void TileSheetEditorModel::paste() { pushCommand(ox::make>(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb)); } -const ox::FileAddress &TileSheetEditorModel::palPath() const noexcept { - return m_img.defaultPalette; +ox::StringView TileSheetEditorModel::palPath() const noexcept { + 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 { - pushCommand(ox::make(activeSubSheetIdx(), &m_img, path)); + oxRequire(uuid, m_ctx->pathToUuid.at(path)); + pushCommand(ox::make(activeSubSheetIdx(), &m_img, uuid->toString())); return OxError(0); } diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.hpp b/src/nostalgia/core/studio/tilesheeteditormodel.hpp index 25094bd8..04f2db6f 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.hpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.hpp @@ -54,7 +54,7 @@ class TileSheetEditorModel: public ox::SignalHandler { constexpr const Palette *pal() const noexcept; [[nodiscard]] - const ox::FileAddress &palPath() const noexcept; + ox::StringView palPath() const noexcept; ox::Error setPalette(const ox::String &path) noexcept;