mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-09-03 23:37:15 +08:00
Add Compare Values node
This commit is contained in:
parent
17ed2ed021
commit
b46cf23259
@ -34,6 +34,41 @@ class BooleanLogicGate:
|
|||||||
def apply_operation(self, value1: bool, value2: bool, mode: str) -> tuple[bool]:
|
def apply_operation(self, value1: bool, value2: bool, mode: str) -> tuple[bool]:
|
||||||
return (self._OPS[mode](value1, value2),)
|
return (self._OPS[mode](value1, value2),)
|
||||||
|
|
||||||
|
class CompareValues:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(cls):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"valueA": (any, ),
|
||||||
|
"valueB": (any, ),
|
||||||
|
"mode": (["A == B", "A != B", "A > b", "A >= b", "a < B", "a <= B"],)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_TYPES = ("BOOLEAN",)
|
||||||
|
RETURN_NAMES = ("output",)
|
||||||
|
CATEGORY = "utils/logic"
|
||||||
|
FUNCTION = "compare"
|
||||||
|
|
||||||
|
_OPS = {
|
||||||
|
"A == B": lambda a, b: a == b,
|
||||||
|
"A != B": lambda a, b: a != b,
|
||||||
|
"A > b": lambda a, b: a > b,
|
||||||
|
"A >= b": lambda a, b: a >= b,
|
||||||
|
"a < B": lambda a, b: a < b,
|
||||||
|
"a <= B": lambda a, b: a <= b,
|
||||||
|
}
|
||||||
|
|
||||||
|
def compare(self, valueA, valueB, mode: str) -> tuple[bool]:
|
||||||
|
if isinstance(valueA, str) and isinstance(valueB, (int, float)):
|
||||||
|
try: valueA = float(valueA)
|
||||||
|
except ValueError as e: raise ValueError("Failed to convert valueA to float.") from e
|
||||||
|
elif isinstance(valueB, str) and isinstance(valueA, (int, float)):
|
||||||
|
try: valueB = float(valueB)
|
||||||
|
except ValueError as e: raise ValueError("Failed to convert valueB to float.") from e
|
||||||
|
|
||||||
|
return (self._OPS[mode](valueA, valueB),)
|
||||||
|
|
||||||
class BooleanSwitch:
|
class BooleanSwitch:
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(cls):
|
def INPUT_TYPES(cls):
|
||||||
@ -63,12 +98,14 @@ class OutputExists:
|
|||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
"BooleanLogicGate": BooleanLogicGate,
|
"BooleanLogicGate": BooleanLogicGate,
|
||||||
|
"CompareValues": CompareValues,
|
||||||
"BooleanSwitch": BooleanSwitch,
|
"BooleanSwitch": BooleanSwitch,
|
||||||
"OutputExists": OutputExists,
|
"OutputExists": OutputExists,
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||||
"BooleanLogicGate": "Boolean Logic Gate",
|
"BooleanLogicGate": "Boolean Logic Gate",
|
||||||
|
"CompareValues": "Compare Values",
|
||||||
"BooleanSwitch": "Boolean Switch",
|
"BooleanSwitch": "Boolean Switch",
|
||||||
"OutputExists": "Output Exists",
|
"OutputExists": "Output Exists",
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user