From 5bb1358dd66a310793a1ea1a8cfcb037618fe37e Mon Sep 17 00:00:00 2001 From: EllangoK Date: Sat, 8 Apr 2023 09:28:35 -0400 Subject: [PATCH] manual set default link color --- web/extensions/core/colorPalette.js | 3 +- web/scripts/test.js | 71 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 web/scripts/test.js diff --git a/web/extensions/core/colorPalette.js b/web/extensions/core/colorPalette.js index d212602c..30a98460 100644 --- a/web/extensions/core/colorPalette.js +++ b/web/extensions/core/colorPalette.js @@ -238,11 +238,11 @@ app.registerExtension({ if (colorPalette.colors) { if (colorPalette.colors.node_slot) { Object.assign(app.canvas.default_connection_color_byType, colorPalette.colors.node_slot); - app.canvas.draw(true, true); } if (colorPalette.colors.litegraph_base) { // Everything updates correctly in the loop, except the Node Title for some reason app.canvas.node_title_color = colorPalette.colors.litegraph_base.NODE_TITLE_COLOR; + app.canvas.default_link_color = colorPalette.colors.litegraph_base.LINK_COLOR; for (const key in colorPalette.colors.litegraph_base) { if (colorPalette.colors.litegraph_base.hasOwnProperty(key) && LiteGraph.hasOwnProperty(key)) { @@ -250,6 +250,7 @@ app.registerExtension({ } } } + app.canvas.draw(true, true); } }; diff --git a/web/scripts/test.js b/web/scripts/test.js new file mode 100644 index 00000000..55f8dfb6 --- /dev/null +++ b/web/scripts/test.js @@ -0,0 +1,71 @@ +(function() { + var LGraphCanvas = LiteGraph.LGraphCanvas; + var LGraph = LiteGraph.LGraph; + + // Save the original renderLink function + var originalRenderLink = LGraphCanvas.prototype.renderLink; + + // Save the original connect function + var originalConnect = LGraph.prototype.connect; + + // Override the connect function + LGraph.prototype.connect = function ( + origin_slot, + target_slot, + options + ) { + var origin_id = origin_slot[0]; + var target_id = target_slot[0]; + + var origin_node = this.getNodeById(origin_id); + var target_node = this.getNodeById(target_id); + + + if (origin_node && target_node) { + var output_slot = origin_slot[1]; + var output_slot_info = origin_node.getOutputInfo(output_slot); + + + console.log(output_slot_info) + if (output_slot_info) { + options = options || {}; + options.color = output_slot_info.label_color || null; + } + } + + return originalConnect.call(this, origin_slot, target_slot, options); + }; + + // Override the renderLink function + LGraphCanvas.prototype.renderLink = function ( + ctx, + a, + b, + link, + skip_border, + flow, + color, + start_dir, + end_dir, + num_sublines + ) { + if (link && link.color) { + color = link.color; + } + + // Call the original renderLink function with the new color + originalRenderLink.call( + this, + ctx, + a, + b, + link, + skip_border, + flow, + color, + start_dir, + end_dir, + num_sublines + ); + }; +})();