anytyped nodes

This commit is contained in:
aria1th
2023-12-13 10:32:51 +09:00
parent b839e5042d
commit 47053b7d71
4 changed files with 64 additions and 184 deletions
+6 -9
View File
@@ -12,15 +12,13 @@ conversion_operators = {
"Bool" : bool,
"String" : str
}
def create_class(type_from, type_to):
if type_from == type_to:
return None
class_name = "{}2{}".format(type_from, type_to)
def create_class(type_to):
class_name = "ConvertAny2{}".format(type_to)
class CustomClass:
FUNCTION = "convert"
RETURN_TYPES = (type_to.upper(),)
CATEGORY = "Conversion"
custom_name = "Convert {} to {}".format(type_from, type_to)
custom_name = "Convert to {}".format(type_to)
@staticmethod
def convert(input1):
return (conversion_operators[type_to](input1),)
@@ -28,7 +26,7 @@ def create_class(type_from, type_to):
def INPUT_TYPES(cls):
return {
"required": {
"input1": (type_from.upper(), {"default": 0.0}),
"input1": (anytype, {"default": 0.0}),
}
}
CustomClass.__name__ = class_name
@@ -89,9 +87,8 @@ class ConvertComboToString:
return (combo,)
return (separator.join(combo),)
for type_from in conversion_operators:
for type_to in conversion_operators:
create_class(type_from, type_to)
for type_to in conversion_operators:
create_class(type_to)
CLASS_MAPPINGS, CLASS_NAMES = get_node_names_mappings(classes)
validate(classes)
+47 -162
View File
@@ -9,76 +9,58 @@ classes = []
node = node_wrapper(classes)
@node
class LogicGateCompareFloat:
class LogicGateCompare:
"""
Returns 1 if input1 > input2, 0 otherwise
"""
RETURN_TYPES = ("INT",)
RETURN_TYPES = ("BOOL",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("FLOAT", {"default": 0.0}),
"input2": ("FLOAT", {"default": 0.0}),
"input1": (anytype, {"default": 0.0}),
"input2": (anytype, {"default": 0.0}),
}
}
FUNCTION = "compareFloat"
CATEGORY = "Logic Gates"
custom_name = "ABiggerThanB(Float)"
custom_name = "ABiggerThanB"
def compareFloat(self, input1, input2):
return (1.0 if input1 > input2 else 0.0,)
return (True if input1 > input2 else False,)
@node
class LogicGateInvertBasic:
"""
Inverts 1 to 0 and 0 to 1
"""
RETURN_TYPES = ("INT",)
RETURN_TYPES = (anytype,)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("INT", {"default": 0}),
"input1": (anytype, {"default": 0}),
}
}
FUNCTION = "invert"
CATEGORY = "Logic Gates"
custom_name = "Invert Basic"
def invert(self, input1):
return (1 if input1 == 0 else 0,)
return (True if not input1 else False,)
@node
class LogicGateInvertValueInt:
class LogicGateNegateValue:
"""
Inverts x -> -x
"""
RETURN_TYPES = ("INT",)
RETURN_TYPES = (anytype,)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("INT", {"default": 0}),
"input1": (anytype, {"default": 0}),
}
}
FUNCTION = "invertValue"
CATEGORY = "Logic Gates"
custom_name = "Invert Value Int"
def invertValue(self, input1):
return (-input1,)
@node
class LogicGateInvertValueFloat:
"""
Inverts x -> -x
"""
RETURN_TYPES = ("FLOAT",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("FLOAT", {"default": 0.0}),
}
}
FUNCTION = "invertValue"
CATEGORY = "Logic Gates"
custom_name = "Invert Value Float"
custom_name = "Negate Value"
def invertValue(self, input1):
return (-input1,)
@node
@@ -185,30 +167,30 @@ class LogicGateBitwiseNot:
def bitwiseNot(self, input1):
return (~input1,)
@node
class LogicGateCompareInt:
class LogicGateCompare:
"""
Returns 1 if input1 > input2, 0 otherwise
"""
RETURN_TYPES = ("INT",)
RETURN_TYPES = ("BOOL",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("INT", {"default": 0}),
"input2": ("INT", {"default": 0}),
"input1": (anytype, {"default": 0}),
"input2": (anytype, {"default": 0}),
}
}
FUNCTION = "compareInt"
CATEGORY = "Logic Gates"
custom_name = "ABiggerThanB(Int)"
custom_name = "ABiggerThanB"
def compareInt(self, input1, input2):
return (1 if input1 > input2 else 0,)
return (True if input1 > input2 else False,)
@node
class LogicGateCompareString:
"""
Returns if given regex (1) is found in given string (2)
"""
RETURN_TYPES = ("INT",)
RETURN_TYPES = ("BOOL",)
@classmethod
def INPUT_TYPES(s):
return {
@@ -221,47 +203,7 @@ class LogicGateCompareString:
CATEGORY = "Logic Gates"
custom_name = "AContainsB(String)"
def compareString(self, regex, input2):
return (1 if re.search(regex, input2) else 0,)
@node
class LogicGateEitherFloat:
"""
Returns input1 if condition is true, input2 otherwise
"""
RETURN_TYPES = ("FLOAT",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"condition": ("INT", {"default": 0}),
"input1": ("FLOAT", {"default": 0}),
"input2": ("FLOAT", {"default": 0}),
}
}
FUNCTION = "either"
CATEGORY = "Logic Gates"
custom_name = "ConditionAorB(Float)"
def either(self, condition, input1, input2):
return (input1 if condition else input2,)
@node
class LogicGateEitherInt:
"""
Returns input1 if condition is true, input2 otherwise
"""
RETURN_TYPES = ("INT",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"condition": ("INT", {"default": 0}),
"input1": ("INT", {"default": 0}),
"input2": ("INT", {"default": 0}),
}
}
FUNCTION = "either"
CATEGORY = "Logic Gates"
custom_name = "ConditionAorB(Int)"
def either(self, condition, input1, input2):
return (input1 if condition else input2,)
return (True if re.search(regex, input2) else False,)
@node
class StaticNumberInt:
"""
@@ -317,137 +259,80 @@ class StaticString:
def staticString(self, string):
return (string,)
@node
class LogicGateAndInt:
class LogicGateAnd:
"""
Returns 1 if all inputs are True, 0 otherwise
"""
RETURN_TYPES = ("INT",)
RETURN_TYPES = ("BOOL",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("INT", {"default": 0}),
"input2": ("INT", {"default": 0}),
"input1": (anytype, {"default": 0.0}),
"input2": (anytype, {"default": 0.0}),
}
}
FUNCTION = "and_"
CATEGORY = "Logic Gates"
custom_name = "And Int"
custom_name = "AAndBGate"
def and_(self, input1, input2):
return (1 if input1 and input2 else 0,)
return (True if input1 and input2 else False,)
@node
class LogicGateAndFloat:
"""
Returns 1 if all inputs are True, 0 otherwise
"""
RETURN_TYPES = ("INT",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("FLOAT", {"default": 0.0}),
"input2": ("FLOAT", {"default": 0.0}),
}
}
FUNCTION = "and_"
CATEGORY = "Logic Gates"
custom_name = "And Float"
def and_(self, input1, input2):
return (1 if input1 and input2 else 0,)
@node
class LogicGateOrInt:
class LogicGateOr:
"""
Returns 1 if any input is True, 0 otherwise
"""
RETURN_TYPES = ("INT",)
RETURN_TYPES = ("BOOL",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("INT", {"default": 0}),
"input2": ("INT", {"default": 0}),
"input1": (anytype, {"default": 0}),
"input2": (anytype, {"default": 0}),
}
}
FUNCTION = "or_"
CATEGORY = "Logic Gates"
custom_name = "Or Int"
custom_name = "AOrBGate"
def or_(self, input1, input2):
return (1 if input1 and input2 else 0,)
return (True if input1 and input2 else False,)
@node
class LogicGateOrFloat:
"""
Returns 1 if any input is True, 0 otherwise
"""
RETURN_TYPES = ("INT",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("FLOAT", {"default": 0.0}),
"input2": ("FLOAT", {"default": 0.0}),
}
}
FUNCTION = "or_"
CATEGORY = "Logic Gates"
custom_name = "Or Float"
def or_(self, input1, input2):
return (1 if input1 and input2 else 0,)
@node
class LogicGateEitherString:
class LogicGateEither:
"""
Returns input1 if condition is true, input2 otherwise
"""
RETURN_TYPES = ("STRING",)
RETURN_TYPES = (anytype,)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"condition": ("INT", {"default": 0}),
"input1": ("STRING", {"default": ""}),
"input2": ("STRING", {"default": ""}),
"condition": (anytype, {"default": 0}),
"input1": (anytype, {"default": ""}),
"input2": (anytype, {"default": ""}),
}
}
FUNCTION = "either"
CATEGORY = "Logic Gates"
custom_name = "Either String"
custom_name = "ReturnAorBValue"
def either(self, condition, input1, input2):
return (input1 if condition else input2,)
@node
class AddInt:
class AddNode:
"""
Returns the sum of the inputs
"""
RETURN_TYPES = ("INT",)
RETURN_TYPES = (anytype,)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("INT", {"default": 0}),
"input2": ("INT", {"default": 0}),
"input1": (anytype, {"default": 0}),
"input2": (anytype, {"default": 0}),
}
}
FUNCTION = "add"
CATEGORY = "Logic Gates"
custom_name = "Add Int"
def add(self, input1, input2):
return (input1 + input2,)
@node
class AddFloat:
"""
Returns the sum of the inputs
"""
RETURN_TYPES = ("FLOAT",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input1": ("FLOAT", {"default": 0.0}),
"input2": ("FLOAT", {"default": 0.0}),
}
}
FUNCTION = "add"
CATEGORY = "Logic Gates"
custom_name = "Add Float"
custom_name = "Add Values"
def add(self, input1, input2):
return (input1 + input2,)
@node
@@ -460,15 +345,15 @@ class MergeString:
def INPUT_TYPES(s):
return {
"required": {
"input1": ("STRING", {"default": ""}),
"input2": ("STRING", {"default": ""}),
"input1": (anytype, {"default": ""}),
"input2": (anytype, {"default": ""}),
}
}
FUNCTION = "merge"
CATEGORY = "Logic Gates"
custom_name = "Merge String"
def merge(self, input1, input2):
return (input1 + input2,)
return (str(input1) + str(input2),)
@node
class MemoryNode:
+7 -9
View File
@@ -4,7 +4,7 @@ from .randomness import CLASS_MAPPINGS as RandomMapping, CLASS_NAMES as RandomNa
from .conversion import CLASS_MAPPINGS as ConversionMapping, CLASS_NAMES as ConversionNames
from .math_nodes import CLASS_MAPPINGS as MathMapping, CLASS_NAMES as MathNames
from .exif.exif import read_info_from_image_stealth
from .autonode import node_wrapper, get_node_names_mappings, validate
from .autonode import node_wrapper, get_node_names_mappings, validate, anytype
import time
fundamental_classes = []
@@ -30,19 +30,19 @@ class SleepNodeFloat:
@fundamental_node
class SleepNodeImage:
FUNCTION = "sleep"
RETURN_TYPES = ("IMAGE",)
RETURN_TYPES = (anytype,)
CATEGORY = "Misc"
custom_name = "Sleep (Image tunnel)"
@staticmethod
def sleep(interval, image):
time.sleep(interval)
return (None,)
return (image,)
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"interval": ("FLOAT", {"default": 0.0}),
"image": ("IMAGE",),
"image": (anytype,),
}
}
@@ -90,20 +90,18 @@ class TextPreviewNode:
FUNCTION = "text_preview"
RETURN_TYPES = ()
CATEGORY = "Misc"
OUTPUT_NODE = True
custom_name = "Text Preview"
def __init__(self) -> None:
self.type = "output"
RESULT_NODE = True
def text_preview(self, text):
print(text)
# below does not work, why?
return {"ui": {"text": text}}
return {"ui": {"text": str(text)}}
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING",{"default": "text"}),
"text": (anytype,{"default": "text"}),
}
}
+4 -4
View File
@@ -25,8 +25,8 @@ class UniformRandomFloat:
def INPUT_TYPES(s):
return {
"required": {
"min_val": ("FLOAT", { "default": 0.0, "min": 0.0, "max": 1000.0, "step": 0.02, "display": "number" }),
"max_val": ("FLOAT", { "default": 1.0, "min": 0.0, "max": 1000.0, "step": 0.02, "display": "number" }),
"min_val": ("FLOAT", { "default": 0.0, "min": -999999999, "max": 999999999.0, "step": 0.02, "display": "number" }),
"max_val": ("FLOAT", { "default": 1.0, "min": -999999999, "max": 999999999.0, "step": 0.02, "display": "number" }),
"decimal_places": ("INT", { "default": 1, "min": 0, "max": 10, "step": 1, "display": "number" }),
"seed" : ("INT", { "default": 0, "min": 0, "max": 9999999999, "step": 1, "display": "number" }),
},
@@ -54,8 +54,8 @@ class UniformRandomInt:
def INPUT_TYPES(s):
return {
"required": {
"min_val": ("INT", { "default": 0, "min": 0, "max": 1000, "step": 1, "display": "number" }),
"max_val": ("INT", { "default": 1, "min": 0, "max": 1000, "step": 1, "display": "number" }),
"min_val": ("INT", { "default": 0, "min": -999999999, "max": 999999999, "step": 1, "display": "number" }),
"max_val": ("INT", { "default": 1, "min": -999999999, "max": 999999999, "step": 1, "display": "number" }),
"seed" : ("INT", { "default": 0, "min": 0, "max": 9999999999, "step": 1, "display": "number" }),
},
}