Pixel-Composer/scripts/node_argument/node_argument.gml

50 lines
1.5 KiB
Text
Raw Normal View History

2024-02-11 13:22:20 +01:00
function Node_Argument(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Argument";
2024-03-28 14:18:02 +01:00
setDimension(96, 32 + 24 * 1);
2024-02-11 13:22:20 +01:00
draw_padding = 8;
inputs[| 0] = nodeValue("Tag", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "");
inputs[| 1] = nodeValue("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "String", "Number" ]);
2024-02-15 14:23:26 +01:00
inputs[| 2] = nodeValue("Default value", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "");
2024-02-11 13:22:20 +01:00
outputs[| 0] = nodeValue("Value", self, JUNCTION_CONNECT.output, VALUE_TYPE.text, "");
2024-02-15 14:23:26 +01:00
static step = function() { #region
2024-02-11 13:22:20 +01:00
var typ = getInputData(1);
switch(typ) {
2024-02-15 14:23:26 +01:00
case 0 :
inputs[| 2].setType(VALUE_TYPE.text);
outputs[| 0].setType(VALUE_TYPE.text);
break;
case 1 :
inputs[| 2].setType(VALUE_TYPE.float);
outputs[| 0].setType(VALUE_TYPE.float);
break;
2024-02-11 13:22:20 +01:00
}
2024-02-15 14:23:26 +01:00
} #endregion
2024-02-11 13:22:20 +01:00
2024-02-15 14:23:26 +01:00
static update = function() { #region
2024-02-11 13:22:20 +01:00
var tag = getInputData(0);
var typ = getInputData(1);
2024-02-15 14:23:26 +01:00
var def = getInputData(2);
var val = struct_try_get(PROGRAM_ARGUMENTS, tag, def);
2024-02-11 13:22:20 +01:00
switch(typ) {
case 0 : outputs[| 0].setValue(val); break;
case 1 : outputs[| 0].setValue(toNumber(val)); break;
}
2024-02-15 14:23:26 +01:00
} #endregion
2024-02-11 13:22:20 +01:00
2024-02-15 14:23:26 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2024-02-11 13:22:20 +01:00
var bbox = drawGetBbox(xx, yy, _s);
var tag = getInputData(0);
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
2024-02-15 14:23:26 +01:00
draw_text_bbox(bbox, $"--{tag}");
} #endregion
2024-02-11 13:22:20 +01:00
}