Pixel-Composer/scripts/node_path_shift/node_path_shift.gml

80 lines
2.3 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Path_Shift(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-02-14 02:48:33 +01:00
name = "Shift Path";
previewable = false;
w = 96;
inputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.pathnode, noone)
.setVisible(true, true);
inputs[| 1] = nodeValue("Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0);
outputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.output, VALUE_TYPE.pathnode, self);
2023-03-07 14:29:47 +01:00
static getLineCount = function() {
var _path = inputs[| 0].getValue();
return struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
}
2023-02-28 09:43:01 +01:00
static getSegmentCount = function() {
var _path = inputs[| 0].getValue();
return struct_has(_path, "getSegmentCount")? _path.getSegmentCount() : 0;
}
2023-03-19 09:17:39 +01:00
static getLength = function() {
var _path = inputs[| 0].getValue();
return struct_has(_path, "getLength")? _path.getLength() : 0;
}
static getSegmentLength = function() {
var _path = inputs[| 0].getValue();
return struct_has(_path, "getSegmentLength")? _path.getSegmentLength() : [];
}
static getAccuLength = function() {
var _path = inputs[| 0].getValue();
return struct_has(_path, "getAccuLength")? _path.getAccuLength() : [];
}
static getBoundary = function() {
var _path = inputs[| 0].getValue();
return struct_has(_path, "getBoundary")? _path.getBoundary() : new BoundingBox( 0, 0, 1, 1 );
}
2023-03-07 14:29:47 +01:00
static getPointRatio = function(_rat, ind = 0) {
2023-02-14 02:48:33 +01:00
var _path = inputs[| 0].getValue();
var _shf = inputs[| 1].getValue();
2023-03-07 14:29:47 +01:00
if(is_array(_path)) {
_path = array_safe_get(_path, ind);
ind = 0;
}
2023-02-14 02:48:33 +01:00
if(!is_struct(_path) || !struct_has(_path, "getPointRatio"))
2023-03-19 09:17:39 +01:00
return new Point();
2023-02-14 02:48:33 +01:00
2023-03-07 14:29:47 +01:00
var _p0 = _path.getPointRatio(clamp(_rat - 0.001, 0, 0.999999), ind);
2023-03-19 09:17:39 +01:00
var _p = _path.getPointRatio(_rat, ind).clone();
2023-03-07 14:29:47 +01:00
var _p1 = _path.getPointRatio(clamp(_rat + 0.001, 0, 0.999999), ind);
2023-02-14 02:48:33 +01:00
2023-03-19 09:17:39 +01:00
var dir = point_direction(_p0.x, _p0.y, _p1.x, _p1.y) + 90;
2023-02-14 02:48:33 +01:00
2023-03-19 09:17:39 +01:00
_p.x += lengthdir_x(_shf, dir);
_p.y += lengthdir_y(_shf, dir);
2023-02-14 02:48:33 +01:00
return _p;
}
2023-03-19 09:17:39 +01:00
static getPointDistance = function(_dist, ind = 0) {
return getPointRatio(_rat * getLength());
}
2023-02-14 02:48:33 +01:00
function update() {
outputs[| 0].setValue(self);
}
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);
2023-02-14 11:40:24 +01:00
draw_sprite_fit(s_node_path_shift, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
2023-02-14 02:48:33 +01:00
}
}