Pixel-Composer/scripts/node_array_range/node_array_range.gml

55 lines
1.4 KiB
Text
Raw Normal View History

function Node_Array_Range(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-01-25 06:49:00 +01:00
name = "Array Range";
2024-05-02 12:13:35 +02:00
setDimension(96, 48);
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_Float("Start", self, 0))
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-12-16 09:18:09 +01:00
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_Float("End", self, 10))
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-12-16 09:18:09 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Float("Step", self, 1))
2023-02-14 05:32:32 +01:00
.rejectArray();
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Array", self, VALUE_TYPE.float, []));
2023-02-14 05:32:32 +01:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
var st = _data[0];
var ed = _data[1];
var stp = _data[2];
2022-12-16 09:18:09 +01:00
if(st == ed)
return array_create(abs(stp), st);
stp = abs(stp) * sign(ed - st);
var _amo = floor(abs((ed - st) / stp));
var arr = array_create(_amo);
for( var i = 0; i < _amo; i++ )
arr[i] = st + i * stp;
2022-12-16 09:18:09 +01:00
return arr;
2022-12-16 09:18:09 +01:00
}
2023-01-25 06:49:00 +01:00
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
var str = getSingleValue(0);
var edd = getSingleValue(1);
var stp = getSingleValue(2);
2024-08-08 06:57:51 +02:00
var arr = outputs[0].getValue();
2023-01-25 06:49:00 +01:00
2024-01-22 14:23:35 +01:00
var str = "";
switch(array_length(arr)) {
case 0 : str = $"[]" break;
case 1 :
case 2 :
case 3 : str = $"{arr}" break;
default : str = $"[{arr[0]}, {arr[1]}, ..., {array_safe_get(arr, -1,, ARRAY_OVERFLOW.loop)}]"; break;
}
2023-01-25 06:49:00 +01:00
var bbox = drawGetBbox(xx, yy, _s);
draw_text_bbox(bbox, str);
2023-01-25 06:49:00 +01:00
}
2022-12-16 09:18:09 +01:00
}