2023-02-28 09:43:01 +01:00
function Node_Particle(_x, _y, _group = noone) : Node_VFX_Spawner_Base(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Particle";
use_cache = true;
2023-02-14 05:32:32 +01:00
inputs[| 3].setDisplay(VALUE_DISPLAY.area, function() { return inputs[| input_len + 0].getValue(); });
inputs[| input_len + 0] = nodeValue("Output dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| input_len + 1] = nodeValue("Round position", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true, "Round position to the closest integer value to avoid jittering.");
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| input_len + 2] = nodeValue("Blend mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2023-02-28 09:43:01 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Normal", "Alpha", "Additive" ]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2022-01-13 05:24:03 +01:00
2022-12-13 09:20:36 +01:00
array_insert(input_display_list, 0, ["Output", true], input_len + 0);
array_push(input_display_list, input_len + 1, input_len + 2);
2022-01-13 05:24:03 +01:00
2022-12-13 09:20:36 +01:00
def_surface = -1;
2022-12-10 05:06:01 +01:00
2023-02-23 07:02:19 +01:00
insp2UpdateTooltip = "Clear cache";
insp2UpdateIcon = [ THEME.cache, 0, COLORS._main_icon ];
static onInspector2Update = function() { clearCache(); }
2023-02-14 05:32:32 +01:00
static onValueUpdate = function(index = 0) {
if(index == input_len + 0) {
var _dim = inputs[| input_len + 0].getValue();
var _outSurf = outputs[| 0].getValue();
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);
outputs[| 0].setValue(_outSurf);
}
2023-02-23 07:02:19 +01:00
if(ANIMATOR.is_playing)
ANIMATOR.setFrame(-1);
2023-02-14 05:32:32 +01:00
}
2022-12-13 09:20:36 +01:00
static onStep = function() {
2023-02-23 07:02:19 +01:00
if(recoverCache() || !ANIMATOR.is_playing)
return;
2022-01-13 05:24:03 +01:00
2023-02-19 13:49:20 +01:00
if(ANIMATOR.current_frame == 0)
2022-12-13 09:20:36 +01:00
reset();
2023-02-19 13:49:20 +01:00
runVFX(ANIMATOR.current_frame);
2022-01-13 05:24:03 +01:00
}
2022-12-10 05:06:01 +01:00
function render(_time = ANIMATOR.current_frame) {
2022-12-13 09:20:36 +01:00
var _dim = inputs[| input_len + 0].getValue(_time);
var _exact = inputs[| input_len + 1].getValue(_time);
var _blend = inputs[| input_len + 2].getValue(_time);
2022-01-13 05:24:03 +01:00
var _outSurf = outputs[| 0].getValue();
2022-12-27 04:00:50 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);
outputs[| 0].setValue(_outSurf);
2022-01-13 05:24:03 +01:00
surface_set_target(_outSurf);
2023-02-14 05:32:32 +01:00
draw_clear_alpha(0, 0);
if(_blend == PARTICLE_BLEND_MODE.normal)
2023-02-28 09:43:01 +01:00
BLEND_NORMAL;
else if(_blend == PARTICLE_BLEND_MODE.alpha)
2023-02-19 02:13:19 +01:00
BLEND_ALPHA;
2023-02-14 05:32:32 +01:00
else if(_blend == PARTICLE_BLEND_MODE.additive)
BLEND_ADD;
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
var surf_w = surface_get_width(_outSurf);
var surf_h = surface_get_height(_outSurf);
2023-02-19 13:49:20 +01:00
for(var i = 0; i < PREF_MAP[? "part_max_amount"]; i++)
2023-01-17 08:11:55 +01:00
parts[i].draw(_exact, surf_w, surf_h);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
BLEND_NORMAL;
2022-01-13 05:24:03 +01:00
surface_reset_target();
2023-02-23 07:02:19 +01:00
if(ANIMATOR.is_playing)
cacheCurrentFrame(_outSurf);
2022-01-13 05:24:03 +01:00
}
}