Pixel-Composer/scripts/node_argument/node_argument.gml

49 lines
1.3 KiB
Plaintext
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;
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Text("Tag", self, ""));
2024-02-11 13:22:20 +01:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Enum_Scroll("Type", self, 0, [ "String", "Number" ]));
2024-02-11 13:22:20 +01:00
2024-08-18 06:16:20 +02:00
newInput(2, nodeValue_Text("Default value", self, ""));
2024-02-15 14:23:26 +01:00
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Value", self, VALUE_TYPE.text, "");
2024-02-11 13:22:20 +01:00
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 :
2024-08-08 06:57:51 +02:00
inputs[2].setType(VALUE_TYPE.text);
outputs[0].setType(VALUE_TYPE.text);
2024-02-15 14:23:26 +01:00
break;
case 1 :
2024-08-08 06:57:51 +02:00
inputs[2].setType(VALUE_TYPE.float);
outputs[0].setType(VALUE_TYPE.float);
2024-02-15 14:23:26 +01:00
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) {
2024-08-08 06:57:51 +02:00
case 0 : outputs[0].setValue(val); break;
case 1 : outputs[0].setValue(toNumber(val)); 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 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
}