Pixel-Composer/scripts/var_comparison/var_comparison.gml

35 lines
978 B
Plaintext
Raw Normal View History

2023-12-24 12:06:44 +01:00
function isEqual(val1, val2, struct_expand = false, _depth = 0) { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-12-24 12:06:44 +01:00
if(_depth > 8) return false;
if(is_array(val1) && is_array(val2)) return array_member_equal(val1, val2, _depth);
if(struct_expand && is_struct(val1) && is_struct(val2)) return struct_equal(val1, val2, _depth);
return val1 == val2;
2023-12-24 12:06:44 +01:00
} #endregion
2023-12-24 12:06:44 +01:00
function array_member_equal(arr1, arr2, _depth = 0) { #region
2023-11-08 08:38:04 +01:00
INLINE
if(array_length(arr1) != array_length(arr2)) return false;
for( var i = 0, n = array_length(arr1); i < n; i++ )
2023-12-24 12:06:44 +01:00
if(!isEqual(arr1[i], arr2[i],, _depth + 1)) return false;
return true;
2023-12-24 12:06:44 +01:00
} #endregion
2023-12-24 12:06:44 +01:00
function struct_equal(str1, str2, _depth = 0) { #region
2023-11-08 08:38:04 +01:00
INLINE
var key1 = variable_struct_get_names(str1);
var key2 = variable_struct_get_names(str2);
if(!array_equals(key1, key2)) return false;
for( var i = 0, n = array_length(key1); i < n; i++ )
2023-12-24 12:06:44 +01:00
if(!isEqual(str1[$ key1[i]], str2[$ key1[i]],, _depth + 1)) return false;
return true;
2023-12-24 12:06:44 +01:00
} #endregion