2024-07-11 08:35:32 +02:00
|
|
|
function Node_Array_Split(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2024-05-17 10:05:24 +02:00
|
|
|
name = "Array Split";
|
|
|
|
setDimension(96, 0);
|
|
|
|
|
|
|
|
draw_padding = 4;
|
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(0, nodeValue("Array", self, CONNECT_TYPE.input, VALUE_TYPE.any, []))
|
2024-05-17 10:05:24 +02:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-09-04 03:57:11 +02:00
|
|
|
newOutput(0, nodeValue_Output("val 0", self, VALUE_TYPE.any, 0));
|
2024-05-17 10:05:24 +02:00
|
|
|
|
|
|
|
attributes.output_amount = 1;
|
|
|
|
|
2024-11-16 07:01:14 +01:00
|
|
|
io_pool = [];
|
|
|
|
|
2024-05-17 10:05:24 +02:00
|
|
|
static update = function() {
|
|
|
|
var _inp = getInputData(0);
|
2024-08-08 06:57:51 +02:00
|
|
|
var type = inputs[0].value_from == noone? VALUE_TYPE.any : inputs[0].value_from.type;
|
|
|
|
inputs[0].setType(type);
|
2024-05-17 10:05:24 +02:00
|
|
|
|
|
|
|
if(!is_array(_inp)) {
|
|
|
|
attributes.output_amount = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var amo = array_length(_inp);
|
|
|
|
|
|
|
|
for (var i = 0; i < amo; i++) {
|
2024-11-16 07:01:14 +01:00
|
|
|
if(i >= array_length(outputs)) {
|
|
|
|
var _pl = array_safe_get(io_pool, i, 0);
|
|
|
|
if(_pl == 0) _pl = nodeValue_Output($"val {i}", self, type, 0);
|
|
|
|
|
|
|
|
newOutput(i, _pl);
|
|
|
|
io_pool[i] = _pl;
|
|
|
|
}
|
|
|
|
|
|
|
|
outputs[i].setType(type);
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[i].setValue(_inp[i]);
|
2024-05-17 10:05:24 +02:00
|
|
|
}
|
|
|
|
|
2024-11-15 09:39:23 +01:00
|
|
|
var _rem = array_length(outputs);
|
|
|
|
for(var i = amo; i < _rem; i++) {
|
|
|
|
var _to = outputs[i].getJunctionTo();
|
|
|
|
|
|
|
|
for( var j = 0, m = array_length(_to); j < m; j++ )
|
|
|
|
_to[j].removeFrom();
|
|
|
|
}
|
|
|
|
|
|
|
|
array_resize(outputs, amo);
|
2024-05-17 10:05:24 +02:00
|
|
|
|
|
|
|
for (var i = 0, n = amo; i < n; i++) {
|
2024-11-12 04:15:04 +01:00
|
|
|
outputs[i].index = i;
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[i].setType(type);
|
|
|
|
outputs[i].resetDisplay();
|
2024-05-17 10:05:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
attributes.output_amount = amo;
|
|
|
|
}
|
|
|
|
|
|
|
|
static preApplyDeserialize = function() {
|
|
|
|
if(!struct_has(attributes, "output_amount")) return;
|
|
|
|
|
2024-11-15 09:39:23 +01:00
|
|
|
var _amo = attributes.output_amount;
|
2024-05-17 10:05:24 +02:00
|
|
|
var _ind = 0;
|
|
|
|
|
2024-11-15 09:39:23 +01:00
|
|
|
repeat(_amo) {
|
2024-11-16 07:01:14 +01:00
|
|
|
var _pl = nodeValue_Output($"val {_ind}", self, VALUE_TYPE.any, 0);
|
|
|
|
newOutput(_ind, _pl);
|
|
|
|
io_pool[_ind] = _pl;
|
2024-05-17 10:05:24 +02:00
|
|
|
_ind++;
|
|
|
|
}
|
|
|
|
}
|
2024-07-11 08:35:32 +02:00
|
|
|
}
|