2018-02-26 05:03:57 +01:00
|
|
|
from arm.logicnode.arm_nodes import *
|
|
|
|
|
2019-01-25 17:17:58 +01:00
|
|
|
def remove_extra_inputs(self, context):
|
|
|
|
if not any(p == self.property0 for p in ['Or', 'And']):
|
|
|
|
while len(self.inputs) > self.min_inputs:
|
|
|
|
self.inputs.remove(self.inputs[-1])
|
|
|
|
|
2020-09-08 21:16:20 +02:00
|
|
|
class CompareNode(ArmLogicTreeNode):
|
2020-10-05 19:55:56 +02:00
|
|
|
"""Compares values."""
|
2018-02-26 05:03:57 +01:00
|
|
|
bl_idname = 'LNCompareNode'
|
|
|
|
bl_label = 'Compare'
|
2020-09-13 11:27:58 +02:00
|
|
|
arm_version = 1
|
2018-12-18 23:48:38 +01:00
|
|
|
property0: EnumProperty(
|
2018-02-26 05:03:57 +01:00
|
|
|
items = [('Equal', 'Equal', 'Equal'),
|
2019-01-25 17:17:58 +01:00
|
|
|
('Almost Equal', 'Almost Equal', 'Almost Equal'),
|
|
|
|
('Greater', 'Greater', 'Greater'),
|
|
|
|
('Greater Equal', 'Greater Equal', 'Greater Equal'),
|
|
|
|
('Less', 'Less', 'Less'),
|
|
|
|
('Less Equal', 'Less Equal', 'Less Equal'),
|
|
|
|
('Or', 'Or', 'Or'),
|
|
|
|
('And', 'And', 'And')],
|
|
|
|
name='', default='Equal',
|
|
|
|
update=remove_extra_inputs)
|
|
|
|
min_inputs = 2
|
|
|
|
property1: FloatProperty(name='Tolerance', description='Precision for float compare', default=0.0001)
|
2020-09-08 17:03:24 +02:00
|
|
|
|
2019-01-25 17:17:58 +01:00
|
|
|
def __init__(self):
|
2020-10-12 19:13:34 +02:00
|
|
|
super(CompareNode, self).__init__()
|
2019-01-25 17:17:58 +01:00
|
|
|
array_nodes[str(id(self))] = self
|
|
|
|
|
2018-02-26 05:03:57 +01:00
|
|
|
def init(self, context):
|
2020-09-13 11:27:58 +02:00
|
|
|
super(CompareNode, self).init(context)
|
2020-09-08 21:49:02 +02:00
|
|
|
self.add_input('NodeSocketShader', 'Value')
|
|
|
|
self.add_input('NodeSocketShader', 'Value')
|
2020-11-17 16:01:15 +01:00
|
|
|
|
2020-09-08 21:49:02 +02:00
|
|
|
self.add_output('NodeSocketBool', 'Bool')
|
2018-02-26 05:03:57 +01:00
|
|
|
|
|
|
|
def draw_buttons(self, context, layout):
|
|
|
|
layout.prop(self, 'property0')
|
|
|
|
|
2019-01-25 17:17:58 +01:00
|
|
|
if self.property0 == 'Almost Equal':
|
|
|
|
layout.prop(self, 'property1')
|
|
|
|
|
|
|
|
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))
|
|
|
|
op.socket_type = 'NodeSocketShader'
|
|
|
|
op2 = row.operator('arm.node_remove_input', text='', icon='X', emboss=True)
|
|
|
|
op2.node_index = str(id(self))
|