Spaces:
Running
on
Zero
Running
on
Zero
from typing import Any, Callable, Mapping | |
DEFAULT_BOOL = ("BOOL", {"default": False}) | |
BOOL_UNARY_OPERATIONS: Mapping[str, Callable[[bool], bool]] = { | |
"Not": lambda a: not a, | |
} | |
BOOL_BINARY_OPERATIONS: Mapping[str, Callable[[bool, bool], bool]] = { | |
"Nor": lambda a, b: not (a or b), | |
"Xor": lambda a, b: a ^ b, | |
"Nand": lambda a, b: not (a and b), | |
"And": lambda a, b: a and b, | |
"Xnor": lambda a, b: not (a ^ b), | |
"Or": lambda a, b: a or b, | |
"Eq": lambda a, b: a == b, | |
"Neq": lambda a, b: a != b, | |
} | |
class BoolUnaryOperation: | |
def INPUT_TYPES(cls) -> Mapping[str, Any]: | |
return { | |
"required": {"op": (list(BOOL_UNARY_OPERATIONS.keys()),), "a": DEFAULT_BOOL} | |
} | |
RETURN_TYPES = ("BOOL",) | |
FUNCTION = "op" | |
CATEGORY = "math/bool" | |
def op(self, op: str, a: bool) -> tuple[bool]: | |
return (BOOL_UNARY_OPERATIONS[op](a),) | |
class BoolBinaryOperation: | |
def INPUT_TYPES(cls) -> Mapping[str, Any]: | |
return { | |
"required": { | |
"op": (list(BOOL_BINARY_OPERATIONS.keys()),), | |
"a": DEFAULT_BOOL, | |
"b": DEFAULT_BOOL, | |
} | |
} | |
RETURN_TYPES = ("BOOL",) | |
FUNCTION = "op" | |
CATEGORY = "math/bool" | |
def op(self, op: str, a: bool, b: bool) -> tuple[bool]: | |
return (BOOL_BINARY_OPERATIONS[op](a, b),) | |
NODE_CLASS_MAPPINGS = { | |
"CM_BoolUnaryOperation": BoolUnaryOperation, | |
"CM_BoolBinaryOperation": BoolBinaryOperation, | |
} | |