Pixel-Composer/scripts/node_struct/node_struct.gml

100 lines
2.7 KiB
Plaintext
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";
previewable = false;
w = 96;
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;
inp.type = typ;
}
}
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_p0b, fa_left, fa_center, COLORS._main_text);
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];
draw_set_color(value_color(val.type));
draw_text_transformed(bbox.x0 + 6 * _s, inputs[| i + 0].y - 1 * _s, key, _s, _s, 0);
}
}
static doApplyDeserialize = function() {
refreshDynamicInput();
}
}