Add Compare Values node

This commit is contained in:
LaVie024 2025-06-25 04:50:05 +00:00 committed by GitHub
parent 17ed2ed021
commit b46cf23259
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,6 +34,41 @@ class BooleanLogicGate:
def apply_operation(self, value1: bool, value2: bool, mode: str) -> tuple[bool]:
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:
@classmethod
def INPUT_TYPES(cls):
@ -63,12 +98,14 @@ class OutputExists:
NODE_CLASS_MAPPINGS = {
"BooleanLogicGate": BooleanLogicGate,
"CompareValues": CompareValues,
"BooleanSwitch": BooleanSwitch,
"OutputExists": OutputExists,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"BooleanLogicGate": "Boolean Logic Gate",
"CompareValues": "Compare Values",
"BooleanSwitch": "Boolean Switch",
"OutputExists": "Output Exists",
}