[keel,nostalgia/core/studio] Fix asset update notifications

This commit is contained in:
Gary Talent 2023-07-15 17:30:26 -05:00
parent 9ceb1df49e
commit 4cf96878a9
4 changed files with 24 additions and 6 deletions

View File

@ -95,6 +95,25 @@ void createUuidMapping(Context *ctx, const ox::String &filePath, const ox::UUID
ox::Error buildUuidMap(Context *ctx) noexcept;
template<typename T>
ox::Result<AssetRef<T>> 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<typename T>
ox::Result<keel::AssetRef<T>> readObj(
keel::Context *ctx,

View File

@ -145,9 +145,7 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept {
ox::Error PaletteEditorImGui::saveItem() noexcept {
const auto sctx = applicationData<studio::StudioContext>(*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);
}
}

View File

@ -773,8 +773,7 @@ void TileSheetEditorModel::ackUpdate() noexcept {
ox::Error TileSheetEditorModel::saveFile() noexcept {
const auto sctx = applicationData<studio::StudioContext>(*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 {

View File

@ -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<typename T>