Pixel-Composer/scripts/node_compare/node_compare.gml

103 lines
3.0 KiB
Plaintext
Raw Normal View History

2023-01-04 02:30:04 +01:00
enum COMPARE_OPERATOR {
equal,
nonEqual,
greater,
greaterEqual,
lesser,
lesserEqual,
}
2023-02-28 09:43:01 +01:00
function Node_create_Compare(_x, _y, _group = noone, _param = "") {
2023-01-04 02:30:04 +01:00
var node = new Node_Compare(_x, _y, _group);
switch(_param) {
case "equal" : node.inputs[| 0].setValue(COMPARE_OPERATOR.equal); break;
case "greater" : node.inputs[| 0].setValue(COMPARE_OPERATOR.greater); break;
case "lesser" : node.inputs[| 0].setValue(COMPARE_OPERATOR.lesser); break;
}
//ds_list_add(PANEL_GRAPH.nodes_list, node);
return node;
}
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;
previewable = false;
w = 96;
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2023-01-04 02:30:04 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Equal", "Not equal", "Greater", "Greater or equal", "Lesser", "Lesser or equal" ]);
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("a", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
2023-01-04 02:30:04 +01:00
.setVisible(true, true);
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("b", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
2023-01-04 02:30:04 +01:00
.setVisible(true, true);
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Result", self, JUNCTION_CONNECT.output, VALUE_TYPE.boolean, false);
2023-01-04 02:30:04 +01:00
static _eval = function(mode, a, b) {
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;
}
2023-02-14 05:32:32 +01:00
function update(frame = ANIMATOR.current_frame) {
2023-01-04 02:30:04 +01:00
var mode = inputs[| 0].getValue();
var a = inputs[| 1].getValue();
var b = inputs[| 2].getValue();
var as = is_array(a);
var bs = is_array(b);
var al = as? array_length(a) : 0;
var bl = bs? array_length(b) : 0;
var val = 0;
if(!as && !bs)
val = _eval(mode, a, b);
else if(!as && bs) {
for( var i = 0; i < bl; i++ )
val[i] = _eval(mode, a, b[i]);
} else if(as && !bs) {
for( var i = 0; i < al; i++ )
val[i] = _eval(mode, a[i], b);
} else {
for( var i = 0; i < max(al, bl); i++ )
val[i] = _eval(mode, array_safe_get(a, i), array_safe_get(b, i));
}
outputs[| 0].setValue(val);
}
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-01-04 02:30:04 +01:00
draw_set_text(f_h3, fa_center, fa_center, COLORS._main_text);
var str = "";
switch(inputs[| 0].getValue()) {
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);
}
}