2023-02-28 09:43:01 +01:00
|
|
|
function Node_Array_Get(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2024-03-28 14:18:02 +01:00
|
|
|
name = "Array Get";
|
|
|
|
setDimension(96, 32 + 24);
|
2022-01-24 02:21:25 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
|
2022-01-24 02:21:25 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[1] = nodeValue_Int("Index", self, 0)
|
2022-01-25 04:05:30 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[2] = nodeValue_Enum_Scroll("Overflow", self, 0, [ "Clamp", "Loop", "Ping Pong" ])
|
2023-02-14 05:32:32 +01:00
|
|
|
.rejectArray();
|
2022-01-24 02:21:25 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Value", self, VALUE_TYPE.any, 0);
|
2022-01-24 02:21:25 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
static step = function() {
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[0].setType(VALUE_TYPE.any);
|
|
|
|
outputs[0].setType(VALUE_TYPE.any);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
if(inputs[0].value_from != noone) {
|
|
|
|
inputs[0].setType(inputs[0].value_from.type);
|
|
|
|
outputs[0].setType(inputs[0].type);
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-25 12:27:04 +01:00
|
|
|
static getArray = function(_arr, index, _ovf) {
|
2022-01-24 02:21:25 +01:00
|
|
|
if(!is_array(_arr)) return;
|
2023-02-14 05:32:32 +01:00
|
|
|
if(is_array(index)) return;
|
2022-01-25 04:05:30 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
var _len = array_length(_arr);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
|
|
|
switch(_ovf) {
|
2022-01-25 04:05:30 +01:00
|
|
|
case 0 :
|
2023-03-25 12:27:04 +01:00
|
|
|
if(index < 0) index = _len + index;
|
2022-01-25 04:05:30 +01:00
|
|
|
index = clamp(index, 0, _len - 1);
|
|
|
|
break;
|
|
|
|
case 1 :
|
|
|
|
index = safe_mod(index, _len);
|
2023-03-25 12:27:04 +01:00
|
|
|
if(index < 0) index = _len + index;
|
2022-01-25 04:05:30 +01:00
|
|
|
break;
|
|
|
|
case 2 :
|
|
|
|
var _pplen = (_len - 1) * 2;
|
|
|
|
index = safe_mod(abs(index), _pplen);
|
|
|
|
if(index >= _len)
|
|
|
|
index = _pplen - index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-03-31 05:36:11 +02:00
|
|
|
return array_safe_get_fast(_arr, index);
|
2023-02-14 05:32:32 +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-01-04 02:30:04 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(!is_array(_arr)) return;
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var index = getInputData(1);
|
|
|
|
var _ovf = getInputData(2);
|
2023-02-14 05:32:32 +01:00
|
|
|
var res = is_array(index)? array_create(array_length(index)) : 0;
|
|
|
|
|
|
|
|
if(is_array(index)) {
|
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
|
|
|
res[i] = getArray(_arr, index[i], _ovf);
|
2023-02-14 05:32:32 +01:00
|
|
|
} else
|
2023-03-25 12:27:04 +01:00
|
|
|
res = getArray(_arr, index, _ovf);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(res);
|
2022-01-24 02:21:25 +01:00
|
|
|
}
|
2023-01-25 06:49:00 +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-01-25 06:49:00 +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);
|
|
|
|
}
|
2022-01-24 02:21:25 +01:00
|
|
|
}
|