From 6db26caba1b878198a7e9ca6f86d8c85c5ee5b32 Mon Sep 17 00:00:00 2001 From: Thomas Ward Date: Thu, 27 Jun 2024 16:41:57 -0400 Subject: [PATCH] Add constant primitive datatype nodes --- comfy_extras/nodes_constant_values,.py | 79 ++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 comfy_extras/nodes_constant_values,.py diff --git a/comfy_extras/nodes_constant_values,.py b/comfy_extras/nodes_constant_values,.py new file mode 100644 index 000000000..f5dc30413 --- /dev/null +++ b/comfy_extras/nodes_constant_values,.py @@ -0,0 +1,79 @@ +class _CONSTANT_BASE: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s) -> dict: + raise NotImplementedError + + RETURN_TYPES: tuple = () + RETURN_NAMES: tuple = () + + CATEGORY: str = "constants" + + FUNCTION: str = "process" + + OUTPUT_NODE: bool = False + + def process(self, value) -> tuple: + return (value,) + + +class ConstantFloat(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required": { + "value": ("FLOAT", {"default": 0.0}) + } + } + + RETURN_TYPES = ("FLOAT",) + RETURN_NAMES = ("float",) + + +class ConstantInteger(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required": { + "value": ("INT", {"default": 0}) + } + } + + RETURN_TYPES = ("INT",) + RETURN_NAMES = ("int",) + + +class ConstantString(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required" : { + "value": ("STRING", {"multiline": False}) + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("string",) + + +class ConstantStringMultiline(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required": { + "value": ("STRING", {"multiline": True}) + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("string",) + + +NODE_CLASS_MAPPINGS = { + "ConstantFloat": ConstantFloat, + "ConstantInteger": ConstantInteger, + "ConstantString": ConstantString, + "ConstantStringMultiline": ConstantStringMultiline, +}