armory/Sources/armory/logicnode/GateNode.hx

57 lines
1.2 KiB
Haxe
Raw Normal View History

2017-03-21 03:06:38 +01:00
package armory.logicnode;
2018-06-01 19:02:56 +02:00
import iron.math.Vec4;
2017-04-08 20:05:35 +02:00
class GateNode extends LogicNode {
2017-03-21 03:06:38 +01:00
2019-12-19 23:54:08 +01:00
public var property0: String;
public var property1: Float;
2017-03-21 03:06:38 +01:00
2019-12-19 23:54:08 +01:00
public function new(tree: LogicTree) {
2017-04-04 23:11:31 +02:00
super(tree);
2017-03-21 03:06:38 +01:00
}
2019-12-19 23:54:08 +01:00
override function run(from: Int) {
var v1: Dynamic = inputs[1].get();
var v2: Dynamic = inputs[2].get();
2017-03-21 03:06:38 +01:00
var cond = false;
switch (property0) {
case "Equal":
cond = Std.isOfType(v1, Vec4) ? v1.equals(v2) : v1 == v2;
2021-10-26 15:05:11 +02:00
case "Not Equal":
cond = Std.isOfType(v1, Vec4) ? !v1.equals(v2) : v1 != v2;
2018-06-01 18:33:52 +02:00
case "Almost Equal":
cond = Std.isOfType(v1, Vec4) ? v1.almostEquals(v2, property1) : Math.abs(v1 - v2) < property1;
2017-03-21 03:06:38 +01:00
case "Greater":
cond = v1 > v2;
case "Greater Equal":
cond = v1 >= v2;
case "Less":
cond = v1 < v2;
case "Less Equal":
cond = v1 <= v2;
2021-10-20 02:19:16 +02:00
case "Between":
var v3: Dynamic = inputs[3].get();
cond = v2 <= v1 && v1 <= v3;
2017-04-08 20:05:35 +02:00
case "Or":
for (i in 1...inputs.length) {
if (inputs[i].get()) {
cond = true;
break;
}
}
2017-04-08 20:05:35 +02:00
case "And":
cond = true;
for (i in 1...inputs.length) {
if (!inputs[i].get()) {
cond = false;
break;
}
}
2017-03-21 03:06:38 +01:00
}
2018-10-22 10:10:33 +02:00
cond ? runOutput(0) : runOutput(1);
2017-03-21 03:06:38 +01:00
}
}