-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathyellow_bus.py
68 lines (57 loc) · 2.2 KB
/
yellow_bus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Dynamic routing node that can handle multiple input/output pairs with adaptive types."""
# Hack: string type that is always equal in not equal comparisons
class AnyType(str):
def __ne__(self, __value: object) -> bool:
return False
def __eq__(self, __value: object) -> bool:
return True
# Our any instance wants to be a wildcard string
any = AnyType("*")
class YellowBus:
"""A dynamic routing node that can have multiple input/output pairs.
Each pair automatically adapts its type to match the connected input node.
"""
@classmethod
def INPUT_TYPES(cls):
"""Define dynamic inputs. The actual number of inputs is controlled by the UI."""
return {
"required": {
"pairs": ("INT", {"default": 2, "min": 1, "max": 10, "step": 1}),
},
"optional": {
f"input_{i}": (any,) for i in range(1, 11) # Support up to 10 pairs
}
}
RETURN_TYPES = tuple([any] * 10) # Support up to 10 outputs
RETURN_NAMES = tuple([f"out_{i}" for i in range(1, 11)]) # Names updated by JS
FUNCTION = "route"
CATEGORY = "klinter"
NODE_COLOR = "#FFFF00" # Yellow color
@classmethod
def VALIDATE_INPUTS(s, **kwargs):
"""All inputs are valid since we handle dynamic types."""
return True
def route(self, pairs, **kwargs):
"""Route inputs to outputs in order.
Each input maps to its corresponding output with the same type.
If an input is not connected, its corresponding output will be None.
"""
# Convert kwargs to list, preserving order and types
values = []
for i in range(1, pairs + 1):
key = f"input_{i}"
value = kwargs.get(key, None)
# Store the type information for the UI
if value is not None:
value_type = type(value).__name__
values.append(value)
# Fill remaining outputs with None
while len(values) < 10:
values.append(None)
return tuple(values)
NODE_CLASS_MAPPINGS = {
"YellowBus": YellowBus
}
NODE_DISPLAY_NAME_MAPPINGS = {
"YellowBus": "Yellow Bus - klinter"
}