Skip to content

Commit

Permalink
centerOnNode & fix node (widgets)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowcz007 committed Jan 21, 2024
1 parent 9a4f2eb commit fc2367d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 10 deletions.
5 changes: 4 additions & 1 deletion web/javascript/app_mixlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ app.registerExtension({
}
},
async loadedGraphNode (node, app) {
console.log('#loadedGraphNode1111')
// console.log('#loadedGraphNode1111')
window._mixlab_app_json = null //切换workflow需要清空
if (node.type === 'AppInfo') {
let auto_save = node.widgets.filter(w => w.name == 'auto_save')[0]
Expand All @@ -408,6 +408,9 @@ app.registerExtension({
auto_save.value = 'enable'
}
}

app.canvas.centerOnNode(node)
app.canvas.setZoom(0.45)
}
}
})
Expand Down
88 changes: 79 additions & 9 deletions web/javascript/ui_mixlab.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,70 @@
import { app } from '../../../scripts/app.js'
import { api } from '../../../scripts/api.js'
import { ComfyWidgets } from '../../../scripts/widgets.js'
import { $el } from '../../../scripts/ui.js'
import { closeIcon } from './svg_icons.js'

import {
GroupNodeConfig,
GroupNodeHandler
} from '../../../extensions/core/groupNode.js'

function copyNodeValues (src, dest) {
// title
dest.title = src.title

// copy input connections

for (let i in src.inputs) {
let input = src.inputs[i]
if (input.link) {
let link = app.graph.links[input.link]
let src_node = app.graph.getNodeById(link.origin_id)
if (dest.inputs.filter(inp => inp.name === input.name).length === 0) {
// 没有,name换了
let dInp = dest.inputs.filter(inp => inp.type === input.type)
if (dInp.length === 1) {
src_node.connect(link.origin_slot, dest.id, dInp[0].name)
}
} else {
src_node.connect(link.origin_slot, dest.id, input.name)
}
}
}

// copy output connections
let output_links = {}
for (let i in src.outputs) {
let output = src.outputs[i]
if (output.links) {
let links = []
for (let j in output.links) {
links.push(app.graph.links[output.links[j]])
}
output_links[output.name] = links
}
}

for (let i in dest.outputs) {
let links = output_links[dest.outputs[i].name]
if (links) {
for (let j in links) {
let link = links[j]
let target_node = app.graph.getNodeById(link.target_id)
dest.connect(parseInt(i), target_node, link.target_slot)
}
}
}

// copy widgets
for (const w of src.widgets) {
for (const d of dest.widgets) {
if (w.name === d.name) {
d.value = w.value
}
}
}

app.graph.afterChange()
}

function deepEqual (obj1, obj2) {
if (typeof obj1 !== typeof obj2) {
return false
Expand Down Expand Up @@ -575,6 +631,14 @@ app.registerExtension({
}
}

LGraphCanvas.prototype.fixTheNode = function (node) {
let new_node = LiteGraph.createNode(node.comfyClass)
new_node.pos = [node.pos[0], node.pos[1]]
app.canvas.graph.add(new_node, false)
copyNodeValues(node, new_node)
app.canvas.graph.remove(node)
}

const getNodeMenuOptions = LGraphCanvas.prototype.getNodeMenuOptions // store the existing method
LGraphCanvas.prototype.getNodeMenuOptions = function (node) {
// replace it
Expand All @@ -588,6 +652,12 @@ app.registerExtension({
LGraphCanvas.prototype.helpAboutNode(node)
} // and the callback
},
{
content: 'Fix node v2♾️Mixlab', // with a name
callback: () => {
LGraphCanvas.prototype.fixTheNode(node)
}
},
null,
...options
] // and return the options
Expand Down Expand Up @@ -703,9 +773,9 @@ app.registerExtension({
// console.log(group)
let nodes = group._nodes
for (const node of nodes) {
app.graph.remove(node);
app.graph.remove(node)
}
app.graph.remove(group);
app.graph.remove(group)
} // and the callback
},
null,
Expand Down Expand Up @@ -733,7 +803,7 @@ app.registerExtension({

const apps = await get_my_app()

let apps_map = { '0': [] }
let apps_map = { 0: [] }

for (const app of apps) {
if (app.category) {
Expand All @@ -746,7 +816,7 @@ app.registerExtension({

let apps_opts = []
for (const category in apps_map) {
console.log('category',typeof(category))
console.log('category', typeof category)
if (category === '0') {
apps_opts.push(
...Array.from(apps_map[category], a => {
Expand Down Expand Up @@ -775,7 +845,7 @@ app.registerExtension({
} else {
// 二级
apps_opts.push({
content: '🚀 '+category,
content: '🚀 ' + category,
has_submenu: true,
disabled: false,
submenu: {
Expand Down Expand Up @@ -1058,7 +1128,7 @@ app.registerExtension({
has_submenu: true,
disabled: false,
submenu: {
options:apps_opts
options: apps_opts
}
}
)
Expand Down

0 comments on commit fc2367d

Please sign in to comment.