Pixel-Composer/scripts/node_VFX_spawner/node_VFX_spawner.gml

94 lines
2.9 KiB
Text
Raw Normal View History

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
manual_ungroupable = false;
2023-06-13 14:42:06 +02:00
attributes.Output_pool = false;
2024-11-30 12:02:41 +01:00
array_push(attributeEditors, ["Output all particles", function() /*=>*/ {return attributes.Output_pool},
new checkBox(function() /*=>*/ { attributes.Output_pool = !attributes.Output_pool; }) ]);
2024-03-22 09:44:11 +01:00
2024-08-08 06:57:51 +02:00
inputs[21].setVisible(false, false);
2023-10-09 16:07:33 +02:00
2024-08-20 10:15:53 +02:00
newInput(input_len + 0, nodeValue("Spawn trigger", self, CONNECT_TYPE.input, VALUE_TYPE.node, false))
2022-12-16 09:18:09 +01:00
.setVisible(true, true);
2022-12-13 09:20:36 +01:00
2024-08-18 06:16:20 +02:00
newInput(input_len + 1, nodeValue_Int("Step interval", self, 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
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Particles", self, VALUE_TYPE.particle, [] ));
newOutput(1, nodeValue_Output("On create", self, VALUE_TYPE.node, noone ));
2024-11-30 12:02:41 +01:00
newOutput(2, nodeValue_Output("On step", self, VALUE_TYPE.node, noone ));
2024-09-04 03:57:11 +02:00
newOutput(3, nodeValue_Output("On destroy", self, 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
2024-08-06 14:04:41 +02:00
static onUpdate = function(frame = CURRENT_FRAME) {
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) {
2024-08-08 06:57:51 +02:00
outputs[0].setValue(parts);
2023-03-13 10:45:56 +01:00
return;
2024-11-30 12:02:41 +01:00
2023-03-13 10:45:56 +01:00
} 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]);
}
2024-11-30 12:02:41 +01:00
2024-08-08 06:57:51 +02:00
outputs[0].setValue(_parts);
2023-03-13 10:45:56 +01:00
}
2024-08-06 14:04:41 +02:00
}
2023-02-23 07:02:19 +01:00
2024-08-06 14:04:41 +02:00
static onSpawn = function(_time, part) {
2024-08-08 06:57:51 +02:00
part.step_int = inputs[input_len + 1].getValue(_time);
2024-08-06 14:04:41 +02:00
}
2022-12-13 09:20:36 +01:00
2024-08-06 14:04:41 +02:00
static onPartCreate = function(part) {
2024-08-08 06:57:51 +02:00
var vt = outputs[1];
2023-12-19 14:30:34 +01:00
if(array_empty(vt.value_to)) return;
2023-01-17 08:11:55 +01:00
2022-12-16 09:18:09 +01:00
var pv = part.getPivot();
2022-12-13 09:20:36 +01:00
2023-12-19 14:30:34 +01:00
for( var i = 0; i < array_length(vt.value_to); i++ ) {
var _n = vt.value_to[i];
2022-12-16 09:18:09 +01:00
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
}
2024-08-06 14:04:41 +02:00
}
2022-12-13 09:20:36 +01:00
2024-08-06 14:04:41 +02:00
static onPartStep = function(part) {
2024-08-08 06:57:51 +02:00
var vt = outputs[2];
2023-12-19 14:30:34 +01:00
if(array_empty(vt.value_to)) return;
2023-01-17 08:11:55 +01:00
var pv = part.getPivot();
2023-12-19 14:30:34 +01:00
for( var i = 0; i < array_length(vt.value_to); i++ ) {
var _n = vt.value_to[i];
2022-12-16 09:18:09 +01:00
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
}
2024-08-06 14:04:41 +02:00
}
2022-12-13 09:20:36 +01:00
2024-08-06 14:04:41 +02:00
static onPartDestroy = function(part) {
2024-08-08 06:57:51 +02:00
var vt = outputs[3];
2023-12-19 14:30:34 +01:00
if(array_empty(vt.value_to)) return;
2023-01-17 08:11:55 +01:00
var pv = part.getPivot();
2023-12-19 14:30:34 +01:00
for( var i = 0; i < array_length(vt.value_to); i++ ) {
var _n = vt.value_to[i];
2022-12-16 09:18:09 +01:00
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
}
2024-08-06 14:04:41 +02:00
}
2022-12-13 09:20:36 +01:00
2023-12-22 04:15:04 +01:00
static getGraphPreviewSurface = function() { return getInputData(0); }
2024-11-30 12:02:41 +01:00
2024-12-02 02:45:17 +01:00
static getPreviewingNode = function() { return is(inline_context, Node_VFX_Group_Inline)? inline_context.getPreviewingNode() : self; }
static getPreviewValues = function() { return is(inline_context, Node_VFX_Group_Inline)? inline_context.getPreviewValues() : self; }
2022-12-13 09:20:36 +01:00
}