2023-02-28 09:43:01 +01:00
|
|
|
function Node_Array_Set(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2024-03-28 14:18:02 +01:00
|
|
|
name = "Array Set";
|
|
|
|
setDimension(96, 32 + 24);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(0, nodeValue("Array", self, CONNECT_TYPE.input, VALUE_TYPE.any, 0))
|
2023-02-14 02:48:33 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(1, nodeValue_Int("Index", self, 0));
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(2, nodeValue("Value", self, CONNECT_TYPE.input, VALUE_TYPE.any, 0))
|
2023-02-14 02:48:33 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Array", self, VALUE_TYPE.any, 0);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
static update = function(frame = CURRENT_FRAME) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _arr = getInputData(0);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[0].setType(VALUE_TYPE.any);
|
|
|
|
inputs[2].setType(VALUE_TYPE.any);
|
|
|
|
outputs[0].setType(VALUE_TYPE.any);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
if(!is_array(_arr)) return;
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var index = getInputData(1);
|
|
|
|
var value = getInputData(2);
|
2023-02-14 02:48:33 +01:00
|
|
|
var _len = array_length(_arr);
|
|
|
|
|
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);
|
|
|
|
inputs[2].setType(type);
|
|
|
|
outputs[0].setType(type);
|
2023-02-14 02:48:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-25 12:27:04 +01:00
|
|
|
if(index[i] < 0) index[i] = array_length(arr) + index[i];
|
2023-02-14 02:48:33 +01:00
|
|
|
array_safe_set(arr, index[i], array_safe_get(value, i,, ARRAY_OVERFLOW.loop));
|
2023-03-24 12:10:01 +01:00
|
|
|
}
|
|
|
|
} else {
|
2023-03-25 12:27:04 +01:00
|
|
|
if(index < 0) index = array_length(arr) + index;
|
2023-02-14 02:48:33 +01:00
|
|
|
array_safe_set(arr, index, value);
|
2023-03-24 12:10:01 +01:00
|
|
|
}
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-08-08 06:57:51 +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-11-23 08:28:04 +01:00
|
|
|
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
|
2023-10-02 08:57:44 +02:00
|
|
|
var idx = getInputData(1);
|
2023-09-14 16:29:39 +02:00
|
|
|
var str = string(idx);
|
2023-02-14 02:48:33 +01:00
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
2023-09-14 16:29:39 +02:00
|
|
|
var ss = string_scale(str, bbox.w, bbox.h);
|
|
|
|
|
2023-02-14 02:48:33 +01:00
|
|
|
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
|
|
|
|
}
|
|
|
|
}
|