Pixel-Composer/scripts/node_array_length/node_array_length.gml

33 lines
1.0 KiB
Plaintext
Raw Normal View History

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