Pixel-Composer/scripts/node_fn_math/node_fn_math.gml
2024-05-31 17:51:14 +07:00

56 lines
No EOL
1.5 KiB
Text

function Node_Fn_Math(_x, _y, _group = noone) : Node_Fn(_x, _y, _group) constructor {
name = "Math";
time_based = false;
inputs[| inl + 0] = nodeValue("Operation", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2 )
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Add", "Minus", "Multiply" ] );
inputs[| inl + 1] = nodeValue("Value 1", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
.setVisible(true, true);
inputs[| inl + 2] = nodeValue("Value 2", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
.setVisible(true, true);
array_append(input_display_list, [
["Value", false], inl + 0, inl + 1, inl + 2,
]);
type = 0;
static __fnEval = function(_x) {
switch(type) {
case 0 : return _x[0] + _x[1];
case 1 : return _x[0] - _x[1];
case 2 : return _x[0] * _x[1];
}
return 0;
}
static refreshDisplayX = function(i) {
var _v0 = getSingleValue(inl + 1);
var _v1 = getSingleValue(inl + 2);
var _f0 = inputs[| inl + 1].value_from;
if(_f0 != noone && is_instanceof(_f0.node, Node_Fn))
_v0 = _f0.node.getDisplayX(i);
var _f1 = inputs[| inl + 2].value_from;
if(_f1 != noone && is_instanceof(_f1.node, Node_Fn))
_v1 = _f1.node.getDisplayX(i);
return [ _v0, _v1 ];
}
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
type = _data[inl + 0];
var v0 = _data[inl + 1];
var v1 = _data[inl + 2];
var val = __fnEval([ v0, v1 ]);
text_display = val;
return val;
} #endregion
}