Pixel-Composer/scripts/node_struct_get/node_struct_get.gml

64 lines
1.8 KiB
Text
Raw Normal View History

2023-03-11 01:40:17 +01:00
function Node_Struct_Get(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Struct Get";
previewable = false;
w = 96;
inputs[| 0] = nodeValue("Struct", self, JUNCTION_CONNECT.input, VALUE_TYPE.struct, {})
.setVisible(true, true);
inputs[| 1] = nodeValue("Key", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "");
outputs[| 0] = nodeValue("Struct", self, JUNCTION_CONNECT.output, VALUE_TYPE.struct, {});
2023-09-26 14:35:25 +02:00
static update = function() {
var str = getInputData(0);
var key = getInputData(1);
2023-03-11 01:40:17 +01:00
var keys = string_splice(key, ".");
var _str = str;
var out = outputs[| 0];
for( var j = 0; j < array_length(keys); j++ ) {
var k = keys[j];
if(!variable_struct_exists(_str, k)) {
out.setValue(0);
2023-10-07 16:23:40 +02:00
out.setType(VALUE_TYPE.float);
2023-03-11 01:40:17 +01:00
break;
}
var val = variable_struct_get(_str, k);
if(j == array_length(keys) - 1) {
2023-03-21 03:01:53 +01:00
if(is_struct(val)) {
if(is_instanceof(val, Surface)) {
2023-10-07 16:23:40 +02:00
out.setType(VALUE_TYPE.surface);
2023-03-21 03:01:53 +01:00
val = val.get();
} else if(is_instanceof(val, Buffer)) {
2023-10-07 16:23:40 +02:00
out.setType(VALUE_TYPE.buffer);
2023-06-24 22:12:35 +02:00
val = val.buffer;
} else
2023-10-07 16:23:40 +02:00
out.setType(VALUE_TYPE.struct);
2023-03-21 03:01:53 +01:00
} else if(is_array(val) && array_length(val))
2023-10-07 16:23:40 +02:00
out.setType(is_string(val[0])? VALUE_TYPE.text : VALUE_TYPE.float);
2023-03-11 01:40:17 +01:00
else
2023-10-07 16:23:40 +02:00
out.setType(is_string(val)? VALUE_TYPE.text : VALUE_TYPE.float);
2023-03-11 01:40:17 +01:00
out.setValue(val);
}
if(is_struct(val)) _str = val;
else break;
}
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
var str = getInputData(1);
2023-03-11 01:40:17 +01:00
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
}
}