Pixel-Composer/scripts/node_rigid_variable/node_rigid_variable.gml

84 lines
2.9 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Rigid_Variable(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-02-14 02:48:33 +01:00
name = "Rigidbody Variable";
color = COLORS.node_blend_simulation;
icon = THEME.rigidSim;
previewable = false;
node_draw_icon = s_node_rigid_variable;
w = 96;
h = 80;
min_h = h;
inputs[| 0] = nodeValue("Object", self, JUNCTION_CONNECT.input, VALUE_TYPE.rigid, noone )
.setVisible(true, true);
input_display_list = [ 0 ];
outputs[| 0] = nodeValue("Positions", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, [ 0, 0 ] )
2023-10-09 16:07:33 +02:00
.setDisplay(VALUE_DISPLAY.vector)
.setVisible(false);
2023-02-14 02:48:33 +01:00
outputs[| 1] = nodeValue("Scales", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, [ 0, 0 ] )
2023-10-09 16:07:33 +02:00
.setDisplay(VALUE_DISPLAY.vector)
.setVisible(false);
2023-02-14 02:48:33 +01:00
2023-10-09 16:07:33 +02:00
outputs[| 2] = nodeValue("Rotations", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, 0 )
.setVisible(false);
2023-02-14 02:48:33 +01:00
outputs[| 3] = nodeValue("Blends", self, JUNCTION_CONNECT.output, VALUE_TYPE.color, 0 )
.setVisible(false);
outputs[| 4] = nodeValue("Alpha", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, 0 )
.setVisible(false);
outputs[| 5] = nodeValue("Velocity", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, [ 0, 0 ] )
.setDisplay(VALUE_DISPLAY.vector)
.setVisible(false);
outputs[| 6] = nodeValue("Center of mass", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, [ 0, 0 ] )
.setDisplay(VALUE_DISPLAY.vector)
.setVisible(false);
2023-10-09 16:07:33 +02:00
outputs[| 7] = nodeValue("Velocity magnitude", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, 0 )
.setDisplay(VALUE_DISPLAY.vector)
.setVisible(false);
static update = function(frame = CURRENT_FRAME) {
var objNode = getInputData(0);
2023-02-14 02:48:33 +01:00
outputs[| 0].setValue(objNode);
if(!variable_struct_exists(objNode, "object")) return;
var objs = objNode.object;
var _get = [];
var _val = [];
for( var i = 0; i < ds_list_size(outputs); i++ ) {
2023-10-09 16:07:33 +02:00
_get[i] = outputs[| i].visible;
2023-02-14 02:48:33 +01:00
_val[i] = [];
if(_get[i]) _val[i] = array_create(array_length(objs));
}
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(objs); i < n; i++ ) {
2023-02-14 02:48:33 +01:00
var obj = objs[i];
if(obj == noone || !instance_exists(obj)) continue;
if(is_undefined(obj.phy_active)) continue;
if(_get[0]) _val[0][i] = [ obj.x, obj.y ];
if(_get[1]) _val[1][i] = [ obj.xscale, obj.yscale ];
2023-10-09 16:07:33 +02:00
if(_get[2]) _val[2][i] = obj.image_angle;
if(_get[3]) _val[3][i] = obj.image_blend;
if(_get[4]) _val[4][i] = obj.image_alpha;
2023-02-14 02:48:33 +01:00
if(_get[5]) _val[5][i] = [ obj.phy_linear_velocity_x, obj.phy_linear_velocity_y ];
if(_get[6]) _val[6][i] = [ obj.phy_com_x, obj.phy_com_y ];
2023-10-09 16:07:33 +02:00
if(_get[7]) _val[7][i] = point_distance(0, 0, obj.phy_linear_velocity_x, obj.phy_linear_velocity_y);
2023-02-14 02:48:33 +01:00
}
for( var i = 0; i < ds_list_size(outputs); i++ )
if(_get[i]) outputs[| i].setValue(_val[i]);
}
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-02-14 02:48:33 +01:00
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(node_draw_icon, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
}