Pixel-Composer/scripts/node_sprite_stack/node_sprite_stack.gml

137 lines
4.6 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Sprite_Stack(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Sprite Stack";
2022-12-27 13:30:02 +01:00
dimension_index = 1;
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Base shape", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
2022-01-13 05:24:03 +01:00
2023-07-21 12:40:20 +02:00
inputs[| 1] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
2022-01-13 05:24:03 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("Stack amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4);
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Stack shift", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 0, 1 ] )
2022-01-13 05:24:03 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 4] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 0, 0 ] )
2022-12-27 04:00:50 +01:00
.setDisplay(VALUE_DISPLAY.vector)
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); });
2022-12-27 04:00:50 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 5] = nodeValue("Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2022-01-13 05:24:03 +01:00
.setDisplay(VALUE_DISPLAY.rotation);
2023-02-14 05:32:32 +01:00
inputs[| 6] = nodeValue("Stack blend", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white );
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 7] = nodeValue("Alpha end", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1, "Alpha value for the last copy." )
2022-01-13 05:24:03 +01:00
.setDisplay(VALUE_DISPLAY.slider, [0, 1, .01]);
2023-02-14 05:32:32 +01:00
inputs[| 8] = nodeValue("Move base", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false, "Make each copy move the original image." );
2022-09-21 06:09:40 +02:00
2023-07-21 12:40:20 +02:00
inputs[| 9] = nodeValue("Highlight", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "None", "Color", "Inner pixel" ]);
inputs[| 10] = nodeValue("Highlight color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white);
inputs[| 11] = nodeValue("Highlight alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider, [0, 1, .01]);
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2022-09-21 06:09:40 +02:00
input_display_list = [
["Output", true], 0, 1,
["Stack", false], 2, 3, 8, 4, 5,
2023-07-21 12:40:20 +02:00
["Render", false], 6, 7, 9, 10, 11,
2022-09-21 06:09:40 +02:00
];
2022-01-13 05:24:03 +01:00
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2022-12-19 13:35:30 +01:00
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
2022-01-13 05:24:03 +01:00
var pos = inputs[| 4].getValue();
var px = _x + pos[0] * _s;
var py = _y + pos[1] * _s;
2022-12-19 13:35:30 +01:00
inputs[| 4].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
inputs[| 5].drawOverlay(active, px, py, _s, _mx, _my, _snx, _sny);
2022-01-13 05:24:03 +01:00
}
2023-07-21 12:40:20 +02:00
static step = function() {
var _high = inputs[| 9].getValue();
inputs[| 10].setVisible(_high);
inputs[| 11].setVisible(_high);
}
2023-08-17 16:56:54 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2023-07-21 12:40:20 +02:00
var _in = _data[0];
var _dim = _data[1];
var _amo = _data[2];
var _shf = _data[3];
var _pos = _data[4];
var _rot = _data[5];
var _col = _data[6];
var _alp = _data[7];
var _mov = _data[8];
2022-01-13 05:24:03 +01:00
2023-07-21 12:40:20 +02:00
var _hig = _data[ 9];
var _hiC = _data[10];
var _hiA = _data[11];
2022-01-13 05:24:03 +01:00
2023-09-14 16:29:39 +02:00
_pos = array_clone(_pos);
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
2022-01-13 05:24:03 +01:00
2022-09-21 06:09:40 +02:00
if(_mov) {
_pos[0] -= _shf[0] * _amo;
_pos[1] -= _shf[1] * _amo;
}
2022-01-13 05:24:03 +01:00
surface_set_target(_outSurf);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
2022-09-21 06:09:40 +02:00
if(is_surface(_in)) {
2023-09-08 21:37:36 +02:00
var _ww = surface_get_width_safe(_in);
var _hh = surface_get_height_safe(_in);
2022-09-21 06:09:40 +02:00
var _po = point_rotate(0, 0, _ww / 2, _hh / 2, _rot);
var aa = _alp;
var aa_delta = (1 - aa) / _amo;
2022-01-13 05:24:03 +01:00
2022-09-21 06:09:40 +02:00
_pos[0] += _shf[0] * _amo;
_pos[1] += _shf[1] * _amo;
2022-01-13 05:24:03 +01:00
2023-07-21 12:40:20 +02:00
for( var i = 0; i < _amo; i++ ) {
if(_hig && i == _amo - 1) {
shader_set(sh_replace_color);
shader_set_i("type", _hig);
shader_set_f("dimension", _ww, _hh);
shader_set_f("shift", _shf[0] / _ww, _shf[1] / _hh);
shader_set_f("angle", degtorad(_rot));
draw_surface_ext_safe(_in, _po[0] + _pos[0], _po[1] + _pos[1], 1, 1, _rot, _hiC, _hiA);
shader_reset();
} else
draw_surface_ext_safe(_in, _po[0] + _pos[0], _po[1] + _pos[1], 1, 1, _rot, _col, aa);
2022-09-21 06:09:40 +02:00
_pos[0] -= _shf[0];
_pos[1] -= _shf[1];
2022-01-13 05:24:03 +01:00
2022-09-21 06:09:40 +02:00
aa += aa_delta;
2022-01-13 05:24:03 +01:00
}
2023-07-21 12:40:20 +02:00
2022-09-21 06:09:40 +02:00
draw_surface_ext_safe(_in, _po[0] + _pos[0], _po[1] + _pos[1], 1, 1, _rot, c_white, aa);
} else if(is_array(_in)) {
2022-01-13 05:24:03 +01:00
for(var i = 0; i < _amo; i++) {
var index = clamp(i, 0, array_length(_in) - 1);
if(is_surface(_in[index])) {
2023-09-08 21:37:36 +02:00
var _ww = surface_get_width_safe(_in[index]);
var _hh = surface_get_width_safe(_in[index]);
2022-01-13 05:24:03 +01:00
var _po = point_rotate(0, 0, _ww / 2, _hh / 2, _rot);
_po[0] += _pos[0];
_po[1] += _pos[1];
draw_surface_ext_safe(_in[index], _po[0] + _pos[0], _po[1] + _pos[1], 1, 1, _rot, _col, 1);
_pos[0] += _shf[0];
_pos[1] += _shf[1];
}
}
}
surface_reset_target();
2022-12-27 04:00:50 +01:00
return _outSurf;
2022-01-13 05:24:03 +01:00
}
}