Pixel-Composer/scripts/node_array_shuffle/node_array_shuffle.gml

39 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Array_Shuffle(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-02-14 02:48:33 +01:00
name = "Shuffle Array";
2024-05-02 11:05:02 +02:00
setDimension(96, 48);
2023-02-14 02:48:33 +01:00
2024-08-20 10:15:53 +02:00
newInput(0, nodeValue("Array in", self, CONNECT_TYPE.input, VALUE_TYPE.any, []))
2023-02-14 02:48:33 +01:00
.setVisible(true, true);
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_Int("Seed", self, seed_random(6)))
2024-08-08 06:57:51 +02:00
.setDisplay(VALUE_DISPLAY._default, { side_button : button(function() { randomize(); inputs[1].setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) })
2023-02-14 02:48:33 +01:00
.rejectArray();
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Shuffled array", self, VALUE_TYPE.any, []);
2023-02-14 02:48:33 +01:00
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) {
var arr = getInputData(0);
var sed = getInputData(1);
2023-02-28 09:43:01 +01:00
2024-08-08 06:57:51 +02:00
inputs[0].setType(VALUE_TYPE.any);
outputs[0].setType(VALUE_TYPE.any);
2023-02-28 09:43:01 +01:00
2023-02-14 02:48:33 +01:00
if(!is_array(arr)) return;
2023-09-14 16:29:39 +02:00
arr = array_clone(arr);
2023-02-14 02:48:33 +01:00
2024-08-08 06:57:51 +02:00
if(inputs[0].value_from != noone) {
inputs[0].setType(inputs[0].value_from.type);
outputs[0].setType(inputs[0].value_from.type);
2023-02-14 02:48:33 +01:00
}
random_set_seed(sed);
arr = array_shuffle(arr);
2024-08-08 06:57:51 +02:00
outputs[0].setValue(arr);
2023-02-14 02:48:33 +01:00
}
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-02-14 02:48:33 +01:00
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_array_shuffle, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
}