2023-01-04 02:30:04 +01:00
|
|
|
enum COMPARE_OPERATOR {
|
|
|
|
equal,
|
|
|
|
nonEqual,
|
|
|
|
|
|
|
|
greater,
|
|
|
|
greaterEqual,
|
|
|
|
|
|
|
|
lesser,
|
|
|
|
lesserEqual,
|
|
|
|
}
|
|
|
|
|
2024-02-16 07:44:36 +01:00
|
|
|
#region create
|
|
|
|
global.node_compare_keys = ["equal", "not equal", "greater", "greater equal", "lesser", "lesser equal"];
|
|
|
|
|
|
|
|
function Node_create_Compare(_x, _y, _group = noone, _param = {}) {
|
|
|
|
var query = struct_try_get(_param, "query", "");
|
2024-07-31 05:45:59 +02:00
|
|
|
var node = new Node_Compare(_x, _y, _group).skipDefault();
|
2024-02-16 07:44:36 +01:00
|
|
|
var ind = -1;
|
|
|
|
|
|
|
|
switch(query) {
|
|
|
|
default : ind = array_find(global.node_compare_keys, query);
|
|
|
|
}
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
if(ind >= 0) node.inputs[0].setValue(ind);
|
2024-02-16 07:44:36 +01:00
|
|
|
|
|
|
|
return node;
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
2024-02-16 07:44:36 +01:00
|
|
|
#endregion
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
function Node_Compare(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-01-04 02:30:04 +01:00
|
|
|
name = "Compare";
|
|
|
|
color = COLORS.node_blend_number;
|
|
|
|
|
2024-05-02 11:05:02 +02:00
|
|
|
setDimension(96, 48);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(0, nodeValue_Enum_Scroll("Type", self, 0, [ new scrollItem("Equal", s_node_condition_type, 0),
|
|
|
|
new scrollItem("Not equal", s_node_condition_type, 1),
|
|
|
|
new scrollItem("Greater ", s_node_condition_type, 4),
|
|
|
|
new scrollItem("Greater or equal", s_node_condition_type, 5),
|
|
|
|
new scrollItem("Lesser", s_node_condition_type, 2),
|
|
|
|
new scrollItem("Lesser or equal", s_node_condition_type, 3), ]));
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(1, nodeValue_Float("a", self, 0))
|
2023-01-04 02:30:04 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(2, nodeValue_Float("b", self, 0))
|
2023-01-04 02:30:04 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-09-04 03:57:11 +02:00
|
|
|
newOutput(0, nodeValue_Output("Result", self, VALUE_TYPE.boolean, false));
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2024-06-15 11:21:33 +02:00
|
|
|
static _compare = function(mode, a, b) {
|
2023-01-04 02:30:04 +01:00
|
|
|
switch(mode) {
|
|
|
|
case COMPARE_OPERATOR.equal : return a == b;
|
|
|
|
case COMPARE_OPERATOR.nonEqual : return a != b;
|
|
|
|
|
|
|
|
case COMPARE_OPERATOR.greater : return a > b;
|
|
|
|
case COMPARE_OPERATOR.greaterEqual : return a >= b;
|
|
|
|
|
|
|
|
case COMPARE_OPERATOR.lesser : return a < b;
|
|
|
|
case COMPARE_OPERATOR.lesserEqual : return a <= b;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-06-15 11:21:33 +02:00
|
|
|
static evalArray = function(mode, a, b) {
|
|
|
|
var _as = is_array(a);
|
|
|
|
var _bs = is_array(b);
|
|
|
|
var al = _as? array_length(a) : 0;
|
|
|
|
var bl = _bs? array_length(b) : 0;
|
2023-01-04 02:30:04 +01:00
|
|
|
|
|
|
|
var val = 0;
|
2024-06-15 11:21:33 +02:00
|
|
|
|
|
|
|
if(!_as && !_bs)
|
|
|
|
val = _compare(mode, a, b);
|
|
|
|
|
|
|
|
else if(!_as && _bs) {
|
2023-01-04 02:30:04 +01:00
|
|
|
for( var i = 0; i < bl; i++ )
|
2024-06-15 11:21:33 +02:00
|
|
|
val[i] = evalArray(mode, a, b[i]);
|
|
|
|
|
|
|
|
} else if(_as && !_bs) {
|
2023-01-04 02:30:04 +01:00
|
|
|
for( var i = 0; i < al; i++ )
|
2024-06-15 11:21:33 +02:00
|
|
|
val[i] = evalArray(mode, a[i], b);
|
|
|
|
|
2023-01-04 02:30:04 +01:00
|
|
|
} else {
|
|
|
|
for( var i = 0; i < max(al, bl); i++ )
|
2024-06-15 11:21:33 +02:00
|
|
|
val[i] = evalArray(mode, array_safe_get_fast(a, i), array_safe_get_fast(b, i));
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
|
|
|
|
2024-06-15 11:21:33 +02:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static update = function(frame = CURRENT_FRAME) {
|
|
|
|
var mode = getInputData(0);
|
|
|
|
var a = getInputData(1);
|
|
|
|
var b = getInputData(2);
|
|
|
|
var val = evalArray(mode, a, b);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(val);
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
2023-11-23 08:28:04 +01:00
|
|
|
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
|
2023-01-04 02:30:04 +01:00
|
|
|
var str = "";
|
2023-10-02 08:57:44 +02:00
|
|
|
switch(getInputData(0)) {
|
2023-01-04 02:30:04 +01:00
|
|
|
case COMPARE_OPERATOR.equal : str = "="; break;
|
|
|
|
case COMPARE_OPERATOR.nonEqual : str = "!="; break;
|
|
|
|
|
|
|
|
case COMPARE_OPERATOR.greater : str = ">"; break;
|
|
|
|
case COMPARE_OPERATOR.greaterEqual : str = ">="; break;
|
|
|
|
|
|
|
|
case COMPARE_OPERATOR.lesser : str = "<"; break;
|
|
|
|
case COMPARE_OPERATOR.lesserEqual : str = "<="; break;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
|
|
|
var ss = string_scale(str, bbox.w, bbox.h);
|
|
|
|
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
|
|
|
|
}
|
|
|
|
}
|