2023-01-25 06:49:00 +01:00
|
|
|
function Node_Array_Length(_x, _y, _group = -1) : Node(_x, _y, _group) constructor {
|
2022-01-17 08:52:51 +01:00
|
|
|
name = "Array Length";
|
|
|
|
previewable = false;
|
|
|
|
|
|
|
|
w = 96;
|
|
|
|
h = 32 + 24;
|
|
|
|
min_h = h;
|
|
|
|
|
2022-01-19 03:05:13 +01:00
|
|
|
inputs[| 0] = nodeValue(0, "Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
|
|
|
|
.setVisible(true, true);
|
2022-01-17 08:52:51 +01:00
|
|
|
|
|
|
|
outputs[| 0] = nodeValue(0, "Size", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, 0);
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
function update() {
|
|
|
|
var _arr = inputs[| 0].getValue();
|
2022-12-22 03:09:55 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
if(!is_array(_arr) || array_length(_arr) == 0) {
|
|
|
|
outputs[| 0].setValue(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var nested = false;
|
|
|
|
for( var i = 0; i < array_length(_arr); i++ ) {
|
|
|
|
nested |= is_array(_arr[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!nested) {
|
|
|
|
outputs[| 0].setValue(array_length(_arr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var len = [];
|
|
|
|
for( var i = 0; i < array_length(_arr); i++ ) {
|
|
|
|
len[i] = is_array(_arr[i])? array_length(_arr[i]) : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
outputs[| 0].setValue(len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s) {
|
|
|
|
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
|
|
|
|
var str = string(outputs[| 0].getValue());
|
|
|
|
|
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
|
|
|
var ss = string_scale(str, bbox.w, bbox.h);
|
|
|
|
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
|
2022-01-17 08:52:51 +01:00
|
|
|
}
|
|
|
|
}
|