2022-12-13 09:20:36 +01:00
|
|
|
function Node_Array_Get(_x, _y, _group = -1) : Node(_x, _y, _group) constructor {
|
2022-01-24 02:21:25 +01:00
|
|
|
name = "Array Get";
|
|
|
|
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-01-24 02:21:25 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 1] = nodeValue("Index", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
2022-01-25 04:05:30 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 2] = nodeValue("Overflow", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, ["Clamp", "Loop", "Ping Pong"])
|
|
|
|
.rejectArray();
|
2022-01-24 02:21:25 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0] = nodeValue("Value", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
|
2022-01-24 02:21:25 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
static step = function() {
|
2023-01-04 02:30:04 +01:00
|
|
|
inputs[| 0].type = VALUE_TYPE.any;
|
|
|
|
outputs[| 0].type = VALUE_TYPE.any;
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(inputs[| 0].value_from != noone) {
|
|
|
|
inputs[| 0].type = inputs[| 0].value_from.type;
|
|
|
|
outputs[| 0].type = inputs[| 0].type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 :
|
|
|
|
index = clamp(index, 0, _len - 1);
|
|
|
|
break;
|
|
|
|
case 1 :
|
|
|
|
index = safe_mod(index, _len);
|
|
|
|
if(index < 0) index = _len + index;
|
|
|
|
break;
|
|
|
|
case 2 :
|
|
|
|
var _pplen = (_len - 1) * 2;
|
|
|
|
index = safe_mod(abs(index), _pplen);
|
|
|
|
if(index >= _len)
|
|
|
|
index = _pplen - index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
return array_safe_get(_arr, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static update = function(frame = ANIMATOR.current_frame) {
|
|
|
|
var _arr = inputs[| 0].getValue();
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(!is_array(_arr)) return;
|
|
|
|
|
|
|
|
var index = inputs[| 1].getValue();
|
|
|
|
var _ovf = inputs[| 2].getValue();
|
|
|
|
var res = is_array(index)? array_create(array_length(index)) : 0;
|
|
|
|
|
|
|
|
if(is_array(index)) {
|
|
|
|
for( var i = 0; i < array_length(index); i++ )
|
|
|
|
res[i] = getArray(_arr, index[i], _ovf);
|
|
|
|
} else
|
|
|
|
res = getArray(_arr, index, _ovf);
|
|
|
|
|
|
|
|
outputs[| 0].setValue(res);
|
2022-01-24 02:21:25 +01:00
|
|
|
}
|
2023-01-25 06:49:00 +01:00
|
|
|
|
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s) {
|
|
|
|
draw_set_text(f_h3, fa_center, fa_center, COLORS._main_text);
|
|
|
|
var idx = inputs[| 1].getValue();
|
|
|
|
|
|
|
|
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
|
|
|
}
|