Pixel-Composer/scripts/node_anim_curve/node_anim_curve.gml

42 lines
1.3 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Anim_Curve(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-02-14 05:32:32 +01:00
name = "Evaluate Curve";
2022-01-13 05:24:03 +01:00
update_on_frame = true;
2024-05-02 11:05:02 +02:00
setDimension(96, 48);
2023-01-17 08:11:55 +01:00
2024-08-08 06:57:51 +02:00
inputs[0] = nodeValue("Curve", self, JUNCTION_CONNECT.input, VALUE_TYPE.curve, CURVE_DEF_01);
inputs[1] = nodeValue_Float("Progress", self, 0)
.setDisplay(VALUE_DISPLAY.slider);
2022-01-13 05:24:03 +01:00
2024-08-08 06:57:51 +02:00
inputs[2] = nodeValue_Float("Minimum", self, 0);
inputs[3] = nodeValue_Float("Maximum", self, 1);
2022-01-13 05:24:03 +01:00
2024-08-08 06:57:51 +02:00
inputs[4] = nodeValue_Bool("Animated", self, false);
2023-10-07 09:09:18 +02:00
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Curve", self, VALUE_TYPE.float, []);
2022-01-13 05:24:03 +01:00
2023-10-07 09:09:18 +02:00
input_display_list = [ 0, 4, 1, 2, 3 ];
static step = function() {
var _anim = getSingleValue(4);
2024-08-08 06:57:51 +02:00
inputs[1].setVisible(!_anim);
2023-10-07 09:09:18 +02:00
}
2023-08-17 16:56:54 +02:00
static processData = function(_output, _data, _output_index, _array_index = 0) {
2022-01-13 05:24:03 +01:00
var curve = _data[0];
2023-10-09 16:07:33 +02:00
var time = _data[4]? CURRENT_FRAME / (TOTAL_FRAMES - 1) : _data[1];
2022-01-13 05:24:03 +01:00
var _min = _data[2];
var _max = _data[3];
2023-02-14 05:32:32 +01:00
var val = eval_curve_x(curve, time) * (_max - _min) + _min;
2022-01-13 05:24:03 +01:00
2024-08-08 06:57:51 +02:00
inputs[0].editWidget.progress_draw = time;
2023-10-07 09:09:18 +02:00
2022-01-13 05:24:03 +01:00
return 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
var bbox = drawGetBbox(xx, yy, _s);
2023-02-14 05:32:32 +01:00
draw_sprite_fit(s_node_curve_eval, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
2022-01-13 05:24:03 +01:00
}
}