|
| 1 | +/** |
| 2 | + * Coded with love by Failfa.st |
| 3 | + * LICENSE: AGPL 3.0 |
| 4 | + * https://github.com/failfa-st/failfast-comfyui-extensions/blob/main/LICENSE |
| 5 | + * |
| 6 | + * Visit https://github.com/failfa-st/failfast-comfyui-extensions for more info |
| 7 | + * |
| 8 | + * Hopmepage: https://failfa.st |
| 9 | + * GitHub: https://github.com/failfa-st |
| 10 | + * Discord: https://discord.com/invite/m3TBB9XEkb |
| 11 | + */ |
| 12 | +import { app } from "../../../scripts/app.js"; |
| 13 | + |
| 14 | +/** |
| 15 | + * Nodes |
| 16 | + */ |
| 17 | + |
| 18 | +const nodesName = "Failfast.nodes"; |
| 19 | + |
| 20 | +const store = { |
| 21 | + stack: new Set(), |
| 22 | +}; |
| 23 | + |
| 24 | +app.registerExtension({ |
| 25 | + name: nodesName, |
| 26 | + async init(app) { |
| 27 | + app.ui.settings.addSetting({ |
| 28 | + id: nodesName, |
| 29 | + name: "Allow group selection resize", |
| 30 | + type: "boolean", |
| 31 | + tooltip: "Resize all selected nodes synchronous.", |
| 32 | + defaultValue: false, |
| 33 | + }); |
| 34 | + }, |
| 35 | + async setup(app) { |
| 36 | + console.log(app); |
| 37 | + app.graph._nodes.forEach((node) => { |
| 38 | + let active = JSON.parse( |
| 39 | + window.localStorage.getItem(`Comfy.Settings.${nodesName}`) ?? "false", |
| 40 | + ); |
| 41 | + const onResize = node.onResize; |
| 42 | + node.onResize = function (size) { |
| 43 | + console.log(active); |
| 44 | + if (active) { |
| 45 | + Array.from(store.stack) |
| 46 | + .filter((node_) => node_ !== node) |
| 47 | + .forEach((node_) => { |
| 48 | + node_.size[0] = size[0]; |
| 49 | + node_.size[1] = size[1]; |
| 50 | + }); |
| 51 | + } |
| 52 | + return onResize?.apply(this, arguments); |
| 53 | + }; |
| 54 | + const onMouseDown = node.onMouseDown; |
| 55 | + node.onMouseDown = function () { |
| 56 | + active = JSON.parse( |
| 57 | + window.localStorage.getItem(`Comfy.Settings.${nodesName}`) ?? "false", |
| 58 | + ); |
| 59 | + return onMouseDown?.apply(this, arguments); |
| 60 | + }; |
| 61 | + const onSelected = node.onSelected; |
| 62 | + node.onSelected = function () { |
| 63 | + store.stack.add(node); |
| 64 | + return onSelected?.apply(this, arguments); |
| 65 | + }; |
| 66 | + const onDeselected = node.onDeselected; |
| 67 | + node.onDeselected = function () { |
| 68 | + store.stack.delete(node); |
| 69 | + return onDeselected?.apply(this, arguments); |
| 70 | + }; |
| 71 | + }); |
| 72 | + }, |
| 73 | +}); |
0 commit comments