Pixel-Composer/scripts/node_array_remove/node_array_remove.gml

77 lines
2.2 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Array_Remove(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-02-14 02:48:33 +01:00
name = "Array Remove";
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("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Index", "Value" ])
.rejectArray();
inputs[| 2] = nodeValue("Index", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
inputs[| 3] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
.setVisible(true, true);
2023-04-11 20:29:20 +02:00
inputs[| 4] = 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);
static step = function() {
var type = getInputData(1);
2023-02-14 02:48:33 +01:00
inputs[| 2].setVisible(type == 0, type == 0);
inputs[| 3].setVisible(type == 1, type == 1);
2023-10-07 16:23:40 +02:00
inputs[| 0].setType(VALUE_TYPE.any);
inputs[| 3].setType(VALUE_TYPE.any);
outputs[| 0].setType(VALUE_TYPE.any);
2023-02-14 02:48:33 +01:00
if(inputs[| 0].value_from != noone) {
var type = inputs[| 0].value_from.type;
2023-10-07 16:23:40 +02:00
inputs[| 0].setType(type);
inputs[| 3].setType(type);
outputs[| 0].setType(type);
2023-02-14 02:48:33 +01:00
}
}
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) {
var _arr = getInputData(0);
2023-02-14 02:48:33 +01:00
if(!is_array(_arr)) return;
var type = getInputData(1);
var index = getInputData(2);
var value = getInputData(3);
var spred = getInputData(4);
2023-02-14 02:48:33 +01:00
2023-09-14 16:29:39 +02:00
_arr = array_clone(_arr);
2023-02-14 02:48:33 +01:00
if(type == 0) {
if(!is_array(index)) index = [ index ];
array_sort(index, false);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(index); i < n; i++ ) {
2023-09-14 16:29:39 +02:00
if(index[i] < 0) index[i] = array_length(_arr) + index[i];
array_delete(_arr, index[i], 1);
2023-03-24 12:10:01 +01:00
}
2023-02-14 02:48:33 +01:00
} else {
2023-04-11 20:29:20 +02:00
if(!spred || !is_array(value)) value = [ value ];
2023-02-14 02:48:33 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(value); i < n; i++ )
2023-09-14 16:29:39 +02:00
array_remove(_arr, value[i]);
2023-02-14 02:48:33 +01:00
}
2023-09-14 16:29:39 +02:00
outputs[| 0].setValue(_arr);
2023-02-14 02:48:33 +01:00
}
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
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_array_remove, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
}