Pixel-Composer/scripts/node_pixel_builder/node_pixel_builder.gml

118 lines
2.9 KiB
Text
Raw Normal View History

2023-07-21 12:40:20 +02:00
function Node_Pixel_Builder(_x, _y, _group = noone) : Node_Collection(_x, _y, _group) constructor {
name = "Pixel Builder";
color = COLORS.node_blend_feedback;
icon = THEME.pixel_builder;
reset_all_child = true;
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Dimension(self));
2023-07-21 12:40:20 +02:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Surface Out", self, VALUE_TYPE.surface, noone));
2023-07-21 12:40:20 +02:00
2024-08-08 06:57:51 +02:00
custom_input_index = array_length(inputs);
custom_output_index = array_length(outputs);
2023-07-21 12:40:20 +02:00
2024-05-03 13:40:46 +02:00
if(NODE_NEW_MANUAL) {
2023-07-21 12:40:20 +02:00
var input = nodeBuild("Node_PB_Layer", -256, -32, self);
2023-10-02 10:45:30 +02:00
RENDER_ALL
2023-07-21 12:40:20 +02:00
}
2023-11-26 13:16:38 +01:00
static getNextNodes = function() { #region
2023-07-21 12:40:20 +02:00
var allReady = true;
2024-08-08 06:57:51 +02:00
for(var i = custom_input_index; i < array_length(inputs); i++) {
var _in = inputs[i].from;
2023-07-21 12:40:20 +02:00
if(!_in.isRenderActive()) continue;
allReady &= _in.isRenderable()
}
if(!allReady) return [];
return __nodeLeafList(getNodeList());
2023-11-26 13:16:38 +01:00
} #endregion
2023-07-21 12:40:20 +02:00
2023-11-26 13:16:38 +01:00
static checkComplete = function() { #region
for( var i = 0; i < array_length(nodes); i++ )
if(!nodes[i].rendered) return [];
2023-07-21 12:40:20 +02:00
buildPixel();
var _nodes = [];
2024-08-08 06:57:51 +02:00
var _tos = outputs[0].getJunctionTo();
2023-07-21 12:40:20 +02:00
for( var j = 0; j < array_length(_tos); j++ ) {
var _to = _tos[j];
array_push(_nodes, _to.node);
}
return _nodes;
2023-11-26 13:16:38 +01:00
} #endregion
2023-07-21 12:40:20 +02:00
2023-11-26 13:16:38 +01:00
static buildPixel = function() { #region
2023-07-21 12:40:20 +02:00
LOG_BLOCK_START();
LOG_IF(global.FLAG.render == 1, $"================== BUILD PIXEL ==================");
2023-07-21 12:40:20 +02:00
var _dim = getInputData(0);
2023-07-21 12:40:20 +02:00
var _surfs = ds_map_create();
for( var i = 0; i < array_length(nodes); i++ ) {
var _n = nodes[i];
2023-07-21 12:40:20 +02:00
2024-08-08 06:57:51 +02:00
for( var j = 0; j < array_length(_n.outputs); j++ ) {
var _out = _n.outputs[j];
2023-07-23 20:21:35 +02:00
if(_out.type != VALUE_TYPE.pbBox) continue;
var _to = _out.getJunctionTo();
if(array_length(_to)) continue;
2024-08-08 06:57:51 +02:00
var _pbox = _n.outputs[j].getValue();
2023-07-21 12:40:20 +02:00
2023-07-23 20:21:35 +02:00
if(!is_array(_pbox))
_pbox = [ _pbox ];
for( var k = 0; k < array_length(_pbox); k++ ) {
var _box = _pbox[k];
if(!is_instanceof(_box, __pbBox)) continue;
if(!is_surface(_box.content)) continue;
var _layer = _box.layer;
if(!ds_map_exists(_surfs, _layer))
_surfs[? _layer] = [];
array_push(_surfs[? _layer], _box);
}
}
2023-07-21 12:40:20 +02:00
}
2024-08-08 06:57:51 +02:00
var _outSurf = outputs[0].getValue();
2023-07-21 12:40:20 +02:00
surface_array_free(_outSurf);
if(ds_map_empty(_surfs)) {
ds_map_destroy(_surfs);
2024-08-08 06:57:51 +02:00
outputs[0].setValue(surface_create(_dim[0], _dim[1]));
2024-04-30 05:57:34 +02:00
LOG_BLOCK_END();
2023-07-21 12:40:20 +02:00
return;
}
var _layers = ds_map_keys_to_array(_surfs);
array_sort(_layers, true);
2023-11-26 13:16:38 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);
2023-07-21 12:40:20 +02:00
surface_set_target(_outSurf);
2023-07-23 20:21:35 +02:00
DRAW_CLEAR
2023-11-26 13:16:38 +01:00
for( var k = 0; k < array_length(_layers); k++ ) {
var _s = _surfs[? _layers[k]];
2023-07-21 12:40:20 +02:00
2023-11-26 13:16:38 +01:00
for( var j = 0; j < array_length(_s); j++ ) {
var _box = _s[j];
draw_surface_safe(_box.content, _box.x, _box.y);
}
}
2023-07-21 12:40:20 +02:00
surface_reset_target();
ds_map_destroy(_surfs);
2024-08-08 06:57:51 +02:00
outputs[0].setValue(_outSurf);
2024-04-30 05:57:34 +02:00
LOG_BLOCK_END();
2023-11-26 13:16:38 +01:00
} #endregion
2023-07-21 12:40:20 +02:00
}