2023-02-28 09:43:01 +01:00
function Node_VFX_Spawner(_x, _y, _group = noone) : Node_VFX_Spawner_Base(_x, _y, _group) constructor {
2023-10-29 06:29:10 +01:00
name = "Spawner";
color = COLORS.node_blend_vfx;
icon = THEME.vfx;
reloop = true;
2022-12-13 09:20:36 +01:00
2023-06-13 14:42:06 +02:00
attributes.Output_pool = false;
2023-10-30 04:18:18 +01:00
array_push(attributeEditors, ["Output all particles", function() { return attributes.Output_pool; },
new checkBox(function() { attributes.Output_pool = !attributes.Output_pool; }) ]);
2023-10-09 16:07:33 +02:00
inputs[| 21].setVisible(false, false);
2023-02-14 05:32:32 +01:00
inputs[| input_len + 0] = nodeValue("Spawn trigger", self, JUNCTION_CONNECT.input, VALUE_TYPE.node, false)
2022-12-16 09:18:09 +01:00
.setVisible(true, true);
2022-12-13 09:20:36 +01:00
2023-02-14 05:32:32 +01:00
inputs[| input_len + 1] = nodeValue("Step interval", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1, "How often the 'on step' event is triggered.\nWith 1 being trigger every frame, 2 means triggered once every 2 frames.");
2022-12-13 09:20:36 +01:00
2023-10-09 16:07:33 +02:00
outputs[| 0] = nodeValue("Particles", self, JUNCTION_CONNECT.output, VALUE_TYPE.particle, [] );
outputs[| 1] = nodeValue("On create", self, JUNCTION_CONNECT.output, VALUE_TYPE.node, noone );
outputs[| 2] = nodeValue("On step", self, JUNCTION_CONNECT.output, VALUE_TYPE.node, noone );
outputs[| 3] = nodeValue("On destroy", self, JUNCTION_CONNECT.output, VALUE_TYPE.node, noone );
2022-12-13 09:20:36 +01:00
2022-12-16 09:18:09 +01:00
array_insert(input_display_list, 0, ["Trigger", true], input_len + 0, input_len + 1);
2022-12-13 09:20:36 +01:00
2023-03-28 06:58:28 +02:00
UPDATE_PART_FORWARD
2023-01-17 08:11:55 +01:00
2023-10-09 16:07:33 +02:00
static onUpdate = function(frame = CURRENT_FRAME) { #region
2023-10-31 13:33:36 +01:00
if(IS_PLAYING) runVFX(frame);
2023-03-13 10:45:56 +01:00
2023-06-13 14:42:06 +02:00
if(attributes.Output_pool) {
2023-03-13 10:45:56 +01:00
outputs[| 0].setValue(parts);
return;
} else {
var _parts = [];
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(parts); i < n; i++ ) {
2023-03-13 10:45:56 +01:00
if(!parts[i].active) continue;
array_push(_parts, parts[i]);
}
outputs[| 0].setValue(_parts);
}
2023-09-29 04:22:41 +02:00
} #endregion
2023-02-23 07:02:19 +01:00
2023-09-29 04:22:41 +02:00
static onSpawn = function(_time, part) { #region
2022-12-16 09:18:09 +01:00
part.step_int = inputs[| input_len + 1].getValue(_time);
2023-09-29 04:22:41 +02:00
} #endregion
2022-12-13 09:20:36 +01:00
2023-09-29 04:22:41 +02:00
static onPartCreate = function(part) { #region
2023-01-17 08:11:55 +01:00
var vt = outputs[| 1];
if(ds_list_empty(vt.value_to)) return;
2022-12-16 09:18:09 +01:00
var pv = part.getPivot();
2022-12-13 09:20:36 +01:00
2022-12-16 09:18:09 +01:00
for( var i = 0; i < ds_list_size(vt.value_to); i++ ) {
var _n = vt.value_to[| i];
if(_n.value_from != vt) continue;
2023-10-09 16:07:33 +02:00
_n.node.spawn(part.frame, pv);
2022-12-16 09:18:09 +01:00
}
2023-09-29 04:22:41 +02:00
} #endregion
2022-12-13 09:20:36 +01:00
2023-09-29 04:22:41 +02:00
static onPartStep = function(part) { #region
2022-12-16 09:18:09 +01:00
var vt = outputs[| 2];
2023-01-17 08:11:55 +01:00
if(ds_list_empty(vt.value_to)) return;
var pv = part.getPivot();
2023-10-02 08:57:44 +02:00
2022-12-16 09:18:09 +01:00
for( var i = 0; i < ds_list_size(vt.value_to); i++ ) {
var _n = vt.value_to[| i];
if(_n.value_from != vt) continue;
2023-10-09 16:07:33 +02:00
_n.node.spawn(part.frame, pv);
2022-12-13 09:20:36 +01:00
}
2023-09-29 04:22:41 +02:00
} #endregion
2022-12-13 09:20:36 +01:00
2023-09-29 04:22:41 +02:00
static onPartDestroy = function(part) { #region
2022-12-16 09:18:09 +01:00
var vt = outputs[| 3];
2023-01-17 08:11:55 +01:00
if(ds_list_empty(vt.value_to)) return;
var pv = part.getPivot();
2022-12-16 09:18:09 +01:00
for( var i = 0; i < ds_list_size(vt.value_to); i++ ) {
var _n = vt.value_to[| i];
if(_n.value_from != vt) continue;
2023-10-09 16:07:33 +02:00
_n.node.spawn(part.frame, pv);
2022-12-13 09:20:36 +01:00
}
2023-09-29 04:22:41 +02:00
} #endregion
2022-12-13 09:20:36 +01:00
2023-09-29 04:22:41 +02:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2023-10-02 08:57:44 +02:00
var spr = getInputData(0);
2022-12-13 09:20:36 +01:00
2022-12-16 09:18:09 +01:00
if(spr == 0) {
2023-02-14 05:32:32 +01:00
if(!is_surface(def_surface))
return;
2022-12-16 09:18:09 +01:00
spr = def_surface;
2022-12-13 09:20:36 +01:00
}
2022-12-16 09:18:09 +01:00
if(is_array(spr))
spr = spr[safe_mod(round(current_time / 100), array_length(spr))];
2022-12-13 09:20:36 +01:00
2022-12-16 09:18:09 +01:00
var cx = xx + w * _s / 2;
var cy = yy + h * _s / 2;
2023-09-08 21:37:36 +02:00
var ss = min((w - 8) / surface_get_width_safe(spr), (h - 8) / surface_get_height_safe(spr)) * _s;
2022-12-16 09:18:09 +01:00
draw_surface_align(spr, cx, cy, ss, fa_center, fa_center);
2023-09-29 04:22:41 +02:00
} #endregion
2023-10-09 16:07:33 +02:00
getPreviewingNode = VFX_PREVIEW_NODE;
2022-12-13 09:20:36 +01:00
}