Pixel-Composer/scripts/node_struct/node_struct.gml

101 lines
2.7 KiB
Text
Raw Normal View History

2023-03-11 01:40:17 +01:00
function Node_Struct(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Struct";
2024-05-02 11:05:02 +02:00
setDimension(96, 48);
2023-03-11 01:40:17 +01:00
outputs[| 0] = nodeValue("Struct", self, JUNCTION_CONNECT.output, VALUE_TYPE.struct, {});
static createNewInput = function() {
var index = ds_list_size(inputs);
inputs[| index + 0] = nodeValue("Key", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "" );
inputs[| index + 1] = nodeValue("value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0 )
.setVisible(false, false);
}
2023-08-05 14:00:33 +02:00
setIsDynamicInput(2);
2023-03-11 01:40:17 +01:00
if(!LOADING && !APPENDING) createNewInput();
static refreshDynamicInput = function() {
var _in = ds_list_create();
for( var i = 0; i < input_fix_len; i++ )
ds_list_add(_in, inputs[| i]);
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
if(getInputData(i) != "") {
2023-03-11 01:40:17 +01:00
ds_list_add(_in, inputs[| i + 0]);
ds_list_add(_in, inputs[| i + 1].setVisible(false, true));
} else {
delete inputs[| i + 0];
delete inputs[| i + 1];
}
}
for( var i = 0; i < ds_list_size(_in); i++ )
_in[| i].index = i;
ds_list_destroy(inputs);
inputs = _in;
createNewInput();
}
static onValueUpdate = function(index = 0) {
if(LOADING || APPENDING) return;
refreshDynamicInput();
2023-03-21 03:01:53 +01:00
if(index < 0) return;
if(safe_mod(index - input_fix_len, data_length) == 0)
inputs[| index + 1].name = getInputData(index) + " value";
2023-03-11 01:40:17 +01:00
}
2023-09-26 14:35:25 +02:00
static step = function() {
2023-03-11 01:40:17 +01:00
for(var i = input_fix_len; i < ds_list_size(inputs) - data_length; i += data_length) {
var inp = inputs[| i + 1];
var typ = inp.value_from == noone? VALUE_TYPE.any : inp.value_from.type;
2023-10-07 16:23:40 +02:00
inp.setType(typ);
2023-03-11 01:40:17 +01:00
}
}
2023-09-26 14:35:25 +02:00
static update = function() {
2023-03-11 01:40:17 +01:00
var str = {};
for(var i = input_fix_len; i < ds_list_size(inputs) - data_length; i += data_length) {
var key = getInputData(i + 0);
var val = getInputData(i + 1);
2023-06-13 14:42:06 +02:00
var frm = inputs[| i + 1].value_from;
2023-03-11 01:40:17 +01:00
2023-06-13 14:42:06 +02:00
if(frm != noone && frm.type == VALUE_TYPE.surface)
2023-03-21 03:01:53 +01:00
str[$ key] = new Surface(val);
else if(frm != noone && frm.type == VALUE_TYPE.buffer)
str[$ key] = new Buffer(val);
2023-03-21 03:01:53 +01:00
else
str[$ key] = val;
2023-03-11 01:40:17 +01:00
}
outputs[| 0].setValue(str);
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
draw_set_text(f_sdf, fa_left, fa_center, COLORS._main_text);
2023-03-11 01:40:17 +01:00
for(var i = input_fix_len; i < ds_list_size(inputs) - data_length; i += data_length) {
var key = getInputData(i + 0);
2023-03-11 01:40:17 +01:00
var val = inputs[| i + 1];
var _ss = min(_s * 0.5, string_scale(key, bbox.w - 12 * _s, 9999));
2023-03-11 01:40:17 +01:00
draw_set_color(value_color(val.type));
draw_text_transformed(bbox.x0 + 6 * _s, inputs[| i + 0].y, key, _ss, _ss, 0);
2023-03-11 01:40:17 +01:00
}
}
static doApplyDeserialize = function() {
refreshDynamicInput();
}
}