2023-10-29 06:29:10 +01:00
|
|
|
function Node_VFX_Trail(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-12-22 08:42:02 +01:00
|
|
|
name = "VFX Trail";
|
|
|
|
w = 96;
|
|
|
|
|
|
|
|
manual_ungroupable = false;
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
length = [];
|
|
|
|
lengthAcc = [];
|
|
|
|
lines = [];
|
|
|
|
lineLength = [];
|
|
|
|
lineData = [];
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
inputs[| 0] = nodeValue("Particles", self, JUNCTION_CONNECT.input, VALUE_TYPE.particle, -1 )
|
|
|
|
.setVisible(true, true);
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
inputs[| 1] = nodeValue("Life", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4 );
|
|
|
|
|
|
|
|
inputs[| 2] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );
|
2023-10-28 15:28:47 +02:00
|
|
|
|
|
|
|
outputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.output, VALUE_TYPE.pathnode, self);
|
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
|
2023-10-28 15:28:47 +02:00
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(lines); i < n; i++ ) {
|
|
|
|
var _line = lines[i];
|
|
|
|
|
|
|
|
for( var j = 1, m = array_length(_line); j < m; j++ ) {
|
|
|
|
var p0 = _line[j - 1];
|
|
|
|
var p1 = _line[j - 0];
|
|
|
|
|
|
|
|
draw_line(_x + p0[0] * _s, _y + p0[1] * _s,
|
|
|
|
_x + p1[0] * _s, _y + p1[1] * _s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static getLineCount = function() { return array_length(lines); }
|
|
|
|
static getSegmentCount = function() { return array_length(lines); }
|
|
|
|
static getLength = function(index) { return array_safe_get(length, index); }
|
|
|
|
static getAccuLength = function(index) { return array_safe_get(lengthAcc, index, []); }
|
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
static getPointRatio = function(_rat, _ind = 0, out = undefined) { #region
|
|
|
|
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
|
|
|
|
|
2023-10-28 15:28:47 +02:00
|
|
|
var _p0, _p1;
|
|
|
|
var _x, _y;
|
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
var line = lines[_ind];
|
2023-11-30 08:55:33 +01:00
|
|
|
var _len = lineLength[_ind] - 1;
|
|
|
|
var _st = _rat * _len;
|
|
|
|
var _fl = floor(_st);
|
|
|
|
var _fr = frac(_st);
|
|
|
|
|
|
|
|
_p0 = line[clamp(_fl + 0, 0, _len)];
|
|
|
|
_p1 = line[clamp(_fl + 1, 0, _len)];
|
2023-11-06 13:45:03 +01:00
|
|
|
|
2023-11-30 08:55:33 +01:00
|
|
|
if(!is_array(_p0) || !is_array(_p1)) return out;
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-11-30 08:55:33 +01:00
|
|
|
out.x = lerp(_p0[0], _p1[0], _fr);
|
|
|
|
out.y = lerp(_p0[1], _p1[1], _fr);
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
return out;
|
2023-10-28 15:28:47 +02:00
|
|
|
} #endregion
|
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
static getPointDistance = function(_dist, ind = 0, out = undefined) { return getPointRatio(_dist / length[ind], ind, out); }
|
|
|
|
|
|
|
|
static getPathData = function() { return lineData; }
|
2023-10-28 15:28:47 +02:00
|
|
|
|
|
|
|
static getBoundary = function() { #region
|
|
|
|
var boundary = new BoundingBox();
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(lines); i < n; i++ ) {
|
|
|
|
var _line = lines[i];
|
|
|
|
for( var j = 0, m = array_length(_line); j < m; j++ )
|
|
|
|
boundary.addPoint(_line[j][0], _line[j][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return boundary;
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static update = function() { #region
|
2023-10-29 06:29:10 +01:00
|
|
|
var _vfxs = getInputData(0);
|
|
|
|
if(array_empty(_vfxs) || !is_array(_vfxs)) return;
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
var _life = getInputData(1); _life = max(_life, 1);
|
|
|
|
var _colr = getInputData(2);
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-11-30 08:55:33 +01:00
|
|
|
var _totlLen = array_length(_vfxs);
|
|
|
|
lines = array_verify(lines, _totlLen);
|
|
|
|
length = array_verify(length, _totlLen);
|
|
|
|
lengthAcc = array_verify(lengthAcc, _totlLen);
|
|
|
|
lineLength = array_verify(lineLength, _totlLen);
|
|
|
|
lineData = array_verify(lineData, _totlLen);
|
|
|
|
|
|
|
|
var _len = 0;
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-11-30 08:55:33 +01:00
|
|
|
for( var i = 0; i < _totlLen; i++ ) {
|
2023-10-29 06:29:10 +01:00
|
|
|
var _vfx = _vfxs[i];
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
var _posx = _vfx.x_history;
|
|
|
|
var _posy = _vfx.y_history;
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
var _trail_ed = min(_vfx.life_incr, _vfx.life_total);
|
|
|
|
var _trail_st = max(1, _vfx.trailLife - _life);
|
|
|
|
var _trail_len = _trail_ed - _trail_st;
|
|
|
|
|
|
|
|
if(_trail_len <= 0) continue;
|
|
|
|
|
|
|
|
var _lngh = 0;
|
|
|
|
var _ox = _posx[_trail_st], _nx;
|
|
|
|
var _oy = _posy[_trail_st], _ny;
|
2023-11-30 08:55:33 +01:00
|
|
|
var _line = array_verify(lines[_len], _trail_len);
|
|
|
|
var _lenA = array_verify(lengthAcc[_len], _trail_len - 1);
|
2023-10-29 06:29:10 +01:00
|
|
|
_line[0] = [ _ox, _oy ];
|
|
|
|
|
|
|
|
for( var j = 0; j <= _trail_len; j++ ) {
|
|
|
|
var _index = _trail_st + j;
|
|
|
|
if(j == _trail_len) {
|
|
|
|
_nx = _vfx.drawx;
|
|
|
|
_ny = _vfx.drawy;
|
|
|
|
} else {
|
|
|
|
_nx = _posx[_index];
|
|
|
|
_ny = _posy[_index];
|
|
|
|
}
|
2023-10-28 15:28:47 +02:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
var dist = point_distance(_ox, _oy, _nx, _ny);
|
2023-10-28 15:28:47 +02:00
|
|
|
_lngh += dist;
|
2023-10-29 06:29:10 +01:00
|
|
|
_lenA[j] = _lngh;
|
|
|
|
_line[j] = [ _nx, _ny ];
|
2023-10-28 15:28:47 +02:00
|
|
|
|
|
|
|
_ox = _nx;
|
|
|
|
}
|
|
|
|
|
2023-11-30 08:55:33 +01:00
|
|
|
lines[_len] = _line;
|
|
|
|
length[_len] = _lngh;
|
|
|
|
lengthAcc[_len] = _lenA;
|
|
|
|
lineLength[_len] = _trail_len;
|
|
|
|
lineData[_len] = { color: _vfx.blend, };
|
|
|
|
_len++;
|
2023-10-28 15:28:47 +02:00
|
|
|
}
|
|
|
|
|
2023-11-30 08:55:33 +01:00
|
|
|
array_resize(lines, _len);
|
|
|
|
array_resize(length, _len);
|
|
|
|
array_resize(lengthAcc, _len);
|
|
|
|
array_resize(lineLength, _len);
|
|
|
|
array_resize(lineData, _len);
|
|
|
|
|
2023-10-28 15:28:47 +02:00
|
|
|
outputs[| 0].setValue(self);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
|
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
2023-10-29 06:29:10 +01:00
|
|
|
draw_sprite_fit(s_node_vfx_trail, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
|
2023-10-28 15:28:47 +02:00
|
|
|
} #endregion
|
|
|
|
}
|