Pixel-Composer/scripts/node_array_range/node_array_range.gml

55 lines
1.6 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Array_Range(_x, _y, _group = noone) : Node(_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
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Start", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.rejectArray();
2022-12-16 09:18:09 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("End", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 10)
.rejectArray();
2022-12-16 09:18:09 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("Step", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.rejectArray();
outputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, []);
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) {
2024-01-22 14:23:35 +01:00
var st = getInputData(0);
var ed = getInputData(1);
var stp = getInputData(2);
var arr = [];
2022-12-16 09:18:09 +01:00
2024-01-22 14:23:35 +01:00
if(st == ed) {
arr = array_create(stp, st);
} else if(sign(stp) == sign(ed - st)) {
var _amo = floor(abs((ed - st) / stp));
for( var i = 0; i < _amo; i++ )
array_push(arr, st + i * stp);
2022-12-16 09:18:09 +01:00
}
outputs[| 0].setValue(arr);
}
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 = getInputData(0);
var edd = getInputData(1);
var stp = getInputData(2);
2024-01-22 14:23:35 +01: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);
2024-01-22 14:23:35 +01:00
var ss = string_scale(str, bbox.w, bbox.h);
2023-01-25 06:49:00 +01:00
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
}
2022-12-16 09:18:09 +01:00
}