Pixel-Composer/scripts/node_condition/node_condition.gml

115 lines
3.9 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Condition(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2022-01-23 04:08:16 +01:00
name = "Condition";
w = 96;
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Check value", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
2022-01-23 04:08:16 +01:00
.setVisible(true, true);
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Condition", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2024-01-28 09:53:41 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ new scrollItem("Equal", s_node_condition_type, 0),
new scrollItem("Not equal", s_node_condition_type, 1),
new scrollItem("Less ", s_node_condition_type, 2),
new scrollItem("Less or equal ", s_node_condition_type, 3),
new scrollItem("Greater ", s_node_condition_type, 4),
new scrollItem("Greater or equal", s_node_condition_type, 5), ])
2023-02-14 05:32:32 +01:00
.rejectArray();
inputs[| 2] = nodeValue("Compare to", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
.rejectArray();
2022-01-23 04:08:16 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("True", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1 )
2022-01-23 04:08:16 +01:00
.setVisible(true, true);
2023-02-14 05:32:32 +01:00
inputs[| 4] = nodeValue("False", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1 )
2022-01-23 04:08:16 +01:00
.setVisible(true, true);
2023-02-14 05:32:32 +01:00
inputs[| 5] = nodeValue("Eval mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2023-03-29 15:02:03 +02:00
.setDisplay(VALUE_DISPLAY.enum_scroll, ["Boolean", "Number compare", "Text compare" ])
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-12-13 09:20:36 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 6] = nodeValue("Boolean", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false )
.setVisible(true, true)
.rejectArray();
2022-12-13 09:20:36 +01:00
2023-03-29 15:02:03 +02:00
inputs[| 7] = nodeValue("Text 1", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "" );
inputs[| 8] = nodeValue("Text 2", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "" );
2022-12-13 09:20:36 +01:00
input_display_list = [ 5,
2023-03-29 15:02:03 +02:00
["Condition", false], 0, 1, 2, 6, 7, 8,
2022-12-13 09:20:36 +01:00
["Result", true], 3, 4
2022-01-23 04:08:16 +01:00
]
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Result", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, []);
outputs[| 1] = nodeValue("Bool", self, JUNCTION_CONNECT.output, VALUE_TYPE.boolean, false);
2022-12-13 09:20:36 +01:00
2023-10-27 13:55:31 +02:00
static step = function() { #region
var _mode = getInputData(5);
2022-12-13 09:20:36 +01:00
2023-03-29 15:02:03 +02:00
inputs[| 0].setVisible(_mode == 1, _mode == 1);
inputs[| 1].setVisible(_mode == 1);
inputs[| 2].setVisible(_mode == 1, _mode == 1);
inputs[| 6].setVisible(_mode == 0, _mode == 0);
inputs[| 7].setVisible(_mode == 2, _mode == 2);
inputs[| 8].setVisible(_mode == 2, _mode == 2);
2023-10-27 13:55:31 +02:00
inputs[| 3].setType(inputs[| 3].isLeaf()? VALUE_TYPE.any : inputs[| 3].value_from.type);
inputs[| 4].setType(inputs[| 4].isLeaf()? VALUE_TYPE.any : inputs[| 4].value_from.type);
} #endregion
2022-01-23 04:08:16 +01:00
2023-10-27 13:55:31 +02:00
static update = function(frame = CURRENT_FRAME) { #region
var _true = getInputData(3);
var _fals = getInputData(4);
2022-12-13 09:20:36 +01:00
var _mode = getInputData(5);
2022-12-13 09:20:36 +01:00
var _chck = getInputData(0);
var _cond = getInputData(1);
var _valu = getInputData(2);
var _bool = getInputData(6);
var _txt1 = getInputData(7);
var _txt2 = getInputData(8);
2022-01-23 04:08:16 +01:00
var res = false;
2023-03-29 15:02:03 +02:00
switch(_mode) {
case 0 : res = _bool; break;
case 1 :
switch(_cond) {
case 0 : res = _chck == _valu; break;
case 1 : res = _chck != _valu; break;
case 2 : res = _chck < _valu; break;
case 3 : res = _chck <= _valu; break;
case 4 : res = _chck > _valu; break;
case 5 : res = _chck >= _valu; break;
}
break;
case 2 : res = _txt1 == _txt2; break;
}
2022-01-23 04:08:16 +01:00
2022-01-25 10:58:11 +01:00
if(res) {
outputs[| 0].setValue(_true);
2023-10-07 16:23:40 +02:00
outputs[| 0].setType(inputs[| 3].type);
2023-03-13 10:45:56 +01:00
outputs[| 0].display_type = inputs[| 3].display_type;
2022-01-25 10:58:11 +01:00
} else {
outputs[| 0].setValue(_fals);
2023-10-07 16:23:40 +02:00
outputs[| 0].setType(inputs[| 4].type);
2023-03-13 10:45:56 +01:00
outputs[| 0].display_type = inputs[| 4].display_type;
2022-01-25 10:58:11 +01:00
}
2022-12-13 09:20:36 +01:00
outputs[| 1].setValue(res);
2023-10-27 13:55:31 +02:00
} #endregion
2022-12-13 09:20:36 +01:00
2023-10-27 13:55:31 +02:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2022-12-13 09:20:36 +01:00
var val = outputs[| 1].getValue();
var frm = val? inputs[| 3] : inputs[| 4];
var to = outputs[| 0];
var c0 = value_color(frm.type);
draw_set_color(c0);
draw_set_alpha(0.5);
draw_line_width(frm.x, frm.y, to.x, to.y, _s * 4);
draw_set_alpha(1);
2023-10-27 13:55:31 +02:00
} #endregion
2022-01-23 04:08:16 +01:00
}