Automatically add forceInput for template types

This commit is contained in:
Jacob Segal 2024-10-19 22:25:00 -07:00
parent a063468444
commit d7f0a4a4b9
1 changed files with 27 additions and 6 deletions

View File

@ -17,9 +17,6 @@ from typing import Optional, Tuple
# #
# Variadic Input - Different Types # Variadic Input - Different Types
# If you want to have a variadic input with a dynamic type, you can combine the two. For example, if you have an input named "input#COUNT" with the type "<FOO#COUNT>", each socket for the input can have a different type. (Internally, this is equivalent to making the type <FOO1> where 1 is the index of this input.) # If you want to have a variadic input with a dynamic type, you can combine the two. For example, if you have an input named "input#COUNT" with the type "<FOO#COUNT>", each socket for the input can have a different type. (Internally, this is equivalent to making the type <FOO1> where 1 is the index of this input.)
#
# Restrictions
# - All dynamic inputs must have `"forceInput": True` due to frontend reasons that will hopefully be resolved before merging.
def TemplateTypeSupport(): def TemplateTypeSupport():
def decorator(cls): def decorator(cls):
@ -35,7 +32,16 @@ def TemplateTypeSupport():
if category not in old_types: if category not in old_types:
continue continue
for key, value in old_types[category].items(): for key, value in old_types[category].items():
new_types[category][replace_variadic_suffix(key, 1)] = (template_to_type(value[0]),) + value[1:] input_name = replace_variadic_suffix(key, 1)
input_type = template_to_type(value[0])
if len(value) == 1:
extra_info = {}
else:
extra_info = value[1]
if input_name != key or input_type != value[0]:
# TODO - Fix front-end to handle widgets and remove this
extra_info["forceInput"] = True
new_types[category][input_name] = (input_type,extra_info)
return new_types return new_types
setattr(cls, "INPUT_TYPES", classmethod(new_input_types)) setattr(cls, "INPUT_TYPES", classmethod(new_input_types))
old_outputs = getattr(cls, "RETURN_TYPES") old_outputs = getattr(cls, "RETURN_TYPES")
@ -77,7 +83,14 @@ def TemplateTypeSupport():
input_type = value[0] input_type = value[0]
if isinstance(input_type, str): if isinstance(input_type, str):
input_type = replace_variadic_suffix(input_type, i) input_type = replace_variadic_suffix(input_type, i)
variadic_inputs[category][replace_variadic_suffix(key, i)] = (input_type,value[1]) if len(value) == 1:
extra_info = {}
else:
extra_info = value[1]
if input_type != value[0]:
# TODO - Fix front-end to handle widgets and remove this
extra_info["forceInput"] = True
variadic_inputs[category][replace_variadic_suffix(key, i)] = (input_type,extra_info)
# Step 3 - Resolve template arguments # Step 3 - Resolve template arguments
resolved = {} resolved = {}
@ -103,7 +116,15 @@ def TemplateTypeSupport():
} }
for category in ["required", "optional"]: for category in ["required", "optional"]:
for key, value in variadic_inputs[category].items(): for key, value in variadic_inputs[category].items():
final_inputs[category][key] = (template_to_type(value[0], resolved),) + value[1:] if len(value) == 1:
extra_info = {}
else:
extra_info = value[1]
resolved_type = template_to_type(value[0], resolved)
if resolved_type != value[0]:
# TODO - Fix front-end to handle widgets and remove this
extra_info["forceInput"] = True
final_inputs[category][key] = (resolved_type,extra_info)
outputs = (template_to_type(x, resolved) for x in old_outputs) outputs = (template_to_type(x, resolved) for x in old_outputs)
return { return {
"input": final_inputs, "input": final_inputs,