@@ -267,6 +267,92 @@ def update(self, condition, if_true, fallback, use_fallback):
267
267
else :
268
268
return (state ["prev_output" ],)
269
269
270
+ class LogicOperator (ControlNodeBase ):
271
+ DESCRIPTION = "Performs logical operations (AND, OR, NOT, XOR) on inputs based on their truthiness"
272
+
273
+ @classmethod
274
+ def INPUT_TYPES (s ):
275
+ return {
276
+ "required" : {
277
+ "operation" : (["AND" , "OR" , "NOT" , "XOR" ], {
278
+ "default" : "AND" ,
279
+ "tooltip" : "Logical operation to perform"
280
+ }),
281
+ "input_a" : (AlwaysEqualProxy ("*" ), {
282
+ "tooltip" : "First input to evaluate for truthiness" ,
283
+ "forceInput" : True ,
284
+ }),
285
+ "always_execute" : ("BOOLEAN" , {
286
+ "default" : True ,
287
+ }),
288
+ },
289
+ "optional" : {
290
+ "input_b" : (AlwaysEqualProxy ("*" ), {
291
+ "tooltip" : "Second input to evaluate for truthiness (not used for NOT operation)" ,
292
+ }),
293
+ }
294
+ }
295
+
296
+ RETURN_TYPES = ("BOOLEAN" ,)
297
+ FUNCTION = "update"
298
+ CATEGORY = "real-time/control/logic"
299
+
300
+ def update (self , operation , input_a , always_execute = True , input_b = None ):
301
+ """Perform the selected logical operation on inputs based on their truthiness."""
302
+ a = bool (input_a )
303
+
304
+ if operation == "NOT" :
305
+ return (not a ,)
306
+
307
+ # For all other operations, we need input_b
308
+ b = bool (input_b )
309
+
310
+ if operation == "AND" :
311
+ return (a and b ,)
312
+ elif operation == "OR" :
313
+ return (a or b ,)
314
+ elif operation == "XOR" :
315
+ return (a != b ,)
316
+
317
+ # Should never get here, but just in case
318
+ return (False ,)
319
+
320
+ class IfThenElse (ControlNodeBase ):
321
+ DESCRIPTION = "Selects between two values based on a condition's truthiness"
322
+
323
+ @classmethod
324
+ def INPUT_TYPES (s ):
325
+ return {
326
+ "required" : {
327
+ "condition" : (AlwaysEqualProxy ("*" ), {
328
+ "tooltip" : "When truthy, outputs then_value; when falsy, outputs else_value" ,
329
+ "forceInput" : True ,
330
+ }),
331
+ "then_value" : (AlwaysEqualProxy ("*" ), {
332
+ "tooltip" : "Value to output when condition is truthy" ,
333
+ "forceInput" : True ,
334
+ }),
335
+ "else_value" : (AlwaysEqualProxy ("*" ), {
336
+ "tooltip" : "Value to output when condition is falsy" ,
337
+ "forceInput" : True ,
338
+ }),
339
+ "always_execute" : ("BOOLEAN" , {
340
+ "default" : True ,
341
+ }),
342
+ }
343
+ }
344
+
345
+ RETURN_TYPES = (AlwaysEqualProxy ("*" ),)
346
+ FUNCTION = "update"
347
+ CATEGORY = "real-time/control/logic"
348
+
349
+ def update (self , condition , then_value , else_value , always_execute = True ):
350
+ """Select between then_value and else_value based on condition truthiness."""
351
+ if condition : # Let Python handle truthiness
352
+ return (then_value ,)
353
+ else :
354
+ return (else_value ,)
355
+
270
356
271
357
272
358
0 commit comments