Pixel-Composer/scripts/node_array_length/node_array_length.gml

36 lines
1.1 KiB
Text
Raw Normal View History

2023-02-28 15:43:01 +07:00
function Node_Array_Length(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Array Length";
w = 96;
h = 32 + 24;
min_h = h;
2023-02-14 11:32:32 +07:00
inputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
2022-01-19 09:05:13 +07:00
.setVisible(true, true);
2023-02-14 11:32:32 +07:00
outputs[| 0] = nodeValue("Size", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, 0);
2023-10-28 09:07:43 +07:00
static step = function() { #region
2023-10-27 18:55:31 +07:00
inputs[| 0].setType(inputs[| 0].isLeaf()? VALUE_TYPE.any : inputs[| 0].value_from.type);
2023-10-28 09:07:43 +07:00
} #endregion
static update = function(frame = CURRENT_FRAME) { #region
var _arr = getInputData(0);
2022-12-22 09:09:55 +07:00
2023-01-25 12:49:00 +07:00
if(!is_array(_arr) || array_length(_arr) == 0) {
outputs[| 0].setValue(0);
return 0;
}
2023-02-14 11:32:32 +07:00
outputs[| 0].setValue(array_length(_arr));
2023-10-28 09:07:43 +07:00
} #endregion
2023-01-25 12:49:00 +07:00
2023-10-28 09:07:43 +07:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
2023-01-25 12:49:00 +07:00
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);
2023-10-28 09:07:43 +07:00
} #endregion
}