diff --git a/README.md b/README.md index 2ba56c4..171905e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,21 @@ A collection of helper nodes for ComfyUI with smart functionality. +## Nodes + +### Smart Format String +### Smart Format String (10 params) +A node that formats a string with placeholders for input parameters and date/time. + +![SmartFormatString](docs/images/SmartFormatString.png) + +### Smart HV LoRA Select +### Smart HV LoRA Stack +Nodes for selecting and stacking HunyuanVideo LoRA files. +Also outputs a human-readable string of the LoRA file name and parameters (for example to save to a file). + +![SmartHVLoraSelect](docs/images/SmartHVLora.png) + ## Installation 1. Clone this repository into your `ComfyUI/custom_nodes` directory: \ No newline at end of file diff --git a/img/SmartFormatString.png b/img/SmartFormatString.png new file mode 100644 index 0000000..a5e375a Binary files /dev/null and b/img/SmartFormatString.png differ diff --git a/img/SmartHVLora.png b/img/SmartHVLora.png new file mode 100644 index 0000000..682cda9 Binary files /dev/null and b/img/SmartHVLora.png differ diff --git a/js/nodes.js b/js/nodes.js index 21b4129..5bdcdfd 100644 --- a/js/nodes.js +++ b/js/nodes.js @@ -3,18 +3,21 @@ import { app } from '../../scripts/app.js' import { api } from '../../scripts/api.js' +const SMART_HV_LORA_STACK_NAME = "Smart HV LoRA Stack"; +const SMART_HV_LORA_STACK_COUNT_WIDGET = "lora_count"; + const nodeWidgetHandlers = { "SmartHVLoraStack": { - 'lora_count': handleSmartHVLoraStackCount + [SMART_HV_LORA_STACK_COUNT_WIDGET]: handleSmartHVLoraStackCount } }; function handleSmartHVLoraStackCount(node, widget) { - handleVisibility(node, widget.value, "Smart HV LoRA Stack"); + handleVisibility(node, widget.value, SMART_HV_LORA_STACK_NAME); } function handleVisibility(node, count, type) { - if (type === "Smart HV LoRA Stack") { + if (type === SMART_HV_LORA_STACK_NAME) { //console.log("Smart: handleVisibility called for", type, "with count", count); for (let i = 1; i <= 50; i++) { const show = i <= count; @@ -54,6 +57,14 @@ function toggleWidget(node, widget, show = false) { } } +function setupVisibilityHandler(node, countWidgetName, blockType) { + const countWidget = node.widgets.find(w => w.name === countWidgetName); + if (countWidget) { + handleVisibility(node, countWidget.value, blockType); + } + return countWidget; +} + // Update the registerExtension implementation app.registerExtension({ name: "SmartHelperNodes", @@ -82,11 +93,11 @@ app.registerExtension({ const result = onNodeCreated?.apply(this, arguments); // Set up widget callbacks - const loraCountWidget = this.widgets.find(w => w.name === "lora_count"); + const loraCountWidget = setupVisibilityHandler(this, SMART_HV_LORA_STACK_COUNT_WIDGET, SMART_HV_LORA_STACK_NAME); if (loraCountWidget) { loraCountWidget.callback = () => { - handleVisibility(this, loraCountWidget.value, "Smart HV LoRA Stack"); + handleVisibility(this, loraCountWidget.value, SMART_HV_LORA_STACK_NAME); }; } @@ -107,9 +118,24 @@ app.registerExtension({ // Initial setup - hide widgets based on current count if (loraCountWidget) { - handleVisibility(this, loraCountWidget.value, "Smart HV LoRA Stack"); + handleVisibility(this, loraCountWidget.value, SMART_HV_LORA_STACK_NAME); } + // Handle workflow switching and initial load + const onConnectionsChange = this.onConnectionsChange; + this.onConnectionsChange = function() { + const result = onConnectionsChange?.apply(this, arguments); + setupVisibilityHandler(this, SMART_HV_LORA_STACK_COUNT_WIDGET, SMART_HV_LORA_STACK_NAME); + return result; + }; + + const onNodeGraphConfigure = this.onConfigure; + this.onConfigure = function() { + const result = onNodeGraphConfigure?.apply(this, arguments); + setupVisibilityHandler(this, SMART_HV_LORA_STACK_COUNT_WIDGET, SMART_HV_LORA_STACK_NAME); + return result; + }; + return result; }; }