Pixel-Composer/scripts/node_array_shift/node_array_shift.gml

60 lines
1.6 KiB
Text
Raw Normal View History

function Node_Array_Shift(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2024-03-28 14:18:02 +01:00
name = "Array Shift";
setDimension(96, 32 + 24);
2023-03-07 14:29:47 +01:00
2024-08-20 10:15:53 +02:00
newInput(0, nodeValue("Array", self, CONNECT_TYPE.input, VALUE_TYPE.any, 0))
.setArrayDepth(99)
2023-03-07 14:29:47 +01:00
.setVisible(true, true);
2024-10-01 08:02:07 +02:00
newInput(1, nodeValue_Int("Shift", self, 0));
newInput(2, nodeValue_Enum_Scroll("Overflow", self, 0, [ "Wrap", "Zero", "Ignore" ]));
2023-03-07 14:29:47 +01:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Array", self, VALUE_TYPE.any, 0));
2023-03-07 14:29:47 +01:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
var _arr = _data[0];
var _shf = _data[1];
2024-10-01 08:02:07 +02:00
var _ovf = _data[2];
2023-03-07 14:29:47 +01:00
2024-08-08 06:57:51 +02:00
inputs[ 0].setType(VALUE_TYPE.any);
outputs[0].setType(VALUE_TYPE.any);
2023-03-07 14:29:47 +01:00
if(!is_array(_arr)) return [];
2023-03-07 14:29:47 +01:00
2024-08-08 06:57:51 +02:00
if(inputs[0].value_from != noone) {
var type = inputs[0].value_from.type;
inputs[ 0].setType(type);
outputs[0].setType(type);
2023-03-07 14:29:47 +01:00
}
var arr = [];
2024-10-01 08:02:07 +02:00
var len = array_length(_arr);
if(_ovf == 0) {
for( var i = 0, n = len; i < n; i++ )
arr[i] = array_safe_get(_arr, i - _shf,, ARRAY_OVERFLOW.loop);
} else if(_ovf == 1) {
for( var i = 0, n = len; i < n; i++ ) {
var _i = i - _shf;
arr[i] = array_safe_get(_arr, _i, 0);
}
} else if(_ovf == 2) {
for( var i = 0, n = len; i < n; i++ ) {
var _i = i - _shf;
if(_i < 0 || _i >= len) continue;
array_push(arr, array_safe_get(_arr, _i));
}
}
2023-03-07 14:29:47 +01:00
return arr;
2023-03-07 14:29:47 +01:00
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
2023-03-13 10:45:56 +01:00
draw_sprite_fit(s_node_array_shift, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
2023-03-07 14:29:47 +01:00
}
}