Pixel-Composer/scripts/node_atlas_set/node_atlas_set.gml

122 lines
3.3 KiB
Plaintext
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;
2023-10-06 11:51:11 +02:00
inputs[| 0] = nodeValue("Atlas", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone)
2023-04-16 15:26:52 +02:00
.setVisible(true, true);
2024-05-19 07:55:09 +02:00
inputs[| 1] = nodeValue("Surface", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
2023-04-16 15:26:52 +02:00
2024-04-27 05:10:20 +02:00
inputs[| 2] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ])
2024-05-19 07:55:09 +02:00
.setDisplay(VALUE_DISPLAY.vector);
2023-04-16 15:26:52 +02:00
2024-05-19 07:55:09 +02:00
inputs[| 3] = nodeValue("Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0);
2023-04-16 15:26:52 +02:00
2024-04-27 05:10:20 +02:00
inputs[| 4] = nodeValue("Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ])
2024-05-19 07:55:09 +02:00
.setDisplay(VALUE_DISPLAY.vector);
2023-04-16 15:26:52 +02:00
2024-05-19 07:55:09 +02:00
inputs[| 5] = nodeValue("Blend", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white);
2023-04-16 15:26:52 +02:00
2024-05-19 07:55:09 +02:00
inputs[| 6] = nodeValue("Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1);
2023-04-16 15:26:52 +02:00
inputs[| 7] = nodeValue("Recalculate Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
2023-10-06 11:51:11 +02:00
outputs[| 0] = nodeValue("Atlas", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, 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;
use[i] = inputs[| i].value_from != noone;
}
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);
2023-04-16 15:26:52 +02:00
outputs[| 0].setValue(natl);
}
}