[jasper/world/studio] Improve WorldEditor dependency tracking

This commit is contained in:
2024-05-27 00:56:04 -05:00
parent 55a747f6a1
commit 3eee6161a0
2 changed files with 29 additions and 7 deletions

View File

@ -87,7 +87,7 @@ WorldEditorImGui::WorldEditorImGui(studio::StudioContext &sctx, ox::StringView p
oxThrowError(loadObjectSets());
setRequiresConstantRefresh(false);
m_objSetPicker.filePicked.connect(this, &WorldEditorImGui::addObjSet);
m_sctx.project->fileUpdated.connect(this, &WorldEditorImGui::handleObjectSetUpdate);
m_sctx.project->fileUpdated.connect(this, &WorldEditorImGui::handleDepUpdate);
studio::Editor::undoStack()->changeTriggered.connect(this, &WorldEditorImGui::undoStackChanged);
}
@ -308,22 +308,34 @@ void WorldEditorImGui::rmObjSet() noexcept {
std::ignore = pushCommand<RmObjectSet>(m_doc, m_palMgr.selectedIdx);
}
ox::Error WorldEditorImGui::handleObjectSetUpdate(ox::StringView, ox::UUID const&uuid) noexcept {
auto const matches = [uuid](ObjectSetEntry const&set) {
ox::Error WorldEditorImGui::handleDepUpdate(ox::StringView, ox::UUID const&uuid) noexcept {
auto const objSetMatches = [&uuid](ObjectSetEntry const&set) {
auto const [setUuid, err] = keel::uuidUrlToUuid(set.path);
return !err && setUuid == uuid;
};
if (ox::any_of(m_doc.objSets.begin(), m_doc.objSets.end(), matches)) {
auto const depMatches = [&uuid](ox::SmallMap<ox::UUID, bool>::Pair const&set) {
return set.key == uuid;
};
auto const depUpdated = ox::any_of(m_doc.objSets.begin(), m_doc.objSets.end(), objSetMatches)
|| ox::any_of(m_dependencies.pairs().begin(), m_dependencies.pairs().end(), depMatches);
if (depUpdated) {
oxReturnError(buildObjCache(keelCtx(m_sctx.tctx), m_doc).moveTo(m_objCache));
oxReturnError(loadWorldStatic(m_objCache, m_doc).moveTo(m_worldStatic));
oxReturnError(loadObjectSets());
}
return loadObjectSets();
return {};
}
ox::Error WorldEditorImGui::loadObjectSets() noexcept {
m_objSets.clear();
m_dependencies.clear();
auto &kctx = keelCtx(m_sctx.tctx);
for (auto const&set : m_doc.objSets) {
oxRequireM(os, readObj<WorldObjectSet>(keelCtx(m_sctx.tctx), set.path));
oxRequireM(os, readObj<WorldObjectSet>(kctx, set.path));
oxLogError(addDependency(os->tilesheet));
for (auto const&pal : os->palettes) {
oxLogError(addDependency(pal.palette));
}
m_objSets.emplace_back(ox::String(set.path), set.id, std::move(os));
}
return {};
@ -347,4 +359,11 @@ void WorldEditorImGui::clearSelection() noexcept {
m_view.clearSelection();
}
ox::Error WorldEditorImGui::addDependency(ox::FileAddress const&fileAddr) noexcept {
auto &kctx = keelCtx(m_sctx.tctx);
oxRequire(uuid, keel::getUuid(kctx, fileAddr));
m_dependencies[uuid] = true;
return {};
}
}

View File

@ -38,6 +38,7 @@ class WorldEditorImGui: public studio::Editor {
constexpr ObjSetRef() = default;
};
ox::Vector<ObjSetRef> m_objSets;
ox::SmallMap<ox::UUID, bool> m_dependencies;
WorldStatic m_worldStatic;
WorldEditorView m_view;
struct {
@ -81,7 +82,7 @@ class WorldEditorImGui: public studio::Editor {
void rmObjSet() noexcept;
// handles the updating of an object set in case it is one used by this world
ox::Error handleObjectSetUpdate(ox::StringView path, ox::UUID const&) noexcept;
ox::Error handleDepUpdate(ox::StringView path, ox::UUID const&) noexcept;
ox::Error loadObjectSets() noexcept;
@ -91,6 +92,8 @@ class WorldEditorImGui: public studio::Editor {
bool tileSelected(ox::Point const&pt) const noexcept;
void clearSelection() noexcept;
ox::Error addDependency(ox::FileAddress const&fileAddr) noexcept;
};
}