This commit is contained in:
Tanasart 2023-03-24 18:10:01 +07:00
parent a7d56baffa
commit f0fa4e0b6b
4 changed files with 24 additions and 10 deletions

View File

@ -16,6 +16,8 @@ function Node_Array_Get(_x, _y, _group = noone) : Node(_x, _y, _group) construct
.setDisplay(VALUE_DISPLAY.enum_scroll, ["Clamp", "Loop", "Ping Pong"])
.rejectArray();
inputs[| 3] = nodeValue("Index", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
outputs[| 0] = nodeValue("Value", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
static step = function() {
@ -28,7 +30,7 @@ function Node_Array_Get(_x, _y, _group = noone) : Node(_x, _y, _group) construct
}
}
static getArray = function(_arr, index, _ovf) {
static getArray = function(_arr, index, _ovf, _dim = 0) {
if(!is_array(_arr)) return;
if(is_array(index)) return;
@ -36,12 +38,12 @@ function Node_Array_Get(_x, _y, _group = noone) : Node(_x, _y, _group) construct
switch(_ovf) {
case 0 :
if(index < 0) index = _len + index;
if(index < 0) index = _len - 1 + index;
index = clamp(index, 0, _len - 1);
break;
case 1 :
index = safe_mod(index, _len);
if(index < 0) index = _len + index;
if(index < 0) index = _len - 1 + index;
break;
case 2 :
var _pplen = (_len - 1) * 2;
@ -61,13 +63,14 @@ function Node_Array_Get(_x, _y, _group = noone) : Node(_x, _y, _group) construct
var index = inputs[| 1].getValue();
var _ovf = inputs[| 2].getValue();
var _dim = inputs[| 3].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);
res[i] = getArray(_arr, index[i], _ovf, _dim);
} else
res = getArray(_arr, index, _ovf);
res = getArray(_arr, index, _ovf, _dim);
outputs[| 0].setValue(res);
}

View File

@ -39,14 +39,19 @@ function Node_Array_Insert(_x, _y, _group = noone) : Node(_x, _y, _group) constr
var arr = array_clone(_arr);
if(is_array(index)) {
if(!is_array(value)) value = [ value ];
for( var i = 0; i < array_length(index); i++ )
for( var i = 0; i < array_length(index); i++ ) {
if(index[i] < 0) index[i] = array_length(arr) - 1 + index[i];
array_insert(arr, index[i], array_safe_get(value, i,, ARRAY_OVERFLOW.loop));
}
} else {
if(index < 0) index = array_length(arr) - 1 + index;
if(is_array(value)) {
for( var i = 0; i < array_length(value); i++ )
array_insert(arr, index + i, value[i]);
} else
} else {
array_insert(arr, index, value);
}
}
outputs[| 0].setValue(arr);

View File

@ -54,8 +54,10 @@ function Node_Array_Remove(_x, _y, _group = noone) : Node(_x, _y, _group) constr
if(!is_array(index)) index = [ index ];
array_sort(index, false);
for( var i = 0; i < array_length(index); i++ )
for( var i = 0; i < array_length(index); i++ ) {
if(index[i] < 0) index[i] = array_length(arr) - 1 + index[i];
array_delete(arr, index[i], 1);
}
} else {
if(!is_array(value)) value = [ value ];

View File

@ -39,10 +39,14 @@ function Node_Array_Set(_x, _y, _group = noone) : Node(_x, _y, _group) construct
var arr = array_clone(_arr);
if(is_array(index)) {
if(!is_array(value)) value = [ value ];
for( var i = 0; i < array_length(index); i++ )
for( var i = 0; i < array_length(index); i++ ) {
if(index[i] < 0) index[i] = array_length(arr) - 1 + index[i];
array_safe_set(arr, index[i], array_safe_get(value, i,, ARRAY_OVERFLOW.loop));
} else
}
} else {
if(index < 0) index = array_length(arr) - 1 + index;
array_safe_set(arr, index, value);
}
outputs[| 0].setValue(arr);
}