Pixel-Composer/scripts/node_group_output/node_group_output.gml

128 lines
3.6 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Group_Output(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Group Output";
color = COLORS.node_blend_collection;
is_group_io = true;
destroy_when_upgroup = true;
skipDefault();
2024-03-28 14:18:02 +01:00
setDimension(96, 32 + 24);
2022-01-13 05:24:03 +01:00
2024-08-20 10:15:53 +02:00
newInput(0, nodeValue("Value", self, CONNECT_TYPE.input, VALUE_TYPE.any, -1))
2023-07-25 20:12:40 +02:00
.uncache()
2022-01-19 06:11:17 +01:00
.setVisible(true, true);
2024-08-08 06:57:51 +02:00
inputs[0].onSetFrom = function(juncFrom) /*=>*/ { if(attributes.inherit_name && !LOADING && !APPENDING) setDisplayName(juncFrom.name); }
2022-01-13 05:24:03 +01:00
2023-12-03 05:02:04 +01:00
attributes.inherit_name = true;
outParent = undefined;
output_index = -1;
2022-01-18 05:31:19 +01:00
onSetDisplayName = function() /*=>*/ { attributes.inherit_name = false; }
2023-12-03 05:02:04 +01:00
static setRenderStatus = function(result) {
2023-10-08 08:02:38 +02:00
if(rendered == result) return;
LOG_LINE_IF(global.FLAG.render == 1, $"Set render status for {INAME} : {result}");
2023-04-04 09:49:33 +02:00
rendered = result;
if(group) group.setRenderStatus(result);
}
2023-04-04 09:49:33 +02:00
static onValueUpdate = function(index = 0) { if(is_undefined(outParent)) return; }
2022-01-18 05:31:19 +01:00
static getNextNodes = function() {
2023-03-28 06:58:28 +02:00
if(is_undefined(outParent)) return [];
2022-12-16 09:18:09 +01:00
LOG_BLOCK_START();
2023-03-28 06:58:28 +02:00
var nodes = [];
2023-12-19 14:30:34 +01:00
for(var j = 0; j < array_length(outParent.value_to); j++) {
var _to = outParent.value_to[j];
2022-12-16 09:18:09 +01:00
if(!_to.node.isRenderActive()) continue;
if(!_to.node.active || _to.value_from == noone) continue;
if(_to.value_from.node != group) continue;
2022-12-16 09:18:09 +01:00
2023-03-29 15:02:03 +02:00
array_push(nodes, _to.node);
LOG_IF(global.FLAG.render == 1, $"Check complete, push {_to.node.internalName} to queue.");
2022-12-16 09:18:09 +01:00
}
LOG_BLOCK_END();
2023-03-28 06:58:28 +02:00
return nodes;
}
2022-12-16 09:18:09 +01:00
static createOutput = function() {
2024-08-20 10:15:53 +02:00
if(group == noone) return;
2023-03-28 06:58:28 +02:00
if(!is_struct(group)) return;
2024-08-08 06:57:51 +02:00
if(!is_undefined(outParent)) array_remove(group.outputs, outParent);
2023-02-14 05:32:32 +01:00
2024-08-20 10:15:53 +02:00
outParent = nodeValue("Value", group, CONNECT_TYPE.output, VALUE_TYPE.any, -1)
2023-07-25 20:12:40 +02:00
.uncache()
2023-03-28 06:58:28 +02:00
.setVisible(true, true);
outParent.from = self;
2024-08-08 06:57:51 +02:00
array_push(group.outputs, outParent);
if(!LOADING && !APPENDING) {
group.refreshNodeDisplay();
group.sortIO();
group.setHeight();
}
2022-01-13 05:24:03 +01:00
} if(!LOADING && !APPENDING) createOutput();
2022-01-13 05:24:03 +01:00
static step = function() {
2022-01-18 05:31:19 +01:00
if(is_undefined(outParent)) return;
2023-02-14 05:32:32 +01:00
outParent.name = display_name;
2022-01-25 10:58:11 +01:00
2024-08-08 06:57:51 +02:00
var _in0 = inputs[0];
var _pty = _in0.type;
var _typ = _in0.value_from == noone? VALUE_TYPE.any : _in0.value_from.type;
var _dis = _in0.value_from == noone? VALUE_DISPLAY._default : _in0.value_from.display_type;
2022-12-10 05:06:01 +01:00
_in0.setType(_typ);
_in0.display_type = _dis;
2023-10-18 14:58:55 +02:00
outParent.setType(_in0.type);
2024-08-20 10:15:53 +02:00
outParent.display_type = _in0.display_type;
outParent.color_display = _in0.color_display;
outParent.draw_bg = _in0.draw_bg;
outParent.draw_fg = _in0.draw_fg;
2024-03-27 11:51:14 +01:00
if(group && _pty != _typ) group.setHeight();
}
2024-08-08 06:57:51 +02:00
static update = function() {
outParent.setValue(inputs[0].getValue());
}
static getGraphPreviewSurface = function() { return inputs[0].getValue(); }
static postDeserialize = function() { if(group == noone) return; createOutput(false); }
static doApplyDeserialize = function() {}
2023-10-20 12:32:43 +02:00
static onDestroy = function() {
2022-01-18 05:31:19 +01:00
if(is_undefined(outParent)) return;
2024-08-08 06:57:51 +02:00
array_remove(group.outputs, outParent);
group.sortIO();
group.refreshNodes();
2024-07-03 05:16:46 +02:00
var _tos = outParent.getJunctionTo();
for (var i = 0, n = array_length(_tos); i < n; i++)
_tos[i].removeFrom();
}
2023-02-14 05:32:32 +01:00
static onUngroup = function() {
2024-08-08 06:57:51 +02:00
var fr = inputs[0].value_from;
2023-02-14 05:32:32 +01:00
2023-12-19 14:30:34 +01:00
for( var i = 0; i < array_length(outParent.value_to); i++ ) {
var to = outParent.value_to[i];
2023-02-14 05:32:32 +01:00
if(to.value_from != outParent) continue;
to.setFrom(fr);
}
}
2023-10-18 14:58:55 +02:00
static onLoadGroup = function() { if(group == noone) destroy(); }
2022-01-13 05:24:03 +01:00
}