[jasper/world/studio] Make ObjectSetEditor use UUIDs

This commit is contained in:
Gary Talent 2024-05-27 00:55:41 -05:00
parent aa89f20ed6
commit 55a747f6a1

View File

@ -29,8 +29,11 @@ WorldObjectSetEditorImGui::WorldObjectSetEditorImGui(
m_doc(*readObj<WorldObjectSet>(keelCtx(ctx.tctx), path).unwrapThrow()), m_doc(*readObj<WorldObjectSet>(keelCtx(ctx.tctx), path).unwrapThrow()),
m_tileSheet(readObj<ncore::TileSheet>(keelCtx(m_sctx.tctx), m_doc.tilesheet).unwrapThrow()) { m_tileSheet(readObj<ncore::TileSheet>(keelCtx(m_sctx.tctx), m_doc.tilesheet).unwrapThrow()) {
auto const&tilesheetList = m_sctx.project->fileList(ncore::FileExt_ng); auto const&tilesheetList = m_sctx.project->fileList(ncore::FileExt_ng);
auto const tsPath = m_doc.tilesheet.getPath().or_value(""); auto &kctx = keelCtx(m_sctx.tctx);
m_selectedTilesheetIdx = std::find(tilesheetList.begin(), tilesheetList.end(), tsPath).offset(); auto const [tsPath, err] = getPath(kctx, m_doc.tilesheet);
if (err) {
m_selectedTilesheetIdx = std::find(tilesheetList.begin(), tilesheetList.end(), tsPath).offset();
}
loadObj(); loadObj();
undoStack()->changeTriggered.connect(this, &WorldObjectSetEditorImGui::handleCmd); undoStack()->changeTriggered.connect(this, &WorldObjectSetEditorImGui::handleCmd);
buildPaletteDisplayNameList(); buildPaletteDisplayNameList();
@ -81,7 +84,7 @@ WorldObject &WorldObjectSetEditorImGui::activeObj() noexcept {
void WorldObjectSetEditorImGui::buildPaletteDisplayNameList() noexcept { void WorldObjectSetEditorImGui::buildPaletteDisplayNameList() noexcept {
m_paletteDisplayNames.clear(); m_paletteDisplayNames.clear();
for (auto i = 1u; auto const&pal : m_doc.palettes) { 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)); m_paletteDisplayNames.emplace_back(ox::sfmt("{}: {} - {} ms", i, path, pal.intervalMs));
++i; ++i;
} }
@ -91,9 +94,14 @@ void WorldObjectSetEditorImGui::drawTileSheetSelector() noexcept {
auto const&tilesheetList = m_sctx.project->fileList(ncore::FileExt_ng); auto const&tilesheetList = m_sctx.project->fileList(ncore::FileExt_ng);
auto sel = m_selectedTilesheetIdx; auto sel = m_selectedTilesheetIdx;
if (ig::ComboBox("Tile Sheet", tilesheetList, sel)) { if (ig::ComboBox("Tile Sheet", tilesheetList, sel)) {
std::ignore = undoStack()->push(ox::make_unique<ChangeTileSheet> auto const [uuid, err] = keel::pathToUuid(
(m_doc, ox::FileAddress(tilesheetList[sel]), sel, m_selectedTilesheetIdx)); keelCtx(m_sctx.tctx), tilesheetList[m_addPalPopup.selectedIdx]);
loadObj(); if (!err) {
auto const uuidUrl = ox::sfmt("uuid://{}", uuid.toString());
std::ignore = undoStack()->push(ox::make_unique<ChangeTileSheet>
(m_doc, ox::FileAddress(uuidUrl), sel, m_selectedTilesheetIdx));
loadObj();
}
} }
} }
@ -205,7 +213,8 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept {
auto &obj = activeObj(); auto &obj = activeObj();
auto intermediate = obj.collisionMap; auto intermediate = obj.collisionMap;
if (m_colView.click(mousePos, intermediate)) { if (m_colView.click(mousePos, intermediate)) {
std::ignore = undoStack()->push(ox::make_unique<EditObjectCollisionMap>(m_doc, m_selectedObj, intermediate)); std::ignore = undoStack()->push(ox::make_unique<EditObjectCollisionMap>(
m_doc, m_selectedObj, intermediate));
} }
} }
} }
@ -259,7 +268,9 @@ void WorldObjectSetEditorImGui::drawPaletteListItems() noexcept {
ig::IDStackItem const idStackItem(static_cast<int>(i)); ig::IDStackItem const idStackItem(static_cast<int>(i));
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); 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::TableNextColumn();
ImGui::Text("%d ms", pal.intervalMs); ImGui::Text("%d ms", pal.intervalMs);
ImGui::SameLine(); ImGui::SameLine();
@ -284,9 +295,13 @@ void WorldObjectSetEditorImGui::drawAddPalettePopup() noexcept {
auto const&palettes = m_sctx.project->fileList(ncore::FileExt_npal); auto const&palettes = m_sctx.project->fileList(ncore::FileExt_npal);
ig::ComboBox("Palette", palettes, m_addPalPopup.selectedIdx); ig::ComboBox("Palette", palettes, m_addPalPopup.selectedIdx);
if (ig::PopupControlsOkCancel(popupSz.x, m_addPalPopup.show) == ig::PopupResponse::OK) { if (ig::PopupControlsOkCancel(popupSz.x, m_addPalPopup.show) == ig::PopupResponse::OK) {
std::ignore = undoStack()->push(ox::make_unique<AddPalette>( auto [uuid, err] = keel::pathToUuid(
m_doc, keelCtx(m_sctx.tctx), palettes[m_addPalPopup.selectedIdx]);
ox::FileAddress(palettes[m_addPalPopup.selectedIdx]))); if (!err) {
auto const uuidUrl = ox::sfmt("uuid://{}", uuid.toString());
std::ignore = undoStack()->push(ox::make_unique<AddPalette>(
m_doc, ox::FileAddress(uuidUrl)));
}
} }
ImGui::EndPopup(); ImGui::EndPopup();
} }
@ -330,14 +345,14 @@ void WorldObjectSetEditorImGui::editPalette() noexcept {
ox::Error WorldObjectSetEditorImGui::handleCmd(studio::UndoCommand const*cmd) noexcept { ox::Error WorldObjectSetEditorImGui::handleCmd(studio::UndoCommand const*cmd) noexcept {
if (dynamic_cast<ChangeTileSheet const*>(cmd)) { if (dynamic_cast<ChangeTileSheet const*>(cmd)) {
oxLogError(readObj<ncore::TileSheet>(keelCtx(m_sctx.tctx), m_doc.tilesheet).moveTo(m_tileSheet)); auto &kctx = keelCtx(m_sctx.tctx);
} oxLogError(readObj<ncore::TileSheet>(kctx, m_doc.tilesheet).moveTo(m_tileSheet));
if (dynamic_cast<AddPalette const*>(cmd) || } else if (
dynamic_cast<AddPalette const*>(cmd) ||
dynamic_cast<RmPalette const*>(cmd) || dynamic_cast<RmPalette const*>(cmd) ||
dynamic_cast<EditPalette const*>(cmd)) { dynamic_cast<EditPalette const*>(cmd)) {
buildPaletteDisplayNameList(); buildPaletteDisplayNameList();
} } else if (dynamic_cast<EditObjectPalette const*>(cmd)) {
if (dynamic_cast<EditObjectPalette const*>(cmd)) {
auto const&obj = activeObj(); auto const&obj = activeObj();
m_objEditor.palette = obj.palBank; m_objEditor.palette = obj.palBank;
} }