61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
from .any_type import ANY_TYPE
|
|
|
|
class FriendlyPipeIn:
|
|
"""
|
|
A pipe input node that bundles up to 80 arbitrary inputs into a single pipe output.
|
|
Slots can be dynamically added or removed via the UI.
|
|
Each slot can be named, and names are passed through the pipe.
|
|
"""
|
|
|
|
MAX_SLOTS = 80
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
inputs = {
|
|
"required": {},
|
|
"optional": {},
|
|
"hidden": {
|
|
"slot_count": ("INT", {"default": 1}),
|
|
"slot_names": ("STRING", {"default": "{}"}),
|
|
}
|
|
}
|
|
|
|
# Define all possible slots as optional with ANY_TYPE
|
|
for i in range(1, cls.MAX_SLOTS + 1):
|
|
inputs["optional"][f"slot_{i}"] = (ANY_TYPE, {"forceInput": True})
|
|
|
|
return inputs
|
|
|
|
RETURN_TYPES = ("FRIENDLY_PIPE",)
|
|
RETURN_NAMES = ("pipe",)
|
|
FUNCTION = "execute"
|
|
CATEGORY = "utils/pipe"
|
|
|
|
def execute(self, slot_count=1, slot_names="{}", **kwargs):
|
|
import json
|
|
|
|
# Parse slot names from JSON string
|
|
try:
|
|
names_dict = json.loads(slot_names)
|
|
except:
|
|
names_dict = {}
|
|
|
|
# Collect all connected slot values into a dictionary
|
|
pipe_data = {
|
|
"slots": {},
|
|
"names": names_dict
|
|
}
|
|
|
|
# Find the highest slot index that has data
|
|
max_slot = 0
|
|
for i in range(1, self.MAX_SLOTS + 1):
|
|
slot_key = f"slot_{i}"
|
|
if slot_key in kwargs and kwargs[slot_key] is not None:
|
|
pipe_data["slots"][i] = kwargs[slot_key]
|
|
max_slot = i
|
|
|
|
# Use the higher of: the UI slot_count or the actual max slot with data
|
|
pipe_data["slot_count"] = max(slot_count, max_slot)
|
|
|
|
return (pipe_data,)
|