[jasper/world/studio] Fix WorldObjectSetEditor to reload tilesheet when it changes
All checks were successful
Build / build (push) Successful in 3m53s

This commit is contained in:
Gary Talent 2025-01-19 19:24:52 -06:00
parent a1a2b4154e
commit 97cf03fbb7
2 changed files with 13 additions and 12 deletions

View File

@ -34,7 +34,8 @@ WorldObjectSetEditorImGui::WorldObjectSetEditorImGui(
if (!err) {
m_tilesheetPath = tsPath;
}
loadObj();
std::ignore = loadObj();
m_tileSheet.updated.connect(this, &WorldObjectSetEditorImGui::loadObj);
undoStack()->changeTriggered.connect(this, &WorldObjectSetEditorImGui::handleCmd);
buildPaletteDisplayNameList();
}
@ -106,7 +107,7 @@ void WorldObjectSetEditorImGui::drawObjSelector() noexcept {
auto cmd = ox::make_unique<AddObject>(m_doc);
m_selectedObj = cmd->insertIdx();
std::ignore = undoStack()->push(std::move(cmd));
loadObj();
std::ignore = loadObj();
}
ImGui::SameLine();
if (ig::PushButton("-", btnSize)) {
@ -115,13 +116,13 @@ void WorldObjectSetEditorImGui::drawObjSelector() noexcept {
if (ig::ListBox("Objects", [this](size_t i) -> ox::CStringView {
return m_doc.objects[i].name;
}, m_doc.objects.size(), m_selectedObj)) {
loadObj();
std::ignore = loadObj();
}
}
void WorldObjectSetEditorImGui::loadObj() noexcept {
ox::Error WorldObjectSetEditorImGui::loadObj() noexcept {
if (m_selectedObj >= m_doc.objects.size()) {
return;
return ox::Error{1};
}
auto const&obj = activeObj();
auto &nameBuff = m_objEditor.nameBuff;
@ -144,13 +145,13 @@ void WorldObjectSetEditorImGui::loadObj() noexcept {
subsheetId).or_value(0);
auto const&palAddr = m_doc.palettes.size() > obj.palBank ?
m_doc.palettes[obj.palBank] : ox::FileAddress{};
oxLogError(m_colView.setup(
return m_colView.setup(
m_doc.tilesheet,
palAddr,
w,
h,
static_cast<uint_t>(tileIdx),
obj.collisionMap));
obj.collisionMap);
}
[[nodiscard]]
@ -351,14 +352,15 @@ ox::Error WorldObjectSetEditorImGui::setTileSheet(ox::StringViewCR path) noexcep
auto const uuidUrl = ox::sfmt("uuid://{}", uuid.toString());
std::ignore = pushCommand<ChangeTileSheet>
(keelCtx(m_sctx), m_doc, ox::FileAddress{uuidUrl}, m_tilesheetPath);
loadObj();
return {};
return loadObj();
}
ox::Error WorldObjectSetEditorImGui::handleCmd(studio::UndoCommand const*cmd) noexcept {
if (dynamic_cast<ChangeTileSheet const*>(cmd)) {
auto &kctx = keelCtx(m_sctx.tctx);
std::ignore = m_tileSheet.updated.disconnectObject(this);
oxLogError(readObj<ncore::TileSheet>(kctx, m_doc.tilesheet).moveTo(m_tileSheet));
m_tileSheet.updated.connect(this, &WorldObjectSetEditorImGui::loadObj);
} else if (
dynamic_cast<AddPalette const*>(cmd) ||
dynamic_cast<RmPalette const*>(cmd)) {
@ -367,8 +369,7 @@ ox::Error WorldObjectSetEditorImGui::handleCmd(studio::UndoCommand const*cmd) no
auto const&obj = activeObj();
m_objEditor.palette = obj.palBank;
}
loadObj();
return {};
return loadObj();
}
ox::Error WorldObjectSetEditorImGui::saveItem() noexcept {

View File

@ -54,7 +54,7 @@ class WorldObjectSetEditorImGui: public studio::Editor {
void drawObjSelector() noexcept;
void loadObj() noexcept;
ox::Error loadObj() noexcept;
void drawObjEditor() noexcept;