Pixel-Composer/scripts/node_group_output/node_group_output.gml

163 lines
4.4 KiB
Text
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 {
2023-02-19 13:49:20 +01:00
name = "Group Output";
2023-02-14 05:32:32 +01:00
destroy_when_upgroup = true;
2022-12-10 05:06:01 +01:00
color = COLORS.node_blend_collection;
2022-01-13 05:24:03 +01:00
previewable = false;
auto_height = false;
2023-09-11 16:08:58 +02:00
attributes.input_priority = group == noone? 0 : ds_list_size(group.inputs);
array_push(attributeEditors, "Group");
array_push(attributeEditors, ["Input Order", function() { return attributes.input_priority; },
new textBox(TEXTBOX_INPUT.number, function(val) {
attributes.input_priority = val;
group.setHeight();
group.sortIO();
})]);
2022-01-13 05:24:03 +01:00
w = 96;
h = 32 + 24;
min_h = h;
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Value", self, JUNCTION_CONNECT.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);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Order", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2023-07-25 20:12:40 +02:00
.uncache()
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-01-13 05:24:03 +01:00
2023-08-06 16:00:59 +02:00
attributes.inherit_name = !LOADING && !APPENDING;
2022-01-18 05:31:19 +01:00
outParent = undefined;
output_index = -1;
2023-06-13 14:42:06 +02:00
_onSetDisplayName = function() {
attributes.inherit_name = false;
}
2023-04-04 09:49:33 +02:00
static setRenderStatus = function(result) {
2023-06-01 10:32:21 +02:00
LOG_LINE_IF(global.FLAG.render, $"Set render status for {internalName} : {result}");
2023-04-04 09:49:33 +02:00
rendered = result;
if(group) group.setRenderStatus(result);
}
2023-02-14 05:32:32 +01:00
static onValueUpdate = function(index = 0) {
2022-01-18 05:31:19 +01:00
if(is_undefined(outParent)) return;
group.sortIO();
}
2022-12-16 09:18:09 +01:00
static getNextNodes = function() {
2023-03-28 06:58:28 +02:00
if(is_undefined(outParent)) return [];
2023-03-29 15:02:03 +02:00
//group.setRenderStatus(true);
2023-05-22 20:31:55 +02:00
//printIf(global.FLAG.render, "Value to amount " + string(ds_list_size(outParent.value_to)));
2022-12-16 09:18:09 +01:00
LOG_BLOCK_START();
2023-03-28 06:58:28 +02:00
var nodes = [];
2022-12-16 09:18:09 +01:00
for(var j = 0; j < ds_list_size(outParent.value_to); j++) {
var _to = outParent.value_to[| j];
2023-06-17 14:30:49 +02:00
if(!_to.node.isRenderActive()) continue;
2023-05-22 20:31:55 +02:00
//printIf(global.FLAG.render, "Value to " + _to.name);
2022-12-16 09:18:09 +01:00
if(!_to.node.active || _to.value_from == noone) {
2023-05-22 20:31:55 +02:00
//printIf(global.FLAG.render, "no value from");
2022-12-16 09:18:09 +01:00
continue;
}
if(_to.value_from.node != group) {
2023-05-22 20:31:55 +02:00
//printIf(global.FLAG.render, "value from not equal group");
2022-12-16 09:18:09 +01:00
continue;
}
2023-05-22 20:31:55 +02:00
//printIf(global.FLAG.render, "Group output ready " + string(_to.node.isRenderable()));
2022-12-16 09:18:09 +01:00
2023-03-29 15:02:03 +02:00
array_push(nodes, _to.node);
2023-06-01 10:32:21 +02:00
LOG_IF(global.FLAG.render, $"Check complete, push {_to.node.internalName} to stack.");
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
}
2022-01-19 03:05:13 +01:00
static createOutput = function(override_order = true) {
2023-03-28 06:58:28 +02:00
if(group == noone) return;
if(!is_struct(group)) return;
2023-09-11 16:08:58 +02:00
if(override_order)
attributes.input_priority = ds_list_size(group.outputs);
2022-01-18 05:31:19 +01:00
2023-03-28 06:58:28 +02:00
if(!is_undefined(outParent))
ds_list_remove(group.outputs, outParent);
2023-02-14 05:32:32 +01:00
2023-03-28 06:58:28 +02:00
outParent = nodeValue("Value", group, JUNCTION_CONNECT.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;
2022-01-19 03:05:13 +01:00
2023-03-28 06:58:28 +02:00
ds_list_add(group.outputs, outParent);
group.setHeight();
group.sortIO();
2022-01-13 05:24:03 +01:00
2023-03-28 06:58:28 +02:00
outParent.setFrom(inputs[| 0]);
2022-01-13 05:24:03 +01:00
}
2022-01-19 06:11:17 +01:00
2022-01-13 05:24:03 +01:00
if(!LOADING && !APPENDING)
createOutput();
2022-01-18 05:31:19 +01:00
static step = function() {
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
2022-12-10 05:06:01 +01:00
inputs[| 0].type = VALUE_TYPE.any;
if(inputs[| 0].value_from != noone) {
inputs[| 0].type = inputs[| 0].value_from.type;
inputs[| 0].display_type = inputs[| 0].value_from.display_type;
}
2022-01-25 10:58:11 +01:00
outParent.type = inputs[| 0].type;
2022-12-10 05:06:01 +01:00
outParent.display_type = inputs[| 0].display_type;
2023-06-13 14:42:06 +02:00
onSetDisplayName = _onSetDisplayName;
if(attributes.inherit_name && inputs[| 0].value_from != noone) {
if(display_name != inputs[| 0].value_from.name) {
onSetDisplayName = noone;
setDisplayName(inputs[| 0].value_from.name);
}
}
2022-01-13 05:24:03 +01:00
}
2022-12-10 05:06:01 +01:00
2023-03-28 06:58:28 +02:00
//static triggerRender = function() {
// if(is_undefined(outParent)) return;
2022-01-13 05:24:03 +01:00
2023-03-28 06:58:28 +02:00
// for(var j = 0; j < ds_list_size(outParent.value_to); j++) {
// if(outParent.value_to[| j].value_from == outParent)
// outParent.value_to[| j].node.triggerRender();
// }
//}
2022-01-13 05:24:03 +01:00
2022-01-18 05:31:19 +01:00
static postDeserialize = function() {
createOutput(false);
2023-02-14 05:32:32 +01:00
2023-06-13 14:42:06 +02:00
var _inputs = load_map.inputs;
inputs[| 1].applyDeserialize(_inputs[1], load_scale);
2023-09-11 16:08:58 +02:00
if(PROJECT.version < 11520) attributes.input_priority = inputs[| 1].getValue();
2023-02-14 05:32:32 +01:00
group.sortIO();
2022-01-13 05:24:03 +01:00
}
2022-01-19 03:05:13 +01:00
static onDestroy = function() {
2022-01-18 05:31:19 +01:00
if(is_undefined(outParent)) return;
ds_list_delete(group.outputs, ds_list_find_index(group.outputs, outParent));
2022-01-13 05:24:03 +01:00
}
2023-02-14 05:32:32 +01:00
static ungroup = function() {
var fr = inputs[| 0].value_from;
for( var i = 0; i < ds_list_size(outParent.value_to); i++ ) {
var to = outParent.value_to[| i];
if(to.value_from != outParent) continue;
to.setFrom(fr);
}
}
2022-01-13 05:24:03 +01:00
}