Pixel-Composer/scripts/node_pixel_builder/node_pixel_builder.gml

119 lines
3 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;
inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
.setDisplay(VALUE_DISPLAY.vector);
outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
custom_input_index = ds_list_size(inputs);
custom_output_index = ds_list_size(outputs);
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;
for(var i = custom_input_index; i < ds_list_size(inputs); i++) {
var _in = inputs[| i].from;
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
2023-07-21 12:40:20 +02:00
for( var i = 0; i < ds_list_size(nodes); i++ )
if(!nodes[| i].rendered) return [];
buildPixel();
var _nodes = [];
var _tos = outputs[| 0].getJunctionTo();
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 < ds_list_size(nodes); i++ ) {
var _n = nodes[| i];
2023-07-23 20:21:35 +02:00
for( var j = 0; j < ds_list_size(_n.outputs); j++ ) {
var _out = _n.outputs[| j];
if(_out.type != VALUE_TYPE.pbBox) continue;
var _to = _out.getJunctionTo();
if(array_length(_to)) continue;
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
}
var _outSurf = outputs[| 0].getValue();
surface_array_free(_outSurf);
if(ds_map_empty(_surfs)) {
ds_map_destroy(_surfs);
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);
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
}