diff --git a/src/keel/media.hpp b/src/keel/media.hpp index 0f760a03..94e2012d 100644 --- a/src/keel/media.hpp +++ b/src/keel/media.hpp @@ -95,6 +95,25 @@ void createUuidMapping(Context *ctx, const ox::String &filePath, const ox::UUID ox::Error buildUuidMap(Context *ctx) noexcept; +template +ox::Result> setAsset(keel::Context *ctx, ox::StringView assetId, T const&asset) noexcept { +#ifndef OX_BARE_METAL + if (assetId.len() == 0) { + return OxError(1, "Invalid asset ID"); + } + ox::UUIDStr idStr; + if (assetId[0] == '/') { + const auto [id, err] = ctx->pathToUuid.at(assetId); + oxReturnError(err); + idStr = id->toString(); + assetId = idStr; + } + return ctx->assetManager.setAsset(assetId, asset); +#else + return OxError(1, "Not supported on this platform"); +#endif +} + template ox::Result> readObj( keel::Context *ctx, diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp index 4b9b7413..72504b2f 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp @@ -145,9 +145,7 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept { ox::Error PaletteEditorImGui::saveItem() noexcept { const auto sctx = applicationData(*m_ctx); - oxReturnError(sctx->project->writeObj(m_itemPath, &m_pal)); - oxReturnError(m_ctx->keelCtx.assetManager.setAsset(m_itemPath, m_pal)); - return {}; + return sctx->project->writeObj(m_itemPath, &m_pal); } } diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp index 9ea429bb..a5967a11 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp @@ -773,8 +773,7 @@ void TileSheetEditorModel::ackUpdate() noexcept { ox::Error TileSheetEditorModel::saveFile() noexcept { const auto sctx = applicationData(*m_ctx); - oxReturnError(sctx->project->writeObj(m_path, &m_img)); - return m_ctx->keelCtx.assetManager.setAsset(m_path, m_img).error; + return sctx->project->writeObj(m_path, &m_img); } bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept { diff --git a/src/studio/modlib/include/studio/project.hpp b/src/studio/modlib/include/studio/project.hpp index 22888369..42b0889d 100644 --- a/src/studio/modlib/include/studio/project.hpp +++ b/src/studio/modlib/include/studio/project.hpp @@ -125,8 +125,10 @@ ox::Error Project::writeObj(const ox::StringView &path, const T *obj, ox::ClawFo const auto typePath = ox::sfmt("/{}/{}", descPath, buildTypeId(*t)); oxReturnError(writeBuff(typePath, typeOut)); } + oxDebug(path); + oxReturnError(keel::setAsset(m_ctx, path, *obj)); fileUpdated.emit(path); - return OxError(0); + return {}; } template