forked from chaiNNer-org/chaiNNer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditional.py
More file actions
33 lines (29 loc) · 1018 Bytes
/
conditional.py
File metadata and controls
33 lines (29 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import annotations
from api import Lazy
from nodes.properties.inputs import AnyInput, BoolInput
from nodes.properties.outputs import BaseOutput
from .. import value_group
@value_group.register(
schema_id="chainner:utility:conditional",
name="Conditional",
description="Allows you to pass in multiple inputs and then change which one passes through to the output.",
icon="BsShuffle",
inputs=[
BoolInput("Condition", default=True, has_handle=True).with_id(0),
AnyInput(label="If True").with_id(1).make_lazy(),
AnyInput(label="If False").with_id(2).make_lazy(),
],
outputs=[
BaseOutput(
output_type="""
if Input0 { Input1 } else { Input2 }
""",
label="Value",
).as_passthrough_of(1),
],
see_also=["chainner:utility:switch"],
)
def conditional_node(
cond: bool, if_true: Lazy[object], if_false: Lazy[object]
) -> object:
return if_true.value if cond else if_false.value