From 5767d8c988610d6cc94325451cc6f2d54f18f53c Mon Sep 17 00:00:00 2001 From: Tanasart Date: Mon, 2 Sep 2024 08:27:14 +0700 Subject: [PATCH] [Array Processor] Fix array balancing modify output value. --- .../__node_value_array/__node_value_array.gml | 8 +++----- scripts/array_functions/array_functions.gml | 11 +++++++++++ scripts/globals/globals.gml | 2 +- scripts/node_array/node_array.gml | 1 + scripts/node_processor/node_processor.gml | 4 ++-- scripts/node_value/node_value.gml | 19 +++++++------------ scripts/node_value_area/node_value_area.gml | 2 ++ .../node_value_dimension.gml | 1 + .../node_value_padding/node_value_padding.gml | 1 + scripts/node_value_vec2/node_value_vec2.gml | 1 + .../node_value_vec2_range.gml | 1 - 11 files changed, 30 insertions(+), 21 deletions(-) diff --git a/scripts/__node_value_array/__node_value_array.gml b/scripts/__node_value_array/__node_value_array.gml index cbe2d5f5b..1da366ff9 100644 --- a/scripts/__node_value_array/__node_value_array.gml +++ b/scripts/__node_value_array/__node_value_array.gml @@ -12,27 +12,25 @@ function nodeValue_Vector(_name, _node, _value, _data = {}) { function NodeValue_Array(_name, _node, _value, _tooltip = "", _length = 2) : NodeValue(_name, _node, CONNECT_TYPE.input, VALUE_TYPE.float, _value, _tooltip) constructor { - data_array_length = _length; + def_length = _length; /////============== GET ============= static getValue = function(_time = CURRENT_FRAME, applyUnit = true, arrIndex = 0, useCache = false, log = false) { //// Get value getValueRecursive(self.__curr_get_val, _time); var val = __curr_get_val[0]; - - val = array_verify(val, data_array_length); return val; } static __getAnimValue = function(_time = CURRENT_FRAME) { if(!is_anim) { - if(sep_axis) return array_create_ext(data_array_length, function(i) /*=>*/ {return animators[i].processType(animators[i].values[0].value)}); + if(sep_axis) return array_create_ext(def_length, function(i) /*=>*/ {return animators[i].processType(animators[i].values[0].value)}); return array_empty(animator.values)? 0 : animator.processType(animator.values[0].value); } if(sep_axis) { __temp_time = _time; - return array_create_ext(data_array_length, function(i) /*=>*/ {return animators[i].getValue(__temp_time)}); + return array_create_ext(def_length, function(i) /*=>*/ {return animators[i].getValue(__temp_time)}); } return animator.getValue(_time); diff --git a/scripts/array_functions/array_functions.gml b/scripts/array_functions/array_functions.gml index e038a79d6..c7f21b8a7 100644 --- a/scripts/array_functions/array_functions.gml +++ b/scripts/array_functions/array_functions.gml @@ -298,6 +298,17 @@ function array_spread(arr, _arr = [], _minDepth = 0) { return _arr; } +function array_verify_new(arr, length) { + INLINE + + if(!is_array(arr)) return array_create(length); + if(array_length(arr) == length) return arr; + + arr = array_clone(arr, 1); + array_resize(arr, length); + return arr; +} + function array_verify(arr, length) { INLINE diff --git a/scripts/globals/globals.gml b/scripts/globals/globals.gml index 6307ee9a5..fcef735bc 100644 --- a/scripts/globals/globals.gml +++ b/scripts/globals/globals.gml @@ -39,7 +39,7 @@ LATEST_VERSION = 1_16_00; VERSION = 1_17_11_0; SAVE_VERSION = 1_17_10_0; - VERSION_STRING = "1.17.11"; + VERSION_STRING = "1.17.12.001"; BUILD_NUMBER = 1_17_11_0; HOTKEYS = ds_map_create(); diff --git a/scripts/node_array/node_array.gml b/scripts/node_array/node_array.gml index bece8d146..f9ed035e9 100644 --- a/scripts/node_array/node_array.gml +++ b/scripts/node_array/node_array.gml @@ -146,6 +146,7 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { for( var i = input_fix_len; i < array_length(inputs); i++ ) { var val = getInputData(i); + // if(is_array(val)) val = array_clone(val); if(is_array(val) && spd) array_append(res, val); else array_push(res, val); diff --git a/scripts/node_processor/node_processor.gml b/scripts/node_processor/node_processor.gml index b5100b0f5..66dc27a2e 100644 --- a/scripts/node_processor/node_processor.gml +++ b/scripts/node_processor/node_processor.gml @@ -359,7 +359,7 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct for(var i = 0; i < _len; i++) all_inputs[i] = array_verify(all_inputs[i], process_amount); - for(var l = 0; l < process_amount; l++) #region input preparation + for(var l = 0; l < process_amount; l++) // input preparation for(var i = 0; i < _len; i++) { var _in = inputs_data[i]; @@ -382,7 +382,7 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct } all_inputs[i][l] = inputs[i].arrayBalance(_in[_index]); - } #endregion + } } diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index 628879952..0cfeb7f72 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -1313,20 +1313,15 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru } static arrayBalance = function(val) { - if(!is_array(def_val)) - return val; - - if(isDynamicArray()) - return val; + if(!is_array(def_val)) return val; + if(isDynamicArray()) return val; + if(isArray(val)) return val; + if(!is_array(val)) return array_create(def_length, val); - if(isArray(val)) - return val; - - if(!is_array(val)) - return array_create(def_length, val); - - if(array_length(val) < def_length) + if(array_length(val) < def_length) { + val = array_clone(val, 1); array_resize(val, def_length); + } return val; } diff --git a/scripts/node_value_area/node_value_area.gml b/scripts/node_value_area/node_value_area.gml index b57d5cf16..60789726e 100644 --- a/scripts/node_value_area/node_value_area.gml +++ b/scripts/node_value_area/node_value_area.gml @@ -24,7 +24,9 @@ enum AREA_INDEX { function nodeValue_Area(_name, _node, _value, _data = {}) { return new NodeValue_Area(_name, _node, _value, _data); } function NodeValue_Area(_name, _node, _value, _data = {}) : NodeValue(_name, _node, CONNECT_TYPE.input, VALUE_TYPE.float, _value, "") constructor { + setDisplay(VALUE_DISPLAY.area, _data); + def_length = AREA_ARRAY_LENGTH; /////============== GET ============= diff --git a/scripts/node_value_dimension/node_value_dimension.gml b/scripts/node_value_dimension/node_value_dimension.gml index 2cd9ca1c3..aa66564dc 100644 --- a/scripts/node_value_dimension/node_value_dimension.gml +++ b/scripts/node_value_dimension/node_value_dimension.gml @@ -2,6 +2,7 @@ function nodeValue_Dimension(_node, value = DEF_SURF) { return new NodeValue_Dim function NodeValue_Dimension(_node, value) : NodeValue("Dimension", _node, CONNECT_TYPE.input, VALUE_TYPE.integer, value, "") constructor { setDisplay(VALUE_DISPLAY.vector); + def_length = 2; /////============== GET ============= diff --git a/scripts/node_value_padding/node_value_padding.gml b/scripts/node_value_padding/node_value_padding.gml index ee8770173..405fb7081 100644 --- a/scripts/node_value_padding/node_value_padding.gml +++ b/scripts/node_value_padding/node_value_padding.gml @@ -2,6 +2,7 @@ function nodeValue_Padding(_name, _node, _value, _tooltip = "") { return new Nod function NodeValue_Padding(_name, _node, _value, _tooltip = "") : NodeValue(_name, _node, CONNECT_TYPE.input, VALUE_TYPE.float, _value, _tooltip) constructor { setDisplay(VALUE_DISPLAY.padding); + def_length = 4; /////============== GET ============= diff --git a/scripts/node_value_vec2/node_value_vec2.gml b/scripts/node_value_vec2/node_value_vec2.gml index 80a7493d0..c1cb7d51c 100644 --- a/scripts/node_value_vec2/node_value_vec2.gml +++ b/scripts/node_value_vec2/node_value_vec2.gml @@ -2,6 +2,7 @@ function nodeValue_Vec2(_name, _node, _value, _data = {}) { return new NodeValue function NodeValue_Vec2(_name, _node, _value, _data = {}) : NodeValue(_name, _node, CONNECT_TYPE.input, VALUE_TYPE.float, _value, "") constructor { setDisplay(VALUE_DISPLAY.vector, _data); + def_length = 2; /////============== GET ============= diff --git a/scripts/node_value_vec2_range/node_value_vec2_range.gml b/scripts/node_value_vec2_range/node_value_vec2_range.gml index cccbeb90c..e95f87ca3 100644 --- a/scripts/node_value_vec2_range/node_value_vec2_range.gml +++ b/scripts/node_value_vec2_range/node_value_vec2_range.gml @@ -2,5 +2,4 @@ function nodeValue_Vec2_Range(_name, _node, _value, _data = {}) { return new Nod function NodeValue_Vec2_Range(_name, _node, _value, _data = {}) : NodeValue_Array(_name, _node, _value, "", 4) constructor { setDisplay(VALUE_DISPLAY.vector_range, _data); - } \ No newline at end of file