Files
Derfuu-Derfuu_ComfyUI_Modde…/pyscripts/Nodes/Custom/LogicNode.py
T
Derfuu 665c3f10b1 Debug node get additional output to be able for use in-line with other nodes;
Removed(commented) "Tuples" nodes;
Removed "TUPLES" type from "Get size" nodes; (DON'T FORGET TO REPLACE THEM IF THEY'RE PERSISTS IN YOUR WORKFLOW)
Types moved into their own class with class methods and default parameters instead of just tuples with strings and dicts;
Added "Logic node" (>, <, =, AND, OR, XOR); (idk why i did this one, but got an idea that with object recognition models to count objects and correct them in next iterations would be not so bad idea as i think. Or something like this)
changed README.md to current state of this repo
2024-04-03 03:07:33 +03:00

45 lines
1.6 KiB
Python

from custom_nodes.Derfuu_ComfyUI_ModdedNodes.pyscripts.components.fields import Field, ANY
from custom_nodes.Derfuu_ComfyUI_ModdedNodes.pyscripts.components.tree import TREE_FUNCTIONS
class LogicNode:
def __init__(self) -> None:
pass
@classmethod
def INPUT_TYPES(cls) -> dict:
return {
"required": {
"Operation": Field.combo([
">", "<", "=", "AND", "OR", "XOR",
]),
"CompareValue_A": Field.any(),
},
"optional": {
"CompareValue_B": Field.any(),
"OnTrue": Field.any(),
"OnFalse": Field.any()
}
}
RETURN_TYPES = (ANY,)
CATEGORY = TREE_FUNCTIONS
FUNCTION = "do_logic"
def do_logic(self, CompareValue_A, CompareValue_B = False, OnTrue = False, OnFalse = False, Operation: str = "AND") -> tuple:
match Operation:
case ">":
value = OnTrue if CompareValue_A > CompareValue_B else OnFalse
case "<":
value = OnTrue if CompareValue_A < CompareValue_B else OnFalse
case "=":
value = OnTrue if CompareValue_A == CompareValue_B else OnFalse
case "AND":
value = OnTrue if CompareValue_A and CompareValue_B else OnFalse
case "OR":
value = OnTrue if CompareValue_A or CompareValue_B else OnFalse
case "XOR":
value = OnTrue if not (CompareValue_A and CompareValue_B) and (CompareValue_A or CompareValue_B) else OnFalse
case _:
value = None
return (value, )