Pixel-Composer/scripts/node_counter/node_counter.gml

49 lines
1.4 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Counter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-02-14 05:32:32 +01:00
name = "Frame Index";
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-18 06:16:20 +02:00
newInput(0, nodeValue_Float("Start", self, 1));
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Float("Speed", self, 1));
2023-02-14 05:32:32 +01:00
2024-08-20 10:15:53 +02:00
newInput(2, nodeValue_Int("Mode", self, 0, @"Counting mode
2023-01-25 06:49:00 +01:00
- Frame count: Count value up/down per frame.
- Animation progress: Count from 0 (first frame) to 1 (last frame). ")
2024-08-20 10:15:53 +02:00
.setDisplay(VALUE_DISPLAY.enum_scroll, ["Frame count", "Animation progress"]))
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-01-13 05:24:03 +01:00
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Value", self, VALUE_TYPE.float, 0);
2022-01-13 05:24:03 +01:00
2022-12-12 09:08:03 +01:00
input_display_list = [
2, 0, 1
];
static step = function() {
var mode = getInputData(2);
2024-08-08 06:57:51 +02:00
inputs[0].setVisible(mode == 0);
2022-12-12 09:08:03 +01:00
}
2023-08-17 16:56:54 +02:00
static processData = function(_output, _data, _output_index, _array_index = 0) {
2023-10-09 16:07:33 +02:00
var time = CURRENT_FRAME;
2023-02-14 05:32:32 +01:00
var mode = _data[2];
var val = 0;
2022-12-12 09:08:03 +01:00
switch(mode) {
case 0 : val = _data[0] + time * _data[1]; break;
2023-10-09 16:07:33 +02:00
case 1 : val = time / (TOTAL_FRAMES - 1) * _data[1]; break;
2022-12-12 09:08:03 +01: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);
2024-08-08 06:57:51 +02:00
var str = outputs[0].getValue();
2023-01-04 02:30:04 +01:00
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
2023-01-04 02:30:04 +01:00
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
2022-01-13 05:24:03 +01:00
}
}