Pixel-Composer/scripts/node_array_add/node_array_add.gml

96 lines
2.4 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Array_Add(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-01-25 06:49:00 +01:00
name = "Array Add";
2022-12-16 09:18:09 +01:00
previewable = false;
w = 96;
h = 32 + 24;
min_h = h;
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
2022-12-16 09:18:09 +01:00
.setVisible(true, true);
2023-04-11 20:29:20 +02:00
inputs[| 1] = nodeValue("Spread array", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false )
.rejectArray();
2023-02-28 09:43:01 +01:00
outputs[| 0] = nodeValue("Output", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, 0);
2022-12-16 09:18:09 +01:00
2023-02-28 09:43:01 +01:00
input_fix_len = ds_list_size(inputs);
data_length = 1;
2022-12-16 09:18:09 +01:00
2023-02-28 09:43:01 +01:00
static createNewInput = function() {
var index = ds_list_size(inputs);
inputs[| index] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1 )
.setVisible(true, true);
return inputs[| index];
}
if(!LOADING && !APPENDING) createNewInput();
static refreshDynamicInput = function() {
var _l = ds_list_create();
for( var i = 0; i < ds_list_size(inputs); i++ ) {
if(i < input_fix_len || inputs[| i].value_from)
ds_list_add(_l, inputs[| i]);
else
delete inputs[| i];
}
for( var i = 0; i < ds_list_size(_l); i++ )
_l[| i].index = i;
ds_list_destroy(inputs);
inputs = _l;
createNewInput();
}
static onValueFromUpdate = function(index) {
if(LOADING || APPENDING) return;
refreshDynamicInput();
}
2022-12-16 09:18:09 +01:00
2023-07-06 19:49:16 +02:00
static update = function(frame = PROJECT.animator.current_frame) {
2022-12-16 09:18:09 +01:00
var _arr = inputs[| 0].getValue();
2022-12-27 04:00:50 +01:00
if(inputs[| 0].value_from == noone) {
inputs[| 0].type = VALUE_TYPE.any;
outputs[| 0].type = VALUE_TYPE.any;
return;
}
2022-12-16 09:18:09 +01:00
if(!is_array(_arr)) return;
2023-02-28 09:43:01 +01:00
var _type = inputs[| 0].value_from.type;
2023-04-11 20:29:20 +02:00
var spd = inputs[| 1].getValue();
2022-12-27 04:00:50 +01:00
inputs[| 0].type = _type;
outputs[| 0].type = _type;
2023-02-28 09:43:01 +01:00
var _out = array_clone(_arr);
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i += data_length ) {
var _val = inputs[| i].getValue();
inputs[| i].type = _type;
2023-04-11 20:29:20 +02:00
if(is_array(_val) && spd)
2023-02-28 09:43:01 +01:00
array_append(_out, _val);
else
array_push(_out, _val);
}
2022-12-16 09:18:09 +01:00
outputs[| 0].setValue(_out);
}
2023-02-28 09:43:01 +01:00
static postDeserialize = function() {
2023-06-13 14:42:06 +02:00
var _inputs = load_map.inputs;
2023-02-28 09:43:01 +01:00
2023-06-13 14:42:06 +02:00
for(var i = input_fix_len; i < array_length(_inputs); i += data_length )
2023-02-28 09:43:01 +01:00
createNewInput();
}
2023-03-13 10:45:56 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_array_add, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
2022-12-16 09:18:09 +01:00
}