Skip to content

Commit

Permalink
Combine clone new node menu items (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgthree committed Sep 14, 2023
1 parent 47be4d4 commit 06581df
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 60 deletions.
59 changes: 30 additions & 29 deletions js/reroute.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,41 +265,42 @@ app.registerExtension({
},
});
addMenuItem(RerouteNode, app, {
name: "Connect New Reroute Node After",
callback: async (node) => {
name: "Clone New Reroute...",
subMenuOptions: [
"Before",
"After",
],
callback: async (node, value) => {
const clone = node.clone();
const pos = [...node.pos];
clone.pos = [pos[0] + 20, pos[1] + 20];
app.graph.add(clone);
await wait();
const outputLinks = getSlotLinks(node.outputs[0]);
node.connect(0, clone, 0);
for (const outputLink of outputLinks) {
const link = outputLink.link;
const linkedNode = app.graph.getNodeById(link.target_id);
if (linkedNode) {
clone.connect(0, linkedNode, link.target_slot);
if (value === 'Before') {
clone.pos = [pos[0] - 20, pos[1] - 20];
app.graph.add(clone);
await wait();
const inputLinks = getSlotLinks(node.inputs[0]);
for (const inputLink of inputLinks) {
const link = inputLink.link;
const linkedNode = app.graph.getNodeById(link.origin_id);
if (linkedNode) {
linkedNode.connect(0, clone, 0);
}
}
clone.connect(0, node, 0);
}
},
});
addMenuItem(RerouteNode, app, {
name: "Connect New Reroute Node Before",
callback: async (node) => {
const clone = node.clone();
const pos = [...node.pos];
clone.pos = [pos[0] - 20, pos[1] - 20];
app.graph.add(clone);
await wait();
const inputLinks = getSlotLinks(node.inputs[0]);
for (const inputLink of inputLinks) {
const link = inputLink.link;
const linkedNode = app.graph.getNodeById(link.origin_id);
if (linkedNode) {
linkedNode.connect(0, clone, 0);
else {
clone.pos = [pos[0] + 20, pos[1] + 20];
app.graph.add(clone);
await wait();
const outputLinks = getSlotLinks(node.outputs[0]);
node.connect(0, clone, 0);
for (const outputLink of outputLinks) {
const link = outputLink.link;
const linkedNode = app.graph.getNodeById(link.target_id);
if (linkedNode) {
clone.connect(0, linkedNode, link.target_slot);
}
}
}
clone.connect(0, node, 0);
},
});
LiteGraph.registerNodeType(RerouteNode.title, RerouteNode);
Expand Down
62 changes: 31 additions & 31 deletions ts/reroute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,43 +357,43 @@ app.registerExtension({
},
});

addMenuItem(RerouteNode, app, {
name: "Connect New Reroute Node After",
callback: async (node) => {
const clone = node.clone();
const pos = [...node.pos];
clone.pos = [pos[0]! + 20, pos[1]! + 20];
app.graph.add(clone);
await wait();
const outputLinks = getSlotLinks(node.outputs[0]);
node.connect(0, clone, 0);
for (const outputLink of outputLinks) {
const link = outputLink.link;
const linkedNode = app.graph.getNodeById(link.target_id) as TLGraphNode;
if (linkedNode) {
clone.connect(0, linkedNode, link.target_slot);
}
}
},
});

addMenuItem(RerouteNode, app, {
name: "Connect New Reroute Node Before",
callback: async (node) => {
name: "Clone New Reroute...",
subMenuOptions: [
"Before",
"After",
],
callback: async (node, value) => {
const clone = node.clone();
const pos = [...node.pos];
clone.pos = [pos[0]! - 20, pos[1]! - 20];
app.graph.add(clone);
await wait();
const inputLinks = getSlotLinks(node.inputs[0]);
for (const inputLink of inputLinks) {
const link = inputLink.link;
const linkedNode = app.graph.getNodeById(link.origin_id) as TLGraphNode;
if (linkedNode) {
linkedNode.connect(0, clone, 0);
if (value === 'Before') {
clone.pos = [pos[0]! - 20, pos[1]! - 20];
app.graph.add(clone);
await wait();
const inputLinks = getSlotLinks(node.inputs[0]);
for (const inputLink of inputLinks) {
const link = inputLink.link;
const linkedNode = app.graph.getNodeById(link.origin_id) as TLGraphNode;
if (linkedNode) {
linkedNode.connect(0, clone, 0);
}
}
clone.connect(0, node, 0);
} else {
clone.pos = [pos[0]! + 20, pos[1]! + 20];
app.graph.add(clone);
await wait();
const outputLinks = getSlotLinks(node.outputs[0]);
node.connect(0, clone, 0);
for (const outputLink of outputLinks) {
const link = outputLink.link;
const linkedNode = app.graph.getNodeById(link.target_id) as TLGraphNode;
if (linkedNode) {
clone.connect(0, linkedNode, link.target_slot);
}
}
}
clone.connect(0, node, 0);
},
});

Expand Down

0 comments on commit 06581df

Please sign in to comment.