2023-02-28 09:43:01 +01:00
|
|
|
function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2022-01-19 06:11:17 +01:00
|
|
|
name = "Array";
|
2022-01-13 05:24:03 +01:00
|
|
|
previewable = false;
|
|
|
|
|
|
|
|
w = 96;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, { data: [ "Any", "Surface", "Number", "Color", "Text" ], update_hover: false })
|
2023-02-14 05:32:32 +01:00
|
|
|
.rejectArray();
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-04-11 20:29:20 +02:00
|
|
|
inputs[| 1] = nodeValue("Spread array", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false )
|
|
|
|
.rejectArray();
|
|
|
|
|
2023-11-23 08:28:04 +01:00
|
|
|
array_adjust_tool = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region
|
2023-01-25 06:49:00 +01:00
|
|
|
var _h = ui(48);
|
|
|
|
|
|
|
|
var bw = _w / 2 - ui(4);
|
|
|
|
var bh = ui(36);
|
|
|
|
var bx = _x;
|
|
|
|
var by = _y + ui(8);
|
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, _focus, _hover) == 2) {
|
|
|
|
var amo = ds_list_size(inputs) - input_fix_len;
|
2023-06-13 14:42:06 +02:00
|
|
|
attributes.size = amo + 1;
|
2023-01-25 06:49:00 +01:00
|
|
|
refreshDynamicInput();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_icon_light);
|
|
|
|
var bxc = bx + bw / 2 - (string_width("Add") + ui(64)) / 2;
|
|
|
|
var byc = by + bh / 2;
|
|
|
|
draw_sprite_ui(THEME.add, 0, bxc + ui(24), byc,,,, COLORS._main_icon_light);
|
2023-06-05 18:27:53 +02:00
|
|
|
draw_text(bxc + ui(48), byc, __txt("Add"));
|
2023-01-25 06:49:00 +01:00
|
|
|
|
|
|
|
var bx = _x + bw + ui(8);
|
2023-06-13 14:42:06 +02:00
|
|
|
var amo = attributes.size;
|
2023-01-25 06:49:00 +01:00
|
|
|
if(amo > 1 && buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, _focus, _hover) == 2) {
|
|
|
|
var amo = ds_list_size(inputs) - input_fix_len;
|
2023-06-13 14:42:06 +02:00
|
|
|
attributes.size = max(amo - 1, 1);
|
2023-01-25 06:49:00 +01:00
|
|
|
refreshDynamicInput();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_icon_light);
|
|
|
|
var bxc = bx + bw / 2 - (string_width("Remove") + ui(64)) / 2;
|
|
|
|
var byc = by + bh / 2;
|
|
|
|
draw_sprite_ui(THEME.minus, 0, bxc + ui(24), byc,,,, COLORS._main_icon_light, (amo > 1) * 0.5 + 0.5);
|
|
|
|
draw_set_alpha((amo > 1) * 0.5 + 0.5);
|
2023-06-05 18:27:53 +02:00
|
|
|
draw_text(bxc + ui(48), byc, __txt("Remove"));
|
2023-01-25 06:49:00 +01:00
|
|
|
draw_set_alpha(1);
|
|
|
|
|
|
|
|
return _h;
|
2023-11-23 08:28:04 +01:00
|
|
|
}); #endregion
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-05-07 20:55:13 +02:00
|
|
|
input_display_list = [ 0, array_adjust_tool, 1 ];
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
setIsDynamicInput(1);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, []);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
attributes.size = 1;
|
|
|
|
attributes.spread_value = false;
|
2023-04-10 20:02:59 +02:00
|
|
|
|
2023-11-20 05:10:55 +01:00
|
|
|
static getType = function() { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _type = getInputData(0);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
|
|
|
switch(_type) {
|
2023-02-14 05:32:32 +01:00
|
|
|
case 1 : return VALUE_TYPE.surface;
|
|
|
|
case 2 : return VALUE_TYPE.float;
|
|
|
|
case 3 : return VALUE_TYPE.color;
|
|
|
|
case 4 : return VALUE_TYPE.text;
|
|
|
|
default : return VALUE_TYPE.any;
|
2023-01-25 06:49:00 +01:00
|
|
|
}
|
2023-11-20 05:10:55 +01:00
|
|
|
} #endregion
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2023-11-20 05:10:55 +01:00
|
|
|
static createNewInput = function() { #region
|
2023-02-14 05:32:32 +01:00
|
|
|
var index = ds_list_size(inputs);
|
2023-11-20 05:10:55 +01:00
|
|
|
var _typ = getType();
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| index] = nodeValue("Input", self, JUNCTION_CONNECT.input, _typ, -1 )
|
2022-01-19 06:11:17 +01:00
|
|
|
.setVisible(true, true);
|
2023-01-25 06:49:00 +01:00
|
|
|
array_push(input_display_list, index);
|
|
|
|
|
|
|
|
return inputs[| index];
|
2023-11-20 05:10:55 +01:00
|
|
|
} if(!LOADING && !APPENDING) createNewInput(); #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-11-20 05:10:55 +01:00
|
|
|
static refreshDynamicInput = function() { #region
|
2023-05-07 20:55:13 +02:00
|
|
|
var _l = ds_list_create();
|
2023-06-13 14:42:06 +02:00
|
|
|
var amo = attributes.size;
|
2023-05-07 20:55:13 +02:00
|
|
|
var extra = true;
|
2023-01-25 06:49:00 +01:00
|
|
|
var lastNode = noone;
|
|
|
|
|
2022-01-19 06:11:17 +01:00
|
|
|
for( var i = 0; i < ds_list_size(inputs); i++ ) {
|
2023-11-22 05:17:13 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
if(i < input_fix_len || i < amo || inputs[| i].value_from)
|
2022-01-19 06:11:17 +01:00
|
|
|
ds_list_add(_l, inputs[| i]);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-01-19 06:11:17 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
var _add = amo - (ds_list_size(_l) - input_fix_len);
|
|
|
|
repeat(_add) {
|
|
|
|
lastNode = createNewInput();
|
|
|
|
ds_list_add(_l, lastNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
input_display_list = [];
|
|
|
|
for( var i = 0; i < ds_list_size(_l); i++ ) {
|
2022-12-21 02:30:23 +01:00
|
|
|
_l[| i].index = i;
|
2023-02-14 05:32:32 +01:00
|
|
|
_l[| i].setVisible(i < ds_list_size(_l) - 1);
|
2023-01-25 06:49:00 +01:00
|
|
|
array_push(input_display_list, i);
|
|
|
|
|
2023-10-27 13:55:31 +02:00
|
|
|
if(i >= input_fix_len && _l[| i].isLeaf())
|
2023-01-25 06:49:00 +01:00
|
|
|
extra = false;
|
|
|
|
}
|
|
|
|
array_insert(input_display_list, 1, array_adjust_tool);
|
2022-01-19 06:11:17 +01:00
|
|
|
|
|
|
|
ds_list_destroy(inputs);
|
|
|
|
inputs = _l;
|
|
|
|
|
2023-11-22 05:17:13 +01:00
|
|
|
if(extra) lastNode = createNewInput();
|
2023-11-20 05:10:55 +01:00
|
|
|
} #endregion
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-11-20 05:10:55 +01:00
|
|
|
static onValueUpdate = function(index = 0) { #region
|
2023-11-22 05:17:13 +01:00
|
|
|
if(index < input_fix_len) return;
|
2023-05-07 20:55:13 +02:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
refreshDynamicInput();
|
2023-11-20 05:10:55 +01:00
|
|
|
} #endregion
|
2022-01-19 06:11:17 +01:00
|
|
|
|
2023-11-20 05:10:55 +01:00
|
|
|
static onValueFromUpdate = function(index) { #region
|
2023-01-09 03:14:20 +01:00
|
|
|
if(LOADING || APPENDING) return;
|
|
|
|
|
|
|
|
refreshDynamicInput();
|
2023-11-20 05:10:55 +01:00
|
|
|
} #endregion
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-11-20 05:10:55 +01:00
|
|
|
static update = function(frame = CURRENT_FRAME) { #region
|
2023-02-14 05:32:32 +01:00
|
|
|
var _typ = getType();
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-10-07 16:23:40 +02:00
|
|
|
outputs[| 0].setType(_typ);
|
2023-04-10 20:02:59 +02:00
|
|
|
var res = [];
|
2023-01-25 06:49:00 +01:00
|
|
|
var ind = 0;
|
2023-10-02 08:57:44 +02:00
|
|
|
var spd = getInputData(1);
|
2022-01-19 06:11:17 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i++ ) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var val = getInputData(i);
|
2023-04-10 20:02:59 +02:00
|
|
|
|
2023-11-22 05:17:13 +01:00
|
|
|
if(is_array(val) && spd) array_append(res, val);
|
|
|
|
else array_push(res, val);
|
2023-04-10 20:02:59 +02:00
|
|
|
|
2023-10-07 16:23:40 +02:00
|
|
|
inputs[| i].setType(inputs[| i].value_from? inputs[| i].value_from.type : _typ);
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(i == input_fix_len && _typ == VALUE_TYPE.any && inputs[| i].value_from)
|
2023-10-07 16:23:40 +02:00
|
|
|
outputs[| 0].setType(inputs[| i].value_from.type);
|
2022-01-19 06:11:17 +01:00
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
outputs[| 0].setValue(res);
|
2023-11-22 05:17:13 +01:00
|
|
|
|
|
|
|
if(outputs[| 0].type == VALUE_TYPE.surface) {
|
|
|
|
w = 128;
|
|
|
|
previewable = true;
|
|
|
|
} else {
|
|
|
|
w = 96;
|
|
|
|
previewable = false;
|
|
|
|
}
|
2023-11-20 05:10:55 +01:00
|
|
|
} #endregion
|
2022-01-19 06:11:17 +01:00
|
|
|
|
2023-11-20 05:10:55 +01:00
|
|
|
static doApplyDeserialize = function() { #region
|
2023-03-07 14:29:47 +01:00
|
|
|
var _typ = getType();
|
2023-03-08 07:35:51 +01:00
|
|
|
if(_typ == VALUE_TYPE.any) return;
|
2023-03-07 14:29:47 +01:00
|
|
|
|
|
|
|
for( var i = input_fix_len; i < ds_list_size(inputs); i++ ) {
|
2023-10-07 16:23:40 +02:00
|
|
|
inputs[| i].setType(_typ);
|
2023-03-08 07:35:51 +01:00
|
|
|
inputs[| i].resetDisplay();
|
2023-03-07 14:29:47 +01:00
|
|
|
}
|
2023-11-20 05:10:55 +01:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|