Skip to content

Commit

Permalink
fix: Loading of data processor workspaces not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Oct 19, 2023
1 parent c9cd7ad commit d07d36f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions plugins/builtin/include/content/views/view_data_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace hex::plugin::builtin {
static nlohmann::json saveNode(const dp::Node *node);
static nlohmann::json saveNodes(const Workspace &workspace);

static std::unique_ptr<dp::Node> loadNode(const nlohmann::json &data);
static void loadNodes(Workspace &workspace, const nlohmann::json &data);
static std::unique_ptr<dp::Node> loadNode(nlohmann::json data);
void loadNodes(Workspace &workspace, nlohmann::json data);

static void eraseLink(Workspace &workspace, int id);
static void eraseNodes(Workspace &workspace, const std::vector<int> &ids);
Expand Down
11 changes: 6 additions & 5 deletions plugins/builtin/source/content/views/view_data_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ namespace hex::plugin::builtin {
[&](const std::fs::path &path) {
wolv::io::File file(path, wolv::io::File::Mode::Read);
if (file.isValid()) {
ViewDataProcessor::loadNodes(*this->m_mainWorkspace, file.readString());
ViewDataProcessor::loadNodes(*this->m_mainWorkspace, nlohmann::json::parse(file.readString()));
this->m_updateNodePositions = true;
}
});
Expand Down Expand Up @@ -747,7 +747,6 @@ namespace hex::plugin::builtin {
// If a node position update is pending, update the node position
int nodeId = node.getId();
if (this->m_updateNodePositions) {
this->m_updateNodePositions = false;
ImNodes::SetNodeGridSpacePos(nodeId, node.getPosition());
} else {
if (ImNodes::ObjectPoolFind(ImNodes::EditorContextGet().Nodes, nodeId) >= 0)
Expand Down Expand Up @@ -882,6 +881,8 @@ namespace hex::plugin::builtin {
ImNodes::PopColorStyle();
}

this->m_updateNodePositions = false;

// Handle removing links that are connected to attributes that don't exist anymore
{
std::vector<int> linksToRemove;
Expand Down Expand Up @@ -1074,7 +1075,7 @@ namespace hex::plugin::builtin {
return output;
}

std::unique_ptr<dp::Node> ViewDataProcessor::loadNode(const nlohmann::json &node) {
std::unique_ptr<dp::Node> ViewDataProcessor::loadNode(nlohmann::json node) {
try {
auto &nodeEntries = ContentRegistry::DataProcessorNode::impl::getEntries();

Expand Down Expand Up @@ -1108,7 +1109,7 @@ namespace hex::plugin::builtin {
}
}

void ViewDataProcessor::loadNodes(ViewDataProcessor::Workspace &workspace, const nlohmann::json &jsonData) {
void ViewDataProcessor::loadNodes(ViewDataProcessor::Workspace &workspace, nlohmann::json jsonData) {
workspace.nodes.clear();
workspace.endNodes.clear();
workspace.links.clear();
Expand Down Expand Up @@ -1194,7 +1195,7 @@ namespace hex::plugin::builtin {
dp::Attribute::setIdCounter(maxAttrId + 1);
dp::Link::setIdCounter(maxLinkId + 1);

ViewDataProcessor::processNodes(workspace);
this->m_updateNodePositions = true;
} catch (nlohmann::json::exception &e) {
PopupError::open(hex::format("Failed to load nodes: {}", e.what()));
}
Expand Down

0 comments on commit d07d36f

Please sign in to comment.