-
Notifications
You must be signed in to change notification settings - Fork 315
/
CompareNode.hx
57 lines (49 loc) · 1.26 KB
/
CompareNode.hx
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package armory.logicnode;
import iron.math.Vec4;
class CompareNode extends LogicNode {
public var property0: String;
public var property1: Float;
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Bool {
var v1: Dynamic = inputs[0].get();
var v2: Dynamic = inputs[1].get();
var cond = false;
switch (property0) {
case "Equal":
cond = Std.isOfType(v1, Vec4) ? (v1: Vec4).equals(v2) : v1 == v2;
case "Not Equal":
cond = Std.isOfType(v1, Vec4) ? !(v1: Vec4).equals(v2) : v1 != v2;
case "Almost Equal":
cond = Std.isOfType(v1, Vec4) ? (v1: Vec4).almostEquals(v2, property1) : Math.abs(v1 - v2) < property1;
case "Greater":
cond = v1 > v2;
case "Greater Equal":
cond = v1 >= v2;
case "Less":
cond = v1 < v2;
case "Less Equal":
cond = v1 <= v2;
case "Between":
var v3: Dynamic = inputs[2].get();
cond = Std.isOfType(v1, Vec4) ? v2.x <= v1.x && v2.y <= v1.y && v2.z <= v1.z && v1.x <= v3.x && v1.y <= v3.y && v1.z <= v3.z : v2 <= v1 && v1 <= v3;
case "Or":
for (input in inputs) {
if (input.get()) {
cond = true;
break;
}
}
case "And":
cond = true;
for (input in inputs) {
if (!input.get()) {
cond = false;
break;
}
}
}
return cond;
}
}