Skip to content

Commit

Permalink
Fixed Copy/Paste wrong nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
blockout22 committed Sep 17, 2023
1 parent d852de4 commit 2fb1ea1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/main/java/ovs/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ public AdvancedArrayList<Node> getNodes()
return nodes;
}

public Node findNodeById(long id){
Node returnNode = null;
for (Node n : getNodes().getList()) {
if(n.getID() == id){
returnNode = n;
}
}

return returnNode;
}

public void update(){
for(Integer q : queuedForRemoval){
Node n = null;
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/ovs/graph/NodeEditorRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,13 @@ public void show(ImVec2 cursorPos, boolean isLoading) {

if(ImGui.beginPopup("node_menu" + id)){
//TODO Duplicate all info attatched to this node
if(ImGui.menuItem("Duplicate Node " + graph.getNodes().get(targetNode).getName()))
Node selectedNode = graph.findNodeById(targetNode);
if(ImGui.menuItem("Duplicate Node " + selectedNode.getName()))
{
Node newInstance = null;
try{
Node target = graph.getNodes().get(targetNode);
// Node target = graph.getNodes().get(targetNode);
Node target = graph.findNodeById(targetNode);
newInstance = target.getClass().getDeclaredConstructor(Graph.class).newInstance(graph);
graph.addNode(newInstance);
NodeEditor.setNodePosition(newInstance.getID(), NodeEditor.toCanvasX(ImGui.getCursorScreenPosX()), NodeEditor.toCanvasY(ImGui.getCursorScreenPosY()));
Expand All @@ -421,7 +423,7 @@ public void show(ImVec2 cursorPos, boolean isLoading) {

ImGui.separator();

if(ImGui.menuItem("Delete " + graph.getNodes().get(targetNode).getName())){
if(ImGui.menuItem("Delete " + selectedNode.getName())){
NodeEditor.deleteNode(targetNode);
ImGui.closeCurrentPopup();
}
Expand Down Expand Up @@ -496,8 +498,18 @@ public void show(ImVec2 cursorPos, boolean isLoading) {

ArrayList<Node> nodeList = new ArrayList<>();
for (int i = 0; i < list.length; i++) {
Node node = graph.getNodes().get((int)list[i]);
nodeList.add(node);
// Node node = graph.getNodes().get((int)list[i]);
Node node = null;
//Find Node with ID == list[id]
for (Node n : graph.getNodes().getList()) {
if(n.getID() == ((int)list[i])){
node = n;
break;
}
}
if(node != null) {
nodeList.add(node);
}
}
NodeCopyPasteHandler.copy(nodeList);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
937
953

0 comments on commit 2fb1ea1

Please sign in to comment.