Pixel-Composer/scripts/node_atlas_set/node_atlas_set.gml

120 lines
2.9 KiB
Text
Raw Normal View History

2023-04-16 15:26:52 +02:00
function Node_Atlas_Set(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Atlas Set";
previewable = true;
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_Surface("Atlas", self))
2023-04-16 15:26:52 +02:00
.setVisible(true, true);
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Surface("Surface", self));
2023-04-16 15:26:52 +02:00
2024-08-18 06:16:20 +02:00
newInput(2, nodeValue_Vec2("Position", self, [ 0, 0 ]));
2023-04-16 15:26:52 +02:00
2024-08-18 06:16:20 +02:00
newInput(3, nodeValue_Rotation("Rotation", self, 0));
2023-04-16 15:26:52 +02:00
2024-08-18 06:16:20 +02:00
newInput(4, nodeValue_Vec2("Scale", self, [ 0, 0 ]));
2023-04-16 15:26:52 +02:00
2024-08-18 06:16:20 +02:00
newInput(5, nodeValue_Color("Blend", self, c_white));
2023-04-16 15:26:52 +02:00
2024-08-18 06:16:20 +02:00
newInput(6, nodeValue_Float("Alpha", self, 1));
2023-04-16 15:26:52 +02:00
2024-08-18 06:16:20 +02:00
newInput(7, nodeValue_Bool("Recalculate Position", self, true));
2024-11-15 09:39:23 +01:00
newOutput(0, nodeValue_Output("Atlas", self, VALUE_TYPE.atlas, noone));
2023-04-16 15:26:52 +02:00
input_display_list = [
0, 1, 2, 3, 7, 4, 5, 6,
];
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) {
var atl = getInputData(0);
2023-04-16 15:26:52 +02:00
if(atl == noone) return;
2024-04-27 05:10:20 +02:00
if(!is_array(atl)) atl = [ atl ];
if(array_empty(atl)) return;
2023-04-16 15:26:52 +02:00
var _rot = getInputData(7);
2023-04-16 15:26:52 +02:00
2024-05-19 07:55:09 +02:00
var use = array_create(6);
var len = array_create(6);
var val = array_create(6);
2023-04-16 15:26:52 +02:00
2024-05-19 07:55:09 +02:00
for( var i = 0; i < 7; i++ ) {
val[i] = getInputData(i);
len[i] = is_array(val[i])? array_length(val[i]) : 0;
2024-08-08 06:57:51 +02:00
use[i] = inputs[i].value_from != noone;
2024-05-19 07:55:09 +02:00
}
var n = array_length(atl);
var natl = [];
var _ind = 0;
var _at, _newAtl, _surf, _val;
2023-04-16 15:26:52 +02:00
2024-04-27 05:10:20 +02:00
for( var i = 0; i < n; i++ ) {
2024-05-19 07:55:09 +02:00
_at = atl[i];
2024-04-27 05:10:20 +02:00
if(!is_instanceof(_at, SurfaceAtlas)) continue;
2024-05-19 07:55:09 +02:00
_newAtl = _at.clone();
_surf = _at.surface.get();
2023-04-16 15:26:52 +02:00
2024-05-19 07:55:09 +02:00
if(use[1] && (len[1] == 0 || i < len[1])) {
_val = len[1] == 0? val[1] : val[1][i];
_newAtl.setSurface(_val);
}
2023-10-07 09:09:18 +02:00
2024-05-19 07:55:09 +02:00
if(use[2] && (len[2] == 0 || i < len[2])) {
_val = len[2] == 0? val[2] : val[2][i];
_newAtl.x = array_safe_get_fast(_val, 0);
_newAtl.y = array_safe_get_fast(_val, 1);
2023-10-07 09:09:18 +02:00
}
2024-05-19 07:55:09 +02:00
if(use[3] && (len[3] == 0 || i < len[3])) {
_val = len[3] == 0? val[3] : val[3][i];
var _or = _newAtl.rotation;
var _nr = _val;
2024-05-19 07:55:09 +02:00
_newAtl.rotation = _nr;
if(_rot) {
2024-05-19 07:55:09 +02:00
var _sw = surface_get_width_safe(_surf) * _newAtl.sx;
var _sh = surface_get_height_safe(_surf) * _newAtl.sy;
var p0 = point_rotate(0, 0, _sw / 2, _sh / 2, -_or);
var p1 = point_rotate(0, 0, _sw / 2, _sh / 2, _nr);
2024-05-19 07:55:09 +02:00
_newAtl.x = _newAtl.x - p0[1] + p1[0];
_newAtl.y = _newAtl.y - p0[0] + p1[1];
}
}
2023-10-07 09:09:18 +02:00
2024-05-19 07:55:09 +02:00
if(use[4] && (len[4] == 0 || i < len[4])) {
_val = len[4] == 0? val[4] : val[4][i];
_newAtl.sx = array_safe_get_fast(_val, 0, 1);
_newAtl.sy = array_safe_get_fast(_val, 1, 1);
}
if(use[5] && (len[5] == 0 || i < len[5])) {
_val = len[5] == 0? val[5] : val[5][i];
_newAtl.blend = _val;
2023-10-07 09:09:18 +02:00
}
2024-05-19 07:55:09 +02:00
if(use[6] && (len[6] == 0 || i < len[6])) {
_val = len[6] == 0? val[6] : val[6][i];
_newAtl.alpha = _val;
}
2023-10-07 09:09:18 +02:00
2024-05-19 07:55:09 +02:00
natl[_ind] = _newAtl;
_ind++;
2023-04-16 15:26:52 +02:00
}
2024-05-19 07:55:09 +02:00
array_resize(natl, _ind);
2024-08-08 06:57:51 +02:00
outputs[0].setValue(natl);
2023-04-16 15:26:52 +02:00
}
}