Pixel-Composer/scripts/node_array_sample/node_array_sample.gml

91 lines
2.0 KiB
Plaintext
Raw Normal View History

2023-10-10 07:12:42 +02:00
function Node_Array_Sample(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2024-03-28 14:18:02 +01:00
name = "Array Sample";
setDimension(96, 32 + 24);
2023-10-10 07:12:42 +02:00
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_Float("Array", self, []))
2023-10-10 07:12:42 +02:00
.setArrayDepth(1)
.setVisible(true, true);
newInput(1, nodeValue_Float("Step", self, 1));
newInput(2, nodeValue_Enum_Scroll("Mode", self, 0, [ "Uniform", "Random" ]))
newInput(3, nodeValue_Int("Shift", self, 0))
newInput(4, nodeValueSeed(self, VALUE_TYPE.float));
newInput(5, nodeValue_Int("Amount", self, 4))
2023-10-10 07:12:42 +02:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Array", self, VALUE_TYPE.float, 0))
2023-10-10 07:12:42 +02:00
.setArrayDepth(1);
input_display_list = [ 0, 2,
1, 3,
4, 5,
];
2023-10-10 07:12:42 +02:00
static sample = function(arr) {
__temp_arr = arr;
2023-10-10 07:12:42 +02:00
var _mod = getInputData(2);
var _len = array_length(arr);
if(_mod == 0) {
var _stp = getInputData(1);
var _shf = getInputData(3);
_shf = safe_mod(_shf, _stp);
var _res = [];
var _ind = 0;
for( var i = _shf; i < _len; i += _stp )
_res[_ind++] = arr[i];
return _res;
} else if(_mod == 1) {
var _sed = getInputData(4);
var _amo = getInputData(5);
var _res = array_create(_amo);
random_set_seed(_sed);
for( var i = 0; i < _amo; i++ )
_res[i] = arr[irandom(_len - 1)];
return _res;
}
2023-10-10 07:12:42 +02:00
return [];
2023-10-10 07:12:42 +02:00
}
static update = function(frame = CURRENT_FRAME) {
var _arr = getInputData(0);
var _mod = getInputData(2);
inputs[1].setVisible(_mod == 0);
inputs[3].setVisible(_mod == 0);
inputs[4].setVisible(_mod == 1);
inputs[5].setVisible(_mod == 1);
2023-10-10 07:12:42 +02:00
if(array_empty(_arr)) return;
var res;
if(is_array(_arr[0])) {
for( var i = 0, n = array_length(_arr); i < n; i++ )
res[i] = sample(_arr[i]);
2023-10-10 07:12:42 +02:00
} else
res = sample(_arr);
2023-10-10 07:12:42 +02:00
2024-08-08 06:57:51 +02:00
outputs[0].setValue(res);
2023-10-10 07:12:42 +02:00
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_array_sample, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
}