2017-03-21 03:06:38 +01:00
|
|
|
from arm.logicnode.arm_nodes import *
|
|
|
|
|
2020-09-08 17:03:24 +02:00
|
|
|
|
2018-02-26 03:43:06 +01:00
|
|
|
def remove_extra_inputs(self, context):
|
2018-02-26 18:10:14 +01:00
|
|
|
if not any(p == self.property0 for p in ['Or', 'And']):
|
|
|
|
while len(self.inputs) > self.min_inputs:
|
|
|
|
self.inputs.remove(self.inputs[-1])
|
2018-02-26 03:43:06 +01:00
|
|
|
|
2020-09-08 17:03:24 +02:00
|
|
|
|
2020-09-08 21:16:20 +02:00
|
|
|
class GateNode(ArmLogicTreeNode):
|
2020-09-08 17:03:24 +02:00
|
|
|
"""Gate node"""
|
2017-04-04 23:11:31 +02:00
|
|
|
bl_idname = 'LNGateNode'
|
2017-03-21 03:06:38 +01:00
|
|
|
bl_label = 'Gate'
|
2020-09-08 17:03:24 +02:00
|
|
|
|
|
|
|
min_inputs = 3
|
2018-12-18 23:48:38 +01:00
|
|
|
property0: EnumProperty(
|
2017-03-21 03:06:38 +01:00
|
|
|
items = [('Equal', 'Equal', 'Equal'),
|
2018-06-01 18:33:52 +02:00
|
|
|
('Almost Equal', 'Almost Equal', 'Almost Equal'),
|
2017-03-21 03:06:38 +01:00
|
|
|
('Greater', 'Greater', 'Greater'),
|
|
|
|
('Greater Equal', 'Greater Equal', 'Greater Equal'),
|
|
|
|
('Less', 'Less', 'Less'),
|
2017-04-08 20:05:35 +02:00
|
|
|
('Less Equal', 'Less Equal', 'Less Equal'),
|
|
|
|
('Or', 'Or', 'Or'),
|
|
|
|
('And', 'And', 'And')],
|
2018-02-26 03:43:06 +01:00
|
|
|
name='', default='Equal',
|
|
|
|
update=remove_extra_inputs)
|
2018-12-18 23:48:38 +01:00
|
|
|
property1: FloatProperty(name='Tolerance', description='Precision for float compare', default=0.0001)
|
2020-09-08 17:03:24 +02:00
|
|
|
|
2018-02-26 03:43:06 +01:00
|
|
|
def __init__(self):
|
|
|
|
array_nodes[str(id(self))] = self
|
|
|
|
|
2017-03-21 03:06:38 +01:00
|
|
|
def init(self, context):
|
2020-09-08 21:49:02 +02:00
|
|
|
self.add_input('ArmNodeSocketAction', 'In')
|
|
|
|
self.add_input('NodeSocketShader', 'Value')
|
|
|
|
self.add_input('NodeSocketShader', 'Value')
|
|
|
|
self.add_output('ArmNodeSocketAction', 'True')
|
|
|
|
self.add_output('ArmNodeSocketAction', 'False')
|
2017-03-21 03:06:38 +01:00
|
|
|
|
|
|
|
def draw_buttons(self, context, layout):
|
2017-04-08 00:34:45 +02:00
|
|
|
layout.prop(self, 'property0')
|
2017-03-21 03:06:38 +01:00
|
|
|
|
2018-06-01 18:33:52 +02:00
|
|
|
if self.property0 == 'Almost Equal':
|
|
|
|
layout.prop(self, 'property1')
|
|
|
|
|
2018-02-26 03:43:06 +01:00
|
|
|
if any(p == self.property0 for p in ['Or', 'And']):
|
|
|
|
row = layout.row(align=True)
|
|
|
|
op = row.operator('arm.node_add_input', text='New', icon='PLUS', emboss=True)
|
|
|
|
op.node_index = str(id(self))
|
2018-02-26 03:47:21 +01:00
|
|
|
op.socket_type = 'NodeSocketShader'
|
2018-02-26 03:43:06 +01:00
|
|
|
op2 = row.operator('arm.node_remove_input', text='', icon='X', emboss=True)
|
|
|
|
op2.node_index = str(id(self))
|
|
|
|
|
2020-09-08 17:03:24 +02:00
|
|
|
|
2020-09-09 20:48:35 +02:00
|
|
|
add_node(GateNode, category=PKG_AS_CATEGORY)
|