[jasper/world/studio] Make ObjectSetEditor use UUIDs
This commit is contained in:
parent
aa89f20ed6
commit
55a747f6a1
@ -29,8 +29,11 @@ WorldObjectSetEditorImGui::WorldObjectSetEditorImGui(
|
||||
m_doc(*readObj<WorldObjectSet>(keelCtx(ctx.tctx), path).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 tsPath = m_doc.tilesheet.getPath().or_value("");
|
||||
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,10 +94,15 @@ 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)) {
|
||||
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<ChangeTileSheet>
|
||||
(m_doc, ox::FileAddress(tilesheetList[sel]), sel, m_selectedTilesheetIdx));
|
||||
(m_doc, ox::FileAddress(uuidUrl), sel, m_selectedTilesheetIdx));
|
||||
loadObj();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WorldObjectSetEditorImGui::drawObjSelector() noexcept {
|
||||
@ -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<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));
|
||||
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) {
|
||||
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<AddPalette>(
|
||||
m_doc,
|
||||
ox::FileAddress(palettes[m_addPalPopup.selectedIdx])));
|
||||
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<ChangeTileSheet const*>(cmd)) {
|
||||
oxLogError(readObj<ncore::TileSheet>(keelCtx(m_sctx.tctx), m_doc.tilesheet).moveTo(m_tileSheet));
|
||||
}
|
||||
if (dynamic_cast<AddPalette const*>(cmd) ||
|
||||
auto &kctx = keelCtx(m_sctx.tctx);
|
||||
oxLogError(readObj<ncore::TileSheet>(kctx, m_doc.tilesheet).moveTo(m_tileSheet));
|
||||
} else if (
|
||||
dynamic_cast<AddPalette const*>(cmd) ||
|
||||
dynamic_cast<RmPalette const*>(cmd) ||
|
||||
dynamic_cast<EditPalette const*>(cmd)) {
|
||||
buildPaletteDisplayNameList();
|
||||
}
|
||||
if (dynamic_cast<EditObjectPalette const*>(cmd)) {
|
||||
} else if (dynamic_cast<EditObjectPalette const*>(cmd)) {
|
||||
auto const&obj = activeObj();
|
||||
m_objEditor.palette = obj.palBank;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user