armory/Sources/armory/logicnode/ArrayAddNode.hx

40 lines
806 B
Haxe
Raw Normal View History

2017-04-04 23:11:31 +02:00
package armory.logicnode;
2017-04-08 20:05:35 +02:00
class ArrayAddNode extends LogicNode {
2017-04-04 23:11:31 +02:00
var ar: Array<Dynamic>;
2019-12-19 23:54:08 +01:00
public function new(tree: LogicTree) {
2017-04-04 23:11:31 +02:00
super(tree);
}
2019-12-19 23:54:08 +01:00
override function run(from: Int) {
ar = inputs[1].get();
2018-06-14 14:52:05 +02:00
if (ar == null) return;
2018-06-12 23:48:01 +02:00
// "Modify Original" == `false` -> Copy the input array
2020-09-28 15:58:41 +02:00
if (!inputs[2].get()) {
ar = ar.copy();
}
if (inputs.length > 4) {
for (i in 4...inputs.length) {
2019-12-19 23:54:08 +01:00
var value: Dynamic = inputs[i].get();
// "Unique Values" options only supports primitive data types
// for now, a custom indexOf() or contains() method would be
// required to compare values of other types
2020-09-28 15:58:41 +02:00
if (!inputs[3].get() || ar.indexOf(value) == -1) {
ar.push(value);
}
2018-06-12 23:48:01 +02:00
}
}
2017-04-04 23:11:31 +02:00
2018-10-22 10:10:33 +02:00
runOutput(0);
2017-04-04 23:11:31 +02:00
}
override function get(from: Int): Dynamic {
return ar;
}
2017-04-04 23:11:31 +02:00
}