rework output type socket to be more flexible
This commit is contained in:
@@ -15,6 +15,30 @@ NODE_CLASS_MAPPINGS: dict[str, type] = {}
|
||||
NODE_DISPLAY_NAME_MAPPINGS: dict[str, str] = {}
|
||||
|
||||
|
||||
def get_node_output_specs(cls: type) -> tuple[tuple[str, str], ...]:
|
||||
raw_outputs = getattr(cls, "OUTPUTS", None)
|
||||
if raw_outputs is None:
|
||||
raise AttributeError(f"{cls.__name__} must define OUTPUTS.")
|
||||
|
||||
specs: list[tuple[str, str]] = []
|
||||
for index, output in enumerate(raw_outputs):
|
||||
if not isinstance(output, (list, tuple)) or len(output) != 2:
|
||||
raise TypeError(
|
||||
f"{cls.__name__}.OUTPUTS[{index}] must be a 2-item tuple of (type, name)."
|
||||
)
|
||||
type_name, name = output
|
||||
specs.append((str(type_name), str(name)))
|
||||
return tuple(specs)
|
||||
|
||||
|
||||
def get_node_output_types(cls: type) -> tuple[str, ...]:
|
||||
return tuple(type_name for type_name, _ in get_node_output_specs(cls))
|
||||
|
||||
|
||||
def get_node_output_names(cls: type) -> tuple[str, ...]:
|
||||
return tuple(name for _, name in get_node_output_specs(cls))
|
||||
|
||||
|
||||
def register_node(display_name: str | None = None):
|
||||
"""
|
||||
Class decorator that registers a node class into NODE_CLASS_MAPPINGS.
|
||||
@@ -25,6 +49,7 @@ def register_node(display_name: str | None = None):
|
||||
...
|
||||
"""
|
||||
def decorator(cls: type) -> type:
|
||||
get_node_output_specs(cls)
|
||||
name = cls.__name__
|
||||
NODE_CLASS_MAPPINGS[name] = cls
|
||||
NODE_DISPLAY_NAME_MAPPINGS[name] = display_name or name
|
||||
@@ -50,8 +75,8 @@ def get_node_info(class_name: str) -> dict[str, Any]:
|
||||
"menu_categories": list(menu_metadata.get("menu_categories", [])),
|
||||
"input": input_types,
|
||||
"input_order": {k: list(v.keys()) for k, v in input_types.items()},
|
||||
"output": list(cls.RETURN_TYPES),
|
||||
"output_name": list(getattr(cls, "RETURN_NAMES", cls.RETURN_TYPES)),
|
||||
"output": list(get_node_output_types(cls)),
|
||||
"output_name": list(get_node_output_names(cls)),
|
||||
"output_node": bool(getattr(cls, "OUTPUT_NODE", False)),
|
||||
"manual_trigger": bool(getattr(cls, "MANUAL_TRIGGER", False)),
|
||||
"description": getattr(cls, "DESCRIPTION", ""),
|
||||
|
||||
Reference in New Issue
Block a user