From 55a747f6a152a9d027be644a6709f55d7eca326e Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 27 May 2024 00:55:41 -0500 Subject: [PATCH] [jasper/world/studio] Make ObjectSetEditor use UUIDs --- .../worldobjectseteditor-imgui.cpp | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp index 149d50d..a31e7e8 100644 --- a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp @@ -29,8 +29,11 @@ WorldObjectSetEditorImGui::WorldObjectSetEditorImGui( m_doc(*readObj(keelCtx(ctx.tctx), path).unwrapThrow()), m_tileSheet(readObj(keelCtx(m_sctx.tctx), m_doc.tilesheet).unwrapThrow()) { auto const&tilesheetList = m_sctx.project->fileList(ncore::FileExt_ng); - auto const tsPath = m_doc.tilesheet.getPath().or_value(""); - m_selectedTilesheetIdx = std::find(tilesheetList.begin(), tilesheetList.end(), tsPath).offset(); + auto &kctx = keelCtx(m_sctx.tctx); + auto const [tsPath, err] = getPath(kctx, m_doc.tilesheet); + if (err) { + m_selectedTilesheetIdx = std::find(tilesheetList.begin(), tilesheetList.end(), tsPath).offset(); + } loadObj(); undoStack()->changeTriggered.connect(this, &WorldObjectSetEditorImGui::handleCmd); buildPaletteDisplayNameList(); @@ -81,7 +84,7 @@ WorldObject &WorldObjectSetEditorImGui::activeObj() noexcept { void WorldObjectSetEditorImGui::buildPaletteDisplayNameList() noexcept { m_paletteDisplayNames.clear(); for (auto i = 1u; auto const&pal : m_doc.palettes) { - auto path = pal.palette.getPath().or_value("n/a"); + auto const path = keel::getPath(keelCtx(m_sctx.tctx), pal.palette).or_value("Invalid path"); m_paletteDisplayNames.emplace_back(ox::sfmt("{}: {} - {} ms", i, path, pal.intervalMs)); ++i; } @@ -91,9 +94,14 @@ void WorldObjectSetEditorImGui::drawTileSheetSelector() noexcept { auto const&tilesheetList = m_sctx.project->fileList(ncore::FileExt_ng); auto sel = m_selectedTilesheetIdx; if (ig::ComboBox("Tile Sheet", tilesheetList, sel)) { - std::ignore = undoStack()->push(ox::make_unique - (m_doc, ox::FileAddress(tilesheetList[sel]), sel, m_selectedTilesheetIdx)); - loadObj(); + auto const [uuid, err] = keel::pathToUuid( + keelCtx(m_sctx.tctx), tilesheetList[m_addPalPopup.selectedIdx]); + if (!err) { + auto const uuidUrl = ox::sfmt("uuid://{}", uuid.toString()); + std::ignore = undoStack()->push(ox::make_unique + (m_doc, ox::FileAddress(uuidUrl), sel, m_selectedTilesheetIdx)); + loadObj(); + } } } @@ -205,7 +213,8 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept { auto &obj = activeObj(); auto intermediate = obj.collisionMap; if (m_colView.click(mousePos, intermediate)) { - std::ignore = undoStack()->push(ox::make_unique(m_doc, m_selectedObj, intermediate)); + std::ignore = undoStack()->push(ox::make_unique( + m_doc, m_selectedObj, intermediate)); } } } @@ -259,7 +268,9 @@ void WorldObjectSetEditorImGui::drawPaletteListItems() noexcept { ig::IDStackItem const idStackItem(static_cast(i)); ImGui::TableNextRow(); ImGui::TableNextColumn(); - ImGui::Text("%s", pal.palette.getPath().value.c_str()); + auto const path + = keel::getPath(keelCtx(m_sctx.tctx), pal.palette).or_value("Invalid path"); + ImGui::Text("%s", path.c_str()); ImGui::TableNextColumn(); ImGui::Text("%d ms", pal.intervalMs); ImGui::SameLine(); @@ -284,9 +295,13 @@ void WorldObjectSetEditorImGui::drawAddPalettePopup() noexcept { auto const&palettes = m_sctx.project->fileList(ncore::FileExt_npal); ig::ComboBox("Palette", palettes, m_addPalPopup.selectedIdx); if (ig::PopupControlsOkCancel(popupSz.x, m_addPalPopup.show) == ig::PopupResponse::OK) { - std::ignore = undoStack()->push(ox::make_unique( - m_doc, - ox::FileAddress(palettes[m_addPalPopup.selectedIdx]))); + auto [uuid, err] = keel::pathToUuid( + keelCtx(m_sctx.tctx), palettes[m_addPalPopup.selectedIdx]); + if (!err) { + auto const uuidUrl = ox::sfmt("uuid://{}", uuid.toString()); + std::ignore = undoStack()->push(ox::make_unique( + m_doc, ox::FileAddress(uuidUrl))); + } } ImGui::EndPopup(); } @@ -330,14 +345,14 @@ void WorldObjectSetEditorImGui::editPalette() noexcept { ox::Error WorldObjectSetEditorImGui::handleCmd(studio::UndoCommand const*cmd) noexcept { if (dynamic_cast(cmd)) { - oxLogError(readObj(keelCtx(m_sctx.tctx), m_doc.tilesheet).moveTo(m_tileSheet)); - } - if (dynamic_cast(cmd) || + auto &kctx = keelCtx(m_sctx.tctx); + oxLogError(readObj(kctx, m_doc.tilesheet).moveTo(m_tileSheet)); + } else if ( + dynamic_cast(cmd) || dynamic_cast(cmd) || dynamic_cast(cmd)) { buildPaletteDisplayNameList(); - } - if (dynamic_cast(cmd)) { + } else if (dynamic_cast(cmd)) { auto const&obj = activeObj(); m_objEditor.palette = obj.palBank; }