Pixel-Composer/scripts/node_array_insert/node_array_insert.gml

74 lines
2.2 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Array_Insert(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-02-14 02:48:33 +01:00
name = "Array Insert";
previewable = false;
w = 96;
h = 32 + 24;
min_h = h;
inputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
.setVisible(true, true);
inputs[| 1] = nodeValue("Index", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
inputs[| 2] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
.setVisible(true, true);
2023-04-11 20:29:20 +02:00
inputs[| 3] = nodeValue("Spread array", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false )
.rejectArray();
2023-02-14 02:48:33 +01:00
outputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
2023-07-06 19:49:16 +02:00
static update = function(frame = PROJECT.animator.current_frame) {
var _arr = getInputData(0);
2023-02-14 02:48:33 +01:00
inputs[| 0].type = VALUE_TYPE.any;
inputs[| 2].type = VALUE_TYPE.any;
outputs[| 0].type = VALUE_TYPE.any;
if(!is_array(_arr)) return;
var index = getInputData(1);
var value = getInputData(2);
var spred = getInputData(3);
2023-02-14 02:48:33 +01:00
var _len = array_length(_arr);
if(inputs[| 0].value_from != noone) {
var type = inputs[| 0].value_from.type;
inputs[| 0].type = type;
inputs[| 2].type = type;
outputs[| 0].type = type;
}
var arr = array_clone(_arr);
if(is_array(index)) {
if(!is_array(value)) value = [ value ];
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(index); i < n; i++ ) {
2023-03-24 12:10:01 +01:00
if(index[i] < 0) index[i] = array_length(arr) - 1 + index[i];
2023-02-14 02:48:33 +01:00
array_insert(arr, index[i], array_safe_get(value, i,, ARRAY_OVERFLOW.loop));
2023-03-24 12:10:01 +01:00
}
2023-02-14 02:48:33 +01:00
} else {
2023-03-25 12:27:04 +01:00
if(index < 0) index = array_length(arr) + index;
2023-03-24 12:10:01 +01:00
2023-04-11 20:29:20 +02:00
if(is_array(value) && spred) {
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(value); i < n; i++ )
2023-02-14 02:48:33 +01:00
array_insert(arr, index + i, value[i]);
2023-03-24 12:10:01 +01:00
} else {
2023-02-14 02:48:33 +01:00
array_insert(arr, index, value);
2023-03-24 12:10:01 +01:00
}
2023-02-14 02:48:33 +01:00
}
outputs[| 0].setValue(arr);
}
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-02-14 02:48:33 +01:00
draw_set_text(f_h3, fa_center, fa_center, COLORS._main_text);
var idx = getInputData(1);
2023-02-14 02:48:33 +01:00
var str = string(idx);
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);
}
}