Pixel-Composer/scripts/node_ase_layer/node_ase_layer.gml
2024-06-16 10:27:57 +07:00

67 lines
1.8 KiB
Plaintext

function Node_ASE_layer(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "ASE Layer";
inputs[| 0] = nodeValue("ASE data", self, JUNCTION_CONNECT.input, VALUE_TYPE.object, noone)
.setVisible(false, true)
.rejectArray();
inputs[| 1] = nodeValue("Crop Output", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false)
.rejectArray();
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
layer_object = noone;
_name = "";
static onValueFromUpdate = function(index) { findLayer(); }
static findLayer = function() { #region
layer_object = noone;
var data = getInputData(0);
if(data == noone) return;
for( var i = 0, n = array_length(data.layers); i < n; i++ ) {
if(data.layers[i].name == display_name)
layer_object = data.layers[i];
}
} #endregion
static update = function(frame = CURRENT_FRAME) { #region
findLayer();
if(layer_object == noone) return;
var data = getInputData(0);
var cel = layer_object.getCel(CURRENT_FRAME - data._tag_delay);
var celDim = getInputData(1);
var ww = data.content[? "Width"];
var hh = data.content[? "Height"];
var cw = cel? cel.data[? "Width"] : 1;
var ch = cel? cel.data[? "Height"] : 1;
var surf = outputs[| 0].getValue();
if(celDim) surf = surface_verify(surf, cw, ch);
else surf = surface_verify(surf, ww, hh);
outputs[| 0].setValue(surf);
if(cel == 0) {
surface_set_target(surf);
DRAW_CLEAR
surface_reset_target();
return;
}
var _inSurf = cel.getSurface();
var xx = celDim? 0 : cel.data[? "X"];
var yy = celDim? 0 : cel.data[? "Y"];
surface_set_target(surf);
DRAW_CLEAR
BLEND_OVERRIDE;
draw_surface_safe(_inSurf, xx, yy);
BLEND_NORMAL;
surface_reset_target();
} #endregion
}