From f0fa4e0b6b482a364aa33a03a4d07477a85cf84d Mon Sep 17 00:00:00 2001 From: Tanasart <22589759+Ttanasart-pt@users.noreply.github.com> Date: Fri, 24 Mar 2023 18:10:01 +0700 Subject: [PATCH] 1.14pr4 --- scripts/node_array_get/node_array_get.gml | 13 ++++++++----- scripts/node_array_insert/node_array_insert.gml | 9 +++++++-- scripts/node_array_remove/node_array_remove.gml | 4 +++- scripts/node_array_set/node_array_set.gml | 8 ++++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/scripts/node_array_get/node_array_get.gml b/scripts/node_array_get/node_array_get.gml index a0c84ee74..fa54c6c90 100644 --- a/scripts/node_array_get/node_array_get.gml +++ b/scripts/node_array_get/node_array_get.gml @@ -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); } diff --git a/scripts/node_array_insert/node_array_insert.gml b/scripts/node_array_insert/node_array_insert.gml index 151167169..cd6e2c550 100644 --- a/scripts/node_array_insert/node_array_insert.gml +++ b/scripts/node_array_insert/node_array_insert.gml @@ -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); diff --git a/scripts/node_array_remove/node_array_remove.gml b/scripts/node_array_remove/node_array_remove.gml index 1aa40ef1d..d7ec3235c 100644 --- a/scripts/node_array_remove/node_array_remove.gml +++ b/scripts/node_array_remove/node_array_remove.gml @@ -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 ]; diff --git a/scripts/node_array_set/node_array_set.gml b/scripts/node_array_set/node_array_set.gml index 9c487705d..b542abdb5 100644 --- a/scripts/node_array_set/node_array_set.gml +++ b/scripts/node_array_set/node_array_set.gml @@ -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); }