Add 'Almost Equal' to Gate node
This commit is contained in:
parent
1e8ef7aaa5
commit
7f728d78b2
|
@ -3,6 +3,7 @@ package armory.logicnode;
|
|||
class GateNode extends LogicNode {
|
||||
|
||||
public var property0:String;
|
||||
public var property1:Float;
|
||||
|
||||
public function new(tree:LogicTree) {
|
||||
super(tree);
|
||||
|
@ -17,8 +18,8 @@ class GateNode extends LogicNode {
|
|||
switch (property0) {
|
||||
case "Equal":
|
||||
cond = v1 == v2;
|
||||
case "Not Equal":
|
||||
cond = v1 != v2;
|
||||
case "Almost Equal":
|
||||
cond = Math.abs(v1 - v2) < property1;
|
||||
case "Greater":
|
||||
cond = v1 > v2;
|
||||
case "Greater Equal":
|
||||
|
|
|
@ -15,7 +15,7 @@ class GateNode(Node, ArmLogicTreeNode):
|
|||
bl_icon = 'CURVE_PATH'
|
||||
property0 = EnumProperty(
|
||||
items = [('Equal', 'Equal', 'Equal'),
|
||||
('Not Equal', 'Not Equal', 'Not Equal'),
|
||||
('Almost Equal', 'Almost Equal', 'Almost Equal'),
|
||||
('Greater', 'Greater', 'Greater'),
|
||||
('Greater Equal', 'Greater Equal', 'Greater Equal'),
|
||||
('Less', 'Less', 'Less'),
|
||||
|
@ -25,6 +25,7 @@ class GateNode(Node, ArmLogicTreeNode):
|
|||
name='', default='Equal',
|
||||
update=remove_extra_inputs)
|
||||
min_inputs = 3
|
||||
property1 = FloatProperty(name='Tolerance', description='Precision for float compare', default=0.0001)
|
||||
|
||||
def __init__(self):
|
||||
array_nodes[str(id(self))] = self
|
||||
|
@ -39,6 +40,9 @@ class GateNode(Node, ArmLogicTreeNode):
|
|||
def draw_buttons(self, context, layout):
|
||||
layout.prop(self, 'property0')
|
||||
|
||||
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)
|
||||
|
|
|
@ -93,7 +93,8 @@ def build_node(node, f):
|
|||
for i in range(0, 5):
|
||||
if hasattr(node, 'property' + str(i)):
|
||||
prop = getattr(node, 'property' + str(i))
|
||||
f.write('\t\t' + name + '.property' + str(i) + ' = "' + prop + '";\n')
|
||||
prop = '"' + str(prop) + '"' if isinstance(prop, str) else str(prop)
|
||||
f.write('\t\t' + name + '.property' + str(i) + ' = ' + prop + ';\n')
|
||||
|
||||
# Create inputs
|
||||
for inp in node.inputs:
|
||||
|
|
Loading…
Reference in a new issue