[nostalgia/core/studio] Make TileSheets use UUIDs to refer to Palettes
This commit is contained in:
parent
71354fcbbc
commit
b53e8626d7
@ -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<ox::BString<43>>("uuid://{}", newPalette));
|
||||
}
|
||||
|
||||
void redo() noexcept final {
|
||||
@ -597,12 +597,27 @@ void TileSheetEditorModel::paste() {
|
||||
pushCommand(ox::make<CutPasteCommand<CommandId::Paste>>(&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<PaletteChangeCommand>(activeSubSheetIdx(), &m_img, path));
|
||||
oxRequire(uuid, m_ctx->pathToUuid.at(path));
|
||||
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), &m_img, uuid->toString()));
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user